Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Universal Interface for Intel High Definition Audio Codec |
| 3 | * |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4 | * HD audio interface patch for Realtek ALC codecs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 6 | * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw> |
| 7 | * PeiSen Hou <pshou@realtek.com.tw> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Takashi Iwai <tiwai@suse.de> |
Jonathan Woithe | 409a3e9 | 2012-03-27 13:01:01 +1030 | [diff] [blame] | 9 | * Jonathan Woithe <jwoithe@just42.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/init.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/pci.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 30 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <sound/core.h> |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 32 | #include <sound/jack.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "hda_codec.h" |
| 34 | #include "hda_local.h" |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 35 | #include "hda_auto_parser.h" |
Kusanagi Kouichi | 680cd53 | 2009-02-05 00:00:58 +0900 | [diff] [blame] | 36 | #include "hda_beep.h" |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 37 | #include "hda_jack.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 39 | /* 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 Iwai | d4a86d8 | 2010-06-23 17:51:26 +0200 | [diff] [blame] | 44 | |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 45 | /* for GPIO Poll */ |
| 46 | #define GPIO_MASK 0x03 |
| 47 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 48 | /* extra amp-initialization sequence types */ |
| 49 | enum { |
| 50 | ALC_INIT_NONE, |
| 51 | ALC_INIT_DEFAULT, |
| 52 | ALC_INIT_GPIO1, |
| 53 | ALC_INIT_GPIO2, |
| 54 | ALC_INIT_GPIO3, |
| 55 | }; |
| 56 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 57 | struct 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 Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 67 | unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */ |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 68 | }; |
| 69 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 70 | struct 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 Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 76 | enum { |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 77 | 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 Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
Takashi Iwai | c14c95f | 2012-02-16 16:38:07 +0100 | [diff] [blame] | 82 | #define MAX_VOL_NIDS 0x40 |
| 83 | |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 84 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | struct alc_spec { |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 103 | struct hda_gen_spec gen; |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | /* codec parameterization */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 106 | const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | unsigned int num_mixers; |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 108 | const struct snd_kcontrol_new *cap_mixer; /* capture mixer */ |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 109 | unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Takashi Iwai | aa563af | 2009-07-31 10:05:11 +0200 | [diff] [blame] | 111 | char stream_name_analog[32]; /* analog PCM stream */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 112 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Takashi Iwai | aa563af | 2009-07-31 10:05:11 +0200 | [diff] [blame] | 117 | char stream_name_digital[32]; /* digital PCM stream */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 118 | const struct hda_pcm_stream *stream_digital_playback; |
| 119 | const struct hda_pcm_stream *stream_digital_capture; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | /* playback */ |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 122 | 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 Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 126 | hda_nid_t alt_dac_nid; |
Takashi Iwai | 6a05ac4 | 2009-02-13 11:19:09 +0100 | [diff] [blame] | 127 | hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */ |
Takashi Iwai | 8c44198 | 2009-01-20 18:30:20 +0100 | [diff] [blame] | 128 | int dig_out_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 130 | /* capture */ |
| 131 | unsigned int num_adc_nids; |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 132 | const hda_nid_t *adc_nids; |
| 133 | const hda_nid_t *capsrc_nids; |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 134 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 135 | hda_nid_t mixer_nid; /* analog-mixer NID */ |
Takashi Iwai | c14c95f | 2012-02-16 16:38:07 +0100 | [diff] [blame] | 136 | DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1); |
| 137 | DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 139 | /* capture setup for dynamic dual-adc switch */ |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 140 | hda_nid_t cur_adc; |
| 141 | unsigned int cur_adc_stream_tag; |
| 142 | unsigned int cur_adc_format; |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* capture source */ |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 145 | unsigned int num_mux_defs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | const struct hda_input_mux *input_mux; |
| 147 | unsigned int cur_mux[3]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 148 | hda_nid_t ext_mic_pin; |
| 149 | hda_nid_t dock_mic_pin; |
| 150 | hda_nid_t int_mic_pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | /* channel model */ |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 153 | const struct hda_channel_mode *channel_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | int num_channel_mode; |
Takashi Iwai | 4e195a7 | 2006-07-28 14:47:34 +0200 | [diff] [blame] | 155 | int need_dac_fix; |
Hector Martin | 3b315d7 | 2009-06-02 10:54:19 +0200 | [diff] [blame] | 156 | int const_channel_count; |
| 157 | int ext_channel_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | /* PCM information */ |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 160 | struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */ |
Takashi Iwai | 41e41f1 | 2005-06-08 14:48:49 +0200 | [diff] [blame] | 161 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 162 | /* dynamic controls, init_verbs and input_mux */ |
| 163 | struct auto_pin_cfg autocfg; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 164 | struct alc_customize_define cdefine; |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 165 | struct snd_array kctls; |
Herton Ronaldo Krzesinski | 61b9b9b | 2009-01-28 09:16:33 -0200 | [diff] [blame] | 166 | struct hda_input_mux private_imux[3]; |
Takashi Iwai | 41923e4 | 2007-10-22 17:20:10 +0200 | [diff] [blame] | 167 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 168 | hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS]; |
| 169 | hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 170 | 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 Iwai | 125821a | 2012-06-22 14:30:29 +0200 | [diff] [blame] | 173 | hda_nid_t inv_dmic_pin; |
Takashi Iwai | 834be88 | 2006-03-01 14:16:17 +0100 | [diff] [blame] | 174 | |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 175 | /* hooks */ |
| 176 | void (*init_hook)(struct hda_codec *codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 177 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 178 | void (*power_hook)(struct hda_codec *codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 179 | #endif |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 180 | void (*shutup)(struct hda_codec *codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 181 | void (*automute_hook)(struct hda_codec *codec); |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 182 | |
Takashi Iwai | 834be88 | 2006-03-01 14:16:17 +0100 | [diff] [blame] | 183 | /* for pin sensing */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 184 | unsigned int hp_jack_present:1; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 185 | unsigned int line_jack_present:1; |
Takashi Iwai | e942796 | 2011-04-28 15:46:07 +0200 | [diff] [blame] | 186 | unsigned int master_mute:1; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 187 | unsigned int auto_mic:1; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 188 | unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 189 | 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 Iwai | 31150f2 | 2012-01-30 10:54:08 +0100 | [diff] [blame] | 195 | unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 196 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 197 | /* other flags */ |
| 198 | unsigned int no_analog :1; /* digital I/O only */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 199 | unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */ |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 200 | unsigned int single_input_src:1; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 201 | unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */ |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 202 | unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */ |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 203 | unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */ |
Takashi Iwai | 125821a | 2012-06-22 14:30:29 +0200 | [diff] [blame] | 204 | unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */ |
| 205 | unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */ |
Takashi Iwai | e427c23 | 2012-07-29 10:04:08 +0200 | [diff] [blame] | 206 | unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */ |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 207 | |
| 208 | /* auto-mute control */ |
| 209 | int automute_mode; |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 210 | hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 211 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 212 | int init_amp; |
Takashi Iwai | d433a67 | 2010-09-20 15:11:54 +0200 | [diff] [blame] | 213 | int codec_variant; /* flag for other variants */ |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 214 | |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 215 | /* for virtual master */ |
| 216 | hda_nid_t vmaster_nid; |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 217 | struct hda_vmaster_mute_hook vmaster_mute; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 218 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 219 | struct hda_loopback_check loopback; |
Takashi Iwai | 164f73e | 2012-02-21 11:27:09 +0100 | [diff] [blame] | 220 | int num_loopbacks; |
| 221 | struct hda_amp_list loopback_list[8]; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 222 | #endif |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 223 | |
| 224 | /* for PLL fix */ |
| 225 | hda_nid_t pll_nid; |
| 226 | unsigned int pll_coef_idx, pll_coef_bit; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 227 | unsigned int coef0; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 228 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 229 | /* multi-io */ |
| 230 | int multi_ios; |
| 231 | struct alc_multi_io multi_io[4]; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 232 | |
| 233 | /* bind volumes */ |
| 234 | struct snd_array bind_ctls; |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 235 | }; |
| 236 | |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 237 | static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, |
| 238 | int dir, unsigned int bits) |
| 239 | { |
| 240 | if (!nid) |
| 241 | return false; |
| 242 | if (get_wcaps(codec, nid) & (1 << (dir + 1))) |
| 243 | if (query_amp_caps(codec, nid, dir) & bits) |
| 244 | return true; |
| 245 | return false; |
| 246 | } |
| 247 | |
| 248 | #define nid_has_mute(codec, nid, dir) \ |
| 249 | check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE) |
| 250 | #define nid_has_volume(codec, nid, dir) \ |
| 251 | check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS) |
| 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | /* |
| 254 | * input MUX handling |
| 255 | */ |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 256 | static int alc_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 257 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
| 259 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 260 | struct alc_spec *spec = codec->spec; |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 261 | unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id); |
| 262 | if (mux_idx >= spec->num_mux_defs) |
| 263 | mux_idx = 0; |
Takashi Iwai | 5311114 | 2010-03-08 12:13:07 +0100 | [diff] [blame] | 264 | if (!spec->input_mux[mux_idx].num_items && mux_idx > 0) |
| 265 | mux_idx = 0; |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 266 | return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 269 | static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 270 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | { |
| 272 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 273 | struct alc_spec *spec = codec->spec; |
| 274 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 275 | |
| 276 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
| 277 | return 0; |
| 278 | } |
| 279 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 280 | static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 282 | struct alc_spec *spec = codec->spec; |
| 283 | hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]]; |
| 284 | |
| 285 | if (spec->cur_adc && spec->cur_adc != new_adc) { |
| 286 | /* stream is running, let's swap the current ADC */ |
| 287 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); |
| 288 | spec->cur_adc = new_adc; |
| 289 | snd_hda_codec_setup_stream(codec, new_adc, |
| 290 | spec->cur_adc_stream_tag, 0, |
| 291 | spec->cur_adc_format); |
| 292 | return true; |
| 293 | } |
| 294 | return false; |
| 295 | } |
| 296 | |
Takashi Iwai | 6107159 | 2011-11-23 07:52:15 +0100 | [diff] [blame] | 297 | static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx) |
| 298 | { |
| 299 | return spec->capsrc_nids ? |
| 300 | spec->capsrc_nids[idx] : spec->adc_nids[idx]; |
| 301 | } |
| 302 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 303 | static void call_update_outputs(struct hda_codec *codec); |
Takashi Iwai | 125821a | 2012-06-22 14:30:29 +0200 | [diff] [blame] | 304 | static void alc_inv_dmic_sync(struct hda_codec *codec, bool force); |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 305 | |
David Henningsson | 00227f1 | 2012-06-27 18:45:44 +0200 | [diff] [blame] | 306 | /* for shared I/O, change the pin-control accordingly */ |
| 307 | static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic) |
| 308 | { |
| 309 | struct alc_spec *spec = codec->spec; |
| 310 | unsigned int val; |
| 311 | hda_nid_t pin = spec->autocfg.inputs[1].pin; |
| 312 | /* NOTE: this assumes that there are only two inputs, the |
| 313 | * first is the real internal mic and the second is HP/mic jack. |
| 314 | */ |
| 315 | |
| 316 | val = snd_hda_get_default_vref(codec, pin); |
| 317 | |
| 318 | /* This pin does not have vref caps - let's enable vref on pin 0x18 |
| 319 | instead, as suggested by Realtek */ |
| 320 | if (val == AC_PINCTL_VREF_HIZ) { |
| 321 | const hda_nid_t vref_pin = 0x18; |
| 322 | /* Sanity check pin 0x18 */ |
| 323 | if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN && |
| 324 | get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) { |
| 325 | unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin); |
| 326 | if (vref_val != AC_PINCTL_VREF_HIZ) |
| 327 | snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0)); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | val = set_as_mic ? val | PIN_IN : PIN_HP; |
| 332 | snd_hda_set_pin_ctl(codec, pin, val); |
| 333 | |
| 334 | spec->automute_speaker = !set_as_mic; |
| 335 | call_update_outputs(codec); |
| 336 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 337 | |
| 338 | /* select the given imux item; either unmute exclusively or select the route */ |
| 339 | static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx, |
| 340 | unsigned int idx, bool force) |
| 341 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 343 | const struct hda_input_mux *imux; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 344 | unsigned int mux_idx; |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 345 | int i, type, num_conns; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 346 | hda_nid_t nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
Takashi Iwai | 5803a32 | 2012-02-21 11:59:45 +0100 | [diff] [blame] | 348 | if (!spec->input_mux) |
| 349 | return 0; |
| 350 | |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 351 | mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; |
| 352 | imux = &spec->input_mux[mux_idx]; |
Takashi Iwai | 5311114 | 2010-03-08 12:13:07 +0100 | [diff] [blame] | 353 | if (!imux->num_items && mux_idx > 0) |
| 354 | imux = &spec->input_mux[0]; |
Takashi Iwai | cce4aa3 | 2011-12-02 15:29:12 +0100 | [diff] [blame] | 355 | if (!imux->num_items) |
| 356 | return 0; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 357 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 358 | if (idx >= imux->num_items) |
| 359 | idx = imux->num_items - 1; |
| 360 | if (spec->cur_mux[adc_idx] == idx && !force) |
| 361 | return 0; |
| 362 | spec->cur_mux[adc_idx] = idx; |
| 363 | |
David Henningsson | 00227f1 | 2012-06-27 18:45:44 +0200 | [diff] [blame] | 364 | if (spec->shared_mic_hp) |
| 365 | update_shared_mic_hp(codec, spec->cur_mux[adc_idx]); |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 366 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 367 | if (spec->dyn_adc_switch) { |
| 368 | alc_dyn_adc_pcm_resetup(codec, idx); |
| 369 | adc_idx = spec->dyn_adc_idx[idx]; |
| 370 | } |
| 371 | |
Takashi Iwai | 6107159 | 2011-11-23 07:52:15 +0100 | [diff] [blame] | 372 | nid = get_capsrc(spec, adc_idx); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 373 | |
| 374 | /* no selection? */ |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 375 | num_conns = snd_hda_get_num_conns(codec, nid); |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 376 | if (num_conns <= 1) |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 377 | return 1; |
| 378 | |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 379 | type = get_wcaps_type(get_wcaps(codec, nid)); |
Takashi Iwai | 0169b6b | 2009-06-22 10:50:19 +0200 | [diff] [blame] | 380 | if (type == AC_WID_AUD_MIX) { |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 381 | /* Matrix-mixer style (e.g. ALC882) */ |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 382 | int active = imux->items[idx].index; |
| 383 | for (i = 0; i < num_conns; i++) { |
| 384 | unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE; |
| 385 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i, |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 386 | HDA_AMP_MUTE, v); |
| 387 | } |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 388 | } else { |
| 389 | /* MUX style (e.g. ALC880) */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 390 | snd_hda_codec_write_cache(codec, nid, 0, |
| 391 | AC_VERB_SET_CONNECT_SEL, |
| 392 | imux->items[idx].index); |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 393 | } |
Takashi Iwai | 125821a | 2012-06-22 14:30:29 +0200 | [diff] [blame] | 394 | alc_inv_dmic_sync(codec, true); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 395 | return 1; |
| 396 | } |
| 397 | |
| 398 | static int alc_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 399 | struct snd_ctl_elem_value *ucontrol) |
| 400 | { |
| 401 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 402 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 403 | return alc_mux_select(codec, adc_idx, |
| 404 | ucontrol->value.enumerated.item[0], false); |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 405 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | /* |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 408 | * set up the input pin config (depending on the given auto-pin type) |
| 409 | */ |
| 410 | static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid, |
| 411 | int auto_pin_type) |
| 412 | { |
| 413 | unsigned int val = PIN_IN; |
Takashi Iwai | 4740860 | 2012-04-20 13:06:53 +0200 | [diff] [blame] | 414 | if (auto_pin_type == AUTO_PIN_MIC) |
| 415 | val |= snd_hda_get_default_vref(codec, nid); |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 416 | snd_hda_set_pin_ctl(codec, nid, val); |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 420 | * Append the given mixer and verb elements for the later use |
| 421 | * The mixer array is referred in build_controls(), and init_verbs are |
| 422 | * called in init(). |
Takashi Iwai | d88897e | 2008-10-31 15:01:37 +0100 | [diff] [blame] | 423 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 424 | static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix) |
Takashi Iwai | d88897e | 2008-10-31 15:01:37 +0100 | [diff] [blame] | 425 | { |
| 426 | if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers))) |
| 427 | return; |
| 428 | spec->mixers[spec->num_mixers++] = mix; |
| 429 | } |
| 430 | |
Takashi Iwai | d88897e | 2008-10-31 15:01:37 +0100 | [diff] [blame] | 431 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 432 | * GPIO setup tables, used in initialization |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 433 | */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 434 | /* Enable GPIO mask and set output */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 435 | static const struct hda_verb alc_gpio1_init_verbs[] = { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 436 | {0x01, AC_VERB_SET_GPIO_MASK, 0x01}, |
| 437 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, |
| 438 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, |
| 439 | { } |
| 440 | }; |
| 441 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 442 | static const struct hda_verb alc_gpio2_init_verbs[] = { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 443 | {0x01, AC_VERB_SET_GPIO_MASK, 0x02}, |
| 444 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02}, |
| 445 | {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, |
| 446 | { } |
| 447 | }; |
| 448 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 449 | static const struct hda_verb alc_gpio3_init_verbs[] = { |
Kailang Yang | bdd148a | 2007-05-08 15:19:08 +0200 | [diff] [blame] | 450 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, |
| 451 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03}, |
| 452 | {0x01, AC_VERB_SET_GPIO_DATA, 0x03}, |
| 453 | { } |
| 454 | }; |
| 455 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 456 | /* |
| 457 | * Fix hardware PLL issue |
| 458 | * On some codecs, the analog PLL gating control must be off while |
| 459 | * the default value is 1. |
| 460 | */ |
| 461 | static void alc_fix_pll(struct hda_codec *codec) |
| 462 | { |
| 463 | struct alc_spec *spec = codec->spec; |
| 464 | unsigned int val; |
| 465 | |
| 466 | if (!spec->pll_nid) |
| 467 | return; |
| 468 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, |
| 469 | spec->pll_coef_idx); |
| 470 | val = snd_hda_codec_read(codec, spec->pll_nid, 0, |
| 471 | AC_VERB_GET_PROC_COEF, 0); |
| 472 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, |
| 473 | spec->pll_coef_idx); |
| 474 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF, |
| 475 | val & ~(1 << spec->pll_coef_bit)); |
| 476 | } |
| 477 | |
| 478 | static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid, |
| 479 | unsigned int coef_idx, unsigned int coef_bit) |
| 480 | { |
| 481 | struct alc_spec *spec = codec->spec; |
| 482 | spec->pll_nid = nid; |
| 483 | spec->pll_coef_idx = coef_idx; |
| 484 | spec->pll_coef_bit = coef_bit; |
| 485 | alc_fix_pll(codec); |
| 486 | } |
| 487 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 488 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 489 | * Jack detections for HP auto-mute and mic-switch |
| 490 | */ |
| 491 | |
| 492 | /* check each pin in the given array; returns true if any of them is plugged */ |
| 493 | static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 494 | { |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 495 | int i, present = 0; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 496 | |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 497 | for (i = 0; i < num_pins; i++) { |
| 498 | hda_nid_t nid = pins[i]; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 499 | if (!nid) |
| 500 | break; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 501 | present |= snd_hda_jack_detect(codec, nid); |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 502 | } |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 503 | return present; |
| 504 | } |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 505 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 506 | /* standard HP/line-out auto-mute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 507 | static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins, |
Takashi Iwai | e942796 | 2011-04-28 15:46:07 +0200 | [diff] [blame] | 508 | bool mute, bool hp_out) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 509 | { |
| 510 | struct alc_spec *spec = codec->spec; |
| 511 | unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0; |
Takashi Iwai | e942796 | 2011-04-28 15:46:07 +0200 | [diff] [blame] | 512 | unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 513 | int i; |
| 514 | |
| 515 | for (i = 0; i < num_pins; i++) { |
| 516 | hda_nid_t nid = pins[i]; |
Takashi Iwai | 31150f2 | 2012-01-30 10:54:08 +0100 | [diff] [blame] | 517 | unsigned int val; |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 518 | if (!nid) |
| 519 | break; |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 520 | switch (spec->automute_mode) { |
| 521 | case ALC_AUTOMUTE_PIN: |
Takashi Iwai | 31150f2 | 2012-01-30 10:54:08 +0100 | [diff] [blame] | 522 | /* don't reset VREF value in case it's controlling |
| 523 | * the amp (see alc861_fixup_asus_amp_vref_0f()) |
| 524 | */ |
| 525 | if (spec->keep_vref_in_automute) { |
| 526 | val = snd_hda_codec_read(codec, nid, 0, |
| 527 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 528 | val &= ~PIN_HP; |
| 529 | } else |
| 530 | val = 0; |
| 531 | val |= pin_bits; |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 532 | snd_hda_set_pin_ctl(codec, nid, val); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 533 | break; |
| 534 | case ALC_AUTOMUTE_AMP: |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 535 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 536 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 537 | break; |
| 538 | case ALC_AUTOMUTE_MIXER: |
| 539 | nid = spec->automute_mixer_nid[i]; |
| 540 | if (!nid) |
| 541 | break; |
| 542 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 543 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 544 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 545 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 546 | break; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 547 | } |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 548 | } |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 549 | } |
| 550 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 551 | /* Toggle outputs muting */ |
| 552 | static void update_outputs(struct hda_codec *codec) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 553 | { |
| 554 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 555 | int on; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 556 | |
Takashi Iwai | c0a2026 | 2011-06-10 15:28:15 +0200 | [diff] [blame] | 557 | /* Control HP pins/amps depending on master_mute state; |
| 558 | * in general, HP pins/amps control should be enabled in all cases, |
| 559 | * but currently set only for master_mute, just to be safe |
| 560 | */ |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 561 | if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */ |
| 562 | do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins), |
Takashi Iwai | c0a2026 | 2011-06-10 15:28:15 +0200 | [diff] [blame] | 563 | spec->autocfg.hp_pins, spec->master_mute, true); |
| 564 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 565 | if (!spec->automute_speaker) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 566 | on = 0; |
| 567 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 568 | on = spec->hp_jack_present | spec->line_jack_present; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 569 | on |= spec->master_mute; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 570 | do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins), |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 571 | spec->autocfg.speaker_pins, on, false); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 572 | |
| 573 | /* toggle line-out mutes if needed, too */ |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 574 | /* if LO is a copy of either HP or Speaker, don't need to handle it */ |
| 575 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] || |
| 576 | spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0]) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 577 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 578 | if (!spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 579 | on = 0; |
| 580 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 581 | on = spec->hp_jack_present; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 582 | on |= spec->master_mute; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 583 | do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 584 | spec->autocfg.line_out_pins, on, false); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 585 | } |
| 586 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 587 | static void call_update_outputs(struct hda_codec *codec) |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 588 | { |
| 589 | struct alc_spec *spec = codec->spec; |
| 590 | if (spec->automute_hook) |
| 591 | spec->automute_hook(codec); |
| 592 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 593 | update_outputs(codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 594 | } |
| 595 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 596 | /* standard HP-automute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 597 | static void alc_hp_automute(struct hda_codec *codec) |
| 598 | { |
| 599 | struct alc_spec *spec = codec->spec; |
| 600 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 601 | spec->hp_jack_present = |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 602 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins), |
| 603 | spec->autocfg.hp_pins); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 604 | if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo)) |
Takashi Iwai | 3c715a9 | 2011-08-23 12:41:09 +0200 | [diff] [blame] | 605 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 606 | call_update_outputs(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 607 | } |
| 608 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 609 | /* standard line-out-automute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 610 | static void alc_line_automute(struct hda_codec *codec) |
| 611 | { |
| 612 | struct alc_spec *spec = codec->spec; |
| 613 | |
Takashi Iwai | e0d32e3 | 2011-09-26 15:19:55 +0200 | [diff] [blame] | 614 | /* check LO jack only when it's different from HP */ |
| 615 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0]) |
| 616 | return; |
| 617 | |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 618 | spec->line_jack_present = |
| 619 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
| 620 | spec->autocfg.line_out_pins); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 621 | if (!spec->automute_speaker || !spec->detect_lo) |
Takashi Iwai | 3c715a9 | 2011-08-23 12:41:09 +0200 | [diff] [blame] | 622 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 623 | call_update_outputs(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 624 | } |
| 625 | |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 626 | #define get_connection_index(codec, mux, nid) \ |
| 627 | snd_hda_get_conn_index(codec, mux, nid, 0) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 628 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 629 | /* standard mic auto-switch helper */ |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 630 | static void alc_mic_automute(struct hda_codec *codec) |
| 631 | { |
| 632 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 633 | hda_nid_t *pins = spec->imux_pins; |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 634 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 635 | if (!spec->auto_mic || !spec->auto_mic_valid_imux) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 636 | return; |
| 637 | if (snd_BUG_ON(!spec->adc_nids)) |
| 638 | return; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 639 | if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0)) |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 640 | return; |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 641 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 642 | if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx])) |
| 643 | alc_mux_select(codec, 0, spec->ext_mic_idx, false); |
| 644 | else if (spec->dock_mic_idx >= 0 && |
| 645 | snd_hda_jack_detect(codec, pins[spec->dock_mic_idx])) |
| 646 | alc_mux_select(codec, 0, spec->dock_mic_idx, false); |
| 647 | else |
| 648 | alc_mux_select(codec, 0, spec->int_mic_idx, false); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 649 | } |
| 650 | |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 651 | /* handle the specified unsol action (ALC_XXX_EVENT) */ |
| 652 | static void alc_exec_unsol_event(struct hda_codec *codec, int action) |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 653 | { |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 654 | switch (action) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 655 | case ALC_HP_EVENT: |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 656 | alc_hp_automute(codec); |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 657 | break; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 658 | case ALC_FRONT_EVENT: |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 659 | alc_line_automute(codec); |
| 660 | break; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 661 | case ALC_MIC_EVENT: |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 662 | alc_mic_automute(codec); |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 663 | break; |
| 664 | } |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 665 | snd_hda_jack_report_sync(codec); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 666 | } |
| 667 | |
Takashi Iwai | cf5a227 | 2012-02-20 16:31:07 +0100 | [diff] [blame] | 668 | /* update the master volume per volume-knob's unsol event */ |
| 669 | static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid) |
| 670 | { |
| 671 | unsigned int val; |
| 672 | struct snd_kcontrol *kctl; |
| 673 | struct snd_ctl_elem_value *uctl; |
| 674 | |
| 675 | kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume"); |
| 676 | if (!kctl) |
| 677 | return; |
| 678 | uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); |
| 679 | if (!uctl) |
| 680 | return; |
| 681 | val = snd_hda_codec_read(codec, nid, 0, |
| 682 | AC_VERB_GET_VOLUME_KNOB_CONTROL, 0); |
| 683 | val &= HDA_AMP_VOLMASK; |
| 684 | uctl->value.integer.value[0] = val; |
| 685 | uctl->value.integer.value[1] = val; |
| 686 | kctl->put(kctl, uctl); |
| 687 | kfree(uctl); |
| 688 | } |
| 689 | |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 690 | /* unsolicited event for HP jack sensing */ |
David Henningsson | a7a0a64 | 2012-07-05 12:00:12 +0200 | [diff] [blame] | 691 | static void alc_unsol_event(struct hda_codec *codec, unsigned int res) |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 692 | { |
Takashi Iwai | cf5a227 | 2012-02-20 16:31:07 +0100 | [diff] [blame] | 693 | int action; |
| 694 | |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 695 | if (codec->vendor_id == 0x10ec0880) |
| 696 | res >>= 28; |
| 697 | else |
| 698 | res >>= 26; |
Takashi Iwai | cf5a227 | 2012-02-20 16:31:07 +0100 | [diff] [blame] | 699 | action = snd_hda_jack_get_action(codec, res); |
David Henningsson | e21af48 | 2012-03-05 11:38:46 +0100 | [diff] [blame] | 700 | if (action == ALC_DCVOL_EVENT) { |
Takashi Iwai | cf5a227 | 2012-02-20 16:31:07 +0100 | [diff] [blame] | 701 | /* Execute the dc-vol event here as it requires the NID |
| 702 | * but we don't pass NID to alc_exec_unsol_event(). |
| 703 | * Once when we convert all static quirks to the auto-parser, |
| 704 | * this can be integerated into there. |
| 705 | */ |
| 706 | struct hda_jack_tbl *jack; |
| 707 | jack = snd_hda_jack_tbl_get_from_tag(codec, res); |
| 708 | if (jack) |
| 709 | alc_update_knob_master(codec, jack->nid); |
| 710 | return; |
| 711 | } |
| 712 | alc_exec_unsol_event(codec, action); |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 713 | } |
| 714 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 715 | /* call init functions of standard auto-mute helpers */ |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 716 | static void alc_inithook(struct hda_codec *codec) |
| 717 | { |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 718 | alc_hp_automute(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 719 | alc_line_automute(codec); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 720 | alc_mic_automute(codec); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 721 | } |
| 722 | |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 723 | /* additional initialization for ALC888 variants */ |
| 724 | static void alc888_coef_init(struct hda_codec *codec) |
| 725 | { |
| 726 | unsigned int tmp; |
| 727 | |
| 728 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0); |
| 729 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 730 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); |
Takashi Iwai | 37db623 | 2009-03-05 09:40:16 +0100 | [diff] [blame] | 731 | if ((tmp & 0xf0) == 0x20) |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 732 | /* alc888S-VC */ |
| 733 | snd_hda_codec_read(codec, 0x20, 0, |
| 734 | AC_VERB_SET_PROC_COEF, 0x830); |
| 735 | else |
| 736 | /* alc888-VB */ |
| 737 | snd_hda_codec_read(codec, 0x20, 0, |
| 738 | AC_VERB_SET_PROC_COEF, 0x3030); |
| 739 | } |
| 740 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 741 | /* additional initialization for ALC889 variants */ |
Jaroslav Kysela | 87a8c37 | 2009-07-23 10:58:29 +0200 | [diff] [blame] | 742 | static void alc889_coef_init(struct hda_codec *codec) |
| 743 | { |
| 744 | unsigned int tmp; |
| 745 | |
| 746 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 747 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 748 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 749 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010); |
| 750 | } |
| 751 | |
Takashi Iwai | 3fb4a50 | 2010-01-19 15:46:37 +0100 | [diff] [blame] | 752 | /* turn on/off EAPD control (only if available) */ |
| 753 | static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on) |
| 754 | { |
| 755 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) |
| 756 | return; |
| 757 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) |
| 758 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE, |
| 759 | on ? 2 : 0); |
| 760 | } |
| 761 | |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 762 | /* turn on/off EAPD controls of the codec */ |
| 763 | static void alc_auto_setup_eapd(struct hda_codec *codec, bool on) |
| 764 | { |
| 765 | /* We currently only handle front, HP */ |
Takashi Iwai | 39fa84e | 2011-06-27 15:28:57 +0200 | [diff] [blame] | 766 | static hda_nid_t pins[] = { |
| 767 | 0x0f, 0x10, 0x14, 0x15, 0 |
| 768 | }; |
| 769 | hda_nid_t *p; |
| 770 | for (p = pins; *p; p++) |
| 771 | set_eapd(codec, *p, on); |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 772 | } |
| 773 | |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 774 | /* generic shutup callback; |
| 775 | * just turning off EPAD and a little pause for avoiding pop-noise |
| 776 | */ |
| 777 | static void alc_eapd_shutup(struct hda_codec *codec) |
| 778 | { |
| 779 | alc_auto_setup_eapd(codec, false); |
| 780 | msleep(200); |
| 781 | } |
| 782 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 783 | /* generic EAPD initialization */ |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 784 | static void alc_auto_init_amp(struct hda_codec *codec, int type) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 785 | { |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 786 | unsigned int tmp; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 787 | |
Takashi Iwai | 39fa84e | 2011-06-27 15:28:57 +0200 | [diff] [blame] | 788 | alc_auto_setup_eapd(codec, true); |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 789 | switch (type) { |
| 790 | case ALC_INIT_GPIO1: |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 791 | snd_hda_sequence_write(codec, alc_gpio1_init_verbs); |
| 792 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 793 | case ALC_INIT_GPIO2: |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 794 | snd_hda_sequence_write(codec, alc_gpio2_init_verbs); |
| 795 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 796 | case ALC_INIT_GPIO3: |
Kailang Yang | bdd148a | 2007-05-08 15:19:08 +0200 | [diff] [blame] | 797 | snd_hda_sequence_write(codec, alc_gpio3_init_verbs); |
| 798 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 799 | case ALC_INIT_DEFAULT: |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 800 | switch (codec->vendor_id) { |
| 801 | case 0x10ec0260: |
| 802 | snd_hda_codec_write(codec, 0x1a, 0, |
| 803 | AC_VERB_SET_COEF_INDEX, 7); |
| 804 | tmp = snd_hda_codec_read(codec, 0x1a, 0, |
| 805 | AC_VERB_GET_PROC_COEF, 0); |
| 806 | snd_hda_codec_write(codec, 0x1a, 0, |
| 807 | AC_VERB_SET_COEF_INDEX, 7); |
| 808 | snd_hda_codec_write(codec, 0x1a, 0, |
| 809 | AC_VERB_SET_PROC_COEF, |
| 810 | tmp | 0x2010); |
| 811 | break; |
| 812 | case 0x10ec0262: |
| 813 | case 0x10ec0880: |
| 814 | case 0x10ec0882: |
| 815 | case 0x10ec0883: |
| 816 | case 0x10ec0885: |
Takashi Iwai | 4a5a4c5 | 2009-02-06 12:46:59 +0100 | [diff] [blame] | 817 | case 0x10ec0887: |
Takashi Iwai | 20b67dd | 2011-03-23 22:54:32 +0100 | [diff] [blame] | 818 | /*case 0x10ec0889:*/ /* this causes an SPDIF problem */ |
Jaroslav Kysela | 87a8c37 | 2009-07-23 10:58:29 +0200 | [diff] [blame] | 819 | alc889_coef_init(codec); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 820 | break; |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 821 | case 0x10ec0888: |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 822 | alc888_coef_init(codec); |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 823 | break; |
Takashi Iwai | 0aea778 | 2010-01-25 15:44:11 +0100 | [diff] [blame] | 824 | #if 0 /* XXX: This may cause the silent output on speaker on some machines */ |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 825 | case 0x10ec0267: |
| 826 | case 0x10ec0268: |
| 827 | snd_hda_codec_write(codec, 0x20, 0, |
| 828 | AC_VERB_SET_COEF_INDEX, 7); |
| 829 | tmp = snd_hda_codec_read(codec, 0x20, 0, |
| 830 | AC_VERB_GET_PROC_COEF, 0); |
| 831 | snd_hda_codec_write(codec, 0x20, 0, |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 832 | AC_VERB_SET_COEF_INDEX, 7); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 833 | snd_hda_codec_write(codec, 0x20, 0, |
| 834 | AC_VERB_SET_PROC_COEF, |
| 835 | tmp | 0x3000); |
| 836 | break; |
Takashi Iwai | 0aea778 | 2010-01-25 15:44:11 +0100 | [diff] [blame] | 837 | #endif /* XXX */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 838 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 839 | break; |
| 840 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 841 | } |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 842 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 843 | /* |
| 844 | * Auto-Mute mode mixer enum support |
| 845 | */ |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 846 | static int alc_automute_mode_info(struct snd_kcontrol *kcontrol, |
| 847 | struct snd_ctl_elem_info *uinfo) |
| 848 | { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 849 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 850 | struct alc_spec *spec = codec->spec; |
| 851 | static const char * const texts2[] = { |
| 852 | "Disabled", "Enabled" |
| 853 | }; |
| 854 | static const char * const texts3[] = { |
Takashi Iwai | e49a343 | 2012-03-01 18:14:41 +0100 | [diff] [blame] | 855 | "Disabled", "Speaker Only", "Line Out+Speaker" |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 856 | }; |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 857 | const char * const *texts; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 858 | |
| 859 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 860 | uinfo->count = 1; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 861 | if (spec->automute_speaker_possible && spec->automute_lo_possible) { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 862 | uinfo->value.enumerated.items = 3; |
| 863 | texts = texts3; |
| 864 | } else { |
| 865 | uinfo->value.enumerated.items = 2; |
| 866 | texts = texts2; |
| 867 | } |
| 868 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 869 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 870 | strcpy(uinfo->value.enumerated.name, |
| 871 | texts[uinfo->value.enumerated.item]); |
| 872 | return 0; |
| 873 | } |
| 874 | |
| 875 | static int alc_automute_mode_get(struct snd_kcontrol *kcontrol, |
| 876 | struct snd_ctl_elem_value *ucontrol) |
| 877 | { |
| 878 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 879 | struct alc_spec *spec = codec->spec; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 880 | unsigned int val = 0; |
| 881 | if (spec->automute_speaker) |
| 882 | val++; |
| 883 | if (spec->automute_lo) |
| 884 | val++; |
| 885 | |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 886 | ucontrol->value.enumerated.item[0] = val; |
| 887 | return 0; |
| 888 | } |
| 889 | |
| 890 | static int alc_automute_mode_put(struct snd_kcontrol *kcontrol, |
| 891 | struct snd_ctl_elem_value *ucontrol) |
| 892 | { |
| 893 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 894 | struct alc_spec *spec = codec->spec; |
| 895 | |
| 896 | switch (ucontrol->value.enumerated.item[0]) { |
| 897 | case 0: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 898 | if (!spec->automute_speaker && !spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 899 | return 0; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 900 | spec->automute_speaker = 0; |
| 901 | spec->automute_lo = 0; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 902 | break; |
| 903 | case 1: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 904 | if (spec->automute_speaker_possible) { |
| 905 | if (!spec->automute_lo && spec->automute_speaker) |
| 906 | return 0; |
| 907 | spec->automute_speaker = 1; |
| 908 | spec->automute_lo = 0; |
| 909 | } else if (spec->automute_lo_possible) { |
| 910 | if (spec->automute_lo) |
| 911 | return 0; |
| 912 | spec->automute_lo = 1; |
| 913 | } else |
| 914 | return -EINVAL; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 915 | break; |
| 916 | case 2: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 917 | if (!spec->automute_lo_possible || !spec->automute_speaker_possible) |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 918 | return -EINVAL; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 919 | if (spec->automute_speaker && spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 920 | return 0; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 921 | spec->automute_speaker = 1; |
| 922 | spec->automute_lo = 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 923 | break; |
| 924 | default: |
| 925 | return -EINVAL; |
| 926 | } |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 927 | call_update_outputs(codec); |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 928 | return 1; |
| 929 | } |
| 930 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 931 | static const struct snd_kcontrol_new alc_automute_mode_enum = { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 932 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 933 | .name = "Auto-Mute Mode", |
| 934 | .info = alc_automute_mode_info, |
| 935 | .get = alc_automute_mode_get, |
| 936 | .put = alc_automute_mode_put, |
| 937 | }; |
| 938 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 939 | static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec) |
| 940 | { |
| 941 | snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32); |
| 942 | return snd_array_new(&spec->kctls); |
| 943 | } |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 944 | |
| 945 | static int alc_add_automute_mode_enum(struct hda_codec *codec) |
| 946 | { |
| 947 | struct alc_spec *spec = codec->spec; |
| 948 | struct snd_kcontrol_new *knew; |
| 949 | |
| 950 | knew = alc_kcontrol_new(spec); |
| 951 | if (!knew) |
| 952 | return -ENOMEM; |
| 953 | *knew = alc_automute_mode_enum; |
| 954 | knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL); |
| 955 | if (!knew->name) |
| 956 | return -ENOMEM; |
| 957 | return 0; |
| 958 | } |
| 959 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 960 | /* |
| 961 | * Check the availability of HP/line-out auto-mute; |
| 962 | * Set up appropriately if really supported |
| 963 | */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 964 | static void alc_init_automute(struct hda_codec *codec) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 965 | { |
| 966 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 967 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 1daf5f4 | 2011-04-28 17:57:46 +0200 | [diff] [blame] | 968 | int present = 0; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 969 | int i; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 970 | |
Takashi Iwai | 1daf5f4 | 2011-04-28 17:57:46 +0200 | [diff] [blame] | 971 | if (cfg->hp_pins[0]) |
| 972 | present++; |
| 973 | if (cfg->line_out_pins[0]) |
| 974 | present++; |
| 975 | if (cfg->speaker_pins[0]) |
| 976 | present++; |
| 977 | if (present < 2) /* need two different output types */ |
| 978 | return; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 979 | |
Takashi Iwai | c48a8fb | 2011-07-27 16:41:57 +0200 | [diff] [blame] | 980 | if (!cfg->speaker_pins[0] && |
| 981 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 982 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 983 | sizeof(cfg->speaker_pins)); |
| 984 | cfg->speaker_outs = cfg->line_outs; |
| 985 | } |
| 986 | |
Takashi Iwai | c48a8fb | 2011-07-27 16:41:57 +0200 | [diff] [blame] | 987 | if (!cfg->hp_pins[0] && |
| 988 | cfg->line_out_type == AUTO_PIN_HP_OUT) { |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 989 | memcpy(cfg->hp_pins, cfg->line_out_pins, |
| 990 | sizeof(cfg->hp_pins)); |
| 991 | cfg->hp_outs = cfg->line_outs; |
| 992 | } |
| 993 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 994 | spec->automute_mode = ALC_AUTOMUTE_PIN; |
| 995 | |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 996 | for (i = 0; i < cfg->hp_outs; i++) { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 997 | hda_nid_t nid = cfg->hp_pins[i]; |
Takashi Iwai | 06dec22 | 2011-05-17 10:00:16 +0200 | [diff] [blame] | 998 | if (!is_jack_detectable(codec, nid)) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 999 | continue; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 1000 | snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n", |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 1001 | nid); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 1002 | snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 1003 | spec->detect_hp = 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 1004 | } |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 1005 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 1006 | if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) { |
| 1007 | if (cfg->speaker_outs) |
| 1008 | for (i = 0; i < cfg->line_outs; i++) { |
| 1009 | hda_nid_t nid = cfg->line_out_pins[i]; |
| 1010 | if (!is_jack_detectable(codec, nid)) |
| 1011 | continue; |
| 1012 | snd_printdd("realtek: Enable Line-Out " |
| 1013 | "auto-muting on NID 0x%x\n", nid); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 1014 | snd_hda_jack_detect_enable(codec, nid, |
| 1015 | ALC_FRONT_EVENT); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 1016 | spec->detect_lo = 1; |
| 1017 | } |
| 1018 | spec->automute_lo_possible = spec->detect_hp; |
| 1019 | } |
| 1020 | |
| 1021 | spec->automute_speaker_possible = cfg->speaker_outs && |
| 1022 | (spec->detect_hp || spec->detect_lo); |
| 1023 | |
| 1024 | spec->automute_lo = spec->automute_lo_possible; |
| 1025 | spec->automute_speaker = spec->automute_speaker_possible; |
| 1026 | |
David Henningsson | a7a0a64 | 2012-07-05 12:00:12 +0200 | [diff] [blame] | 1027 | if (spec->automute_speaker_possible || spec->automute_lo_possible) |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 1028 | /* create a control for automute mode */ |
| 1029 | alc_add_automute_mode_enum(codec); |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1030 | } |
| 1031 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1032 | /* return the position of NID in the list, or -1 if not found */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1033 | static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 1034 | { |
| 1035 | int i; |
| 1036 | for (i = 0; i < nums; i++) |
| 1037 | if (list[i] == nid) |
| 1038 | return i; |
| 1039 | return -1; |
| 1040 | } |
| 1041 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1042 | /* check whether dynamic ADC-switching is available */ |
| 1043 | static bool alc_check_dyn_adc_switch(struct hda_codec *codec) |
| 1044 | { |
| 1045 | struct alc_spec *spec = codec->spec; |
| 1046 | struct hda_input_mux *imux = &spec->private_imux[0]; |
| 1047 | int i, n, idx; |
| 1048 | hda_nid_t cap, pin; |
| 1049 | |
| 1050 | if (imux != spec->input_mux) /* no dynamic imux? */ |
| 1051 | return false; |
| 1052 | |
| 1053 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 1054 | cap = spec->private_capsrc_nids[n]; |
| 1055 | for (i = 0; i < imux->num_items; i++) { |
| 1056 | pin = spec->imux_pins[i]; |
| 1057 | if (!pin) |
| 1058 | return false; |
| 1059 | if (get_connection_index(codec, cap, pin) < 0) |
| 1060 | break; |
| 1061 | } |
| 1062 | if (i >= imux->num_items) |
Takashi Iwai | 268ff6f | 2011-07-08 14:37:35 +0200 | [diff] [blame] | 1063 | return true; /* no ADC-switch is needed */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | for (i = 0; i < imux->num_items; i++) { |
| 1067 | pin = spec->imux_pins[i]; |
| 1068 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 1069 | cap = spec->private_capsrc_nids[n]; |
| 1070 | idx = get_connection_index(codec, cap, pin); |
| 1071 | if (idx >= 0) { |
| 1072 | imux->items[i].index = idx; |
| 1073 | spec->dyn_adc_idx[i] = n; |
| 1074 | break; |
| 1075 | } |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | snd_printdd("realtek: enabling ADC switching\n"); |
| 1080 | spec->dyn_adc_switch = 1; |
| 1081 | return true; |
| 1082 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1083 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1084 | /* check whether all auto-mic pins are valid; setup indices if OK */ |
| 1085 | static bool alc_auto_mic_check_imux(struct hda_codec *codec) |
| 1086 | { |
| 1087 | struct alc_spec *spec = codec->spec; |
| 1088 | const struct hda_input_mux *imux; |
| 1089 | |
| 1090 | if (!spec->auto_mic) |
| 1091 | return false; |
| 1092 | if (spec->auto_mic_valid_imux) |
| 1093 | return true; /* already checked */ |
| 1094 | |
| 1095 | /* fill up imux indices */ |
| 1096 | if (!alc_check_dyn_adc_switch(codec)) { |
| 1097 | spec->auto_mic = 0; |
| 1098 | return false; |
| 1099 | } |
| 1100 | |
| 1101 | imux = spec->input_mux; |
| 1102 | spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin, |
| 1103 | spec->imux_pins, imux->num_items); |
| 1104 | spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin, |
| 1105 | spec->imux_pins, imux->num_items); |
| 1106 | spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin, |
| 1107 | spec->imux_pins, imux->num_items); |
| 1108 | if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) { |
| 1109 | spec->auto_mic = 0; |
| 1110 | return false; /* no corresponding imux */ |
| 1111 | } |
| 1112 | |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 1113 | snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1114 | if (spec->dock_mic_pin) |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 1115 | snd_hda_jack_detect_enable(codec, spec->dock_mic_pin, |
| 1116 | ALC_MIC_EVENT); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1117 | |
| 1118 | spec->auto_mic_valid_imux = 1; |
| 1119 | spec->auto_mic = 1; |
| 1120 | return true; |
| 1121 | } |
| 1122 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1123 | /* |
| 1124 | * Check the availability of auto-mic switch; |
| 1125 | * Set up if really supported |
| 1126 | */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1127 | static void alc_init_auto_mic(struct hda_codec *codec) |
| 1128 | { |
| 1129 | struct alc_spec *spec = codec->spec; |
| 1130 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1131 | hda_nid_t fixed, ext, dock; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1132 | int i; |
| 1133 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 1134 | if (spec->shared_mic_hp) |
| 1135 | return; /* no auto-mic for the shared I/O */ |
| 1136 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1137 | spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1; |
| 1138 | |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1139 | fixed = ext = dock = 0; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 1140 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1141 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1142 | unsigned int defcfg; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1143 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1144 | switch (snd_hda_get_input_pin_attr(defcfg)) { |
| 1145 | case INPUT_PIN_ATTR_INT: |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1146 | if (fixed) |
| 1147 | return; /* already occupied */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1148 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 1149 | return; /* invalid type */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1150 | fixed = nid; |
| 1151 | break; |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1152 | case INPUT_PIN_ATTR_UNUSED: |
| 1153 | return; /* invalid entry */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1154 | case INPUT_PIN_ATTR_DOCK: |
| 1155 | if (dock) |
| 1156 | return; /* already occupied */ |
| 1157 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) |
| 1158 | return; /* invalid type */ |
| 1159 | dock = nid; |
| 1160 | break; |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1161 | default: |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1162 | if (ext) |
| 1163 | return; /* already occupied */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1164 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 1165 | return; /* invalid type */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1166 | ext = nid; |
| 1167 | break; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1168 | } |
| 1169 | } |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1170 | if (!ext && dock) { |
| 1171 | ext = dock; |
| 1172 | dock = 0; |
| 1173 | } |
Takashi Iwai | eaa9b3a | 2010-01-17 13:09:33 +0100 | [diff] [blame] | 1174 | if (!ext || !fixed) |
| 1175 | return; |
Takashi Iwai | e35d9d6 | 2011-05-17 11:28:16 +0200 | [diff] [blame] | 1176 | if (!is_jack_detectable(codec, ext)) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1177 | return; /* no unsol support */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1178 | if (dock && !is_jack_detectable(codec, dock)) |
| 1179 | return; /* no unsol support */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1180 | |
| 1181 | /* check imux indices */ |
| 1182 | spec->ext_mic_pin = ext; |
| 1183 | spec->int_mic_pin = fixed; |
| 1184 | spec->dock_mic_pin = dock; |
| 1185 | |
| 1186 | spec->auto_mic = 1; |
| 1187 | if (!alc_auto_mic_check_imux(codec)) |
| 1188 | return; |
| 1189 | |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1190 | snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n", |
| 1191 | ext, fixed, dock); |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1192 | } |
| 1193 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1194 | /* check the availabilities of auto-mute and auto-mic switches */ |
| 1195 | static void alc_auto_check_switches(struct hda_codec *codec) |
| 1196 | { |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 1197 | alc_init_automute(codec); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1198 | alc_init_auto_mic(codec); |
| 1199 | } |
| 1200 | |
| 1201 | /* |
| 1202 | * Realtek SSID verification |
| 1203 | */ |
| 1204 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1205 | /* Could be any non-zero and even value. When used as fixup, tells |
| 1206 | * the driver to ignore any present sku defines. |
| 1207 | */ |
| 1208 | #define ALC_FIXUP_SKU_IGNORE (2) |
| 1209 | |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 1210 | static void alc_fixup_sku_ignore(struct hda_codec *codec, |
| 1211 | const struct hda_fixup *fix, int action) |
| 1212 | { |
| 1213 | struct alc_spec *spec = codec->spec; |
| 1214 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { |
| 1215 | spec->cdefine.fixup = 1; |
| 1216 | spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE; |
| 1217 | } |
| 1218 | } |
| 1219 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1220 | static int alc_auto_parse_customize_define(struct hda_codec *codec) |
| 1221 | { |
| 1222 | unsigned int ass, tmp, i; |
Takashi Iwai | 7fb5622 | 2010-03-22 17:09:47 +0100 | [diff] [blame] | 1223 | unsigned nid = 0; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1224 | struct alc_spec *spec = codec->spec; |
| 1225 | |
Takashi Iwai | b6cbe51 | 2010-07-28 17:43:36 +0200 | [diff] [blame] | 1226 | spec->cdefine.enable_pcbeep = 1; /* assume always enabled */ |
| 1227 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1228 | if (spec->cdefine.fixup) { |
| 1229 | ass = spec->cdefine.sku_cfg; |
| 1230 | if (ass == ALC_FIXUP_SKU_IGNORE) |
| 1231 | return -1; |
| 1232 | goto do_sku; |
| 1233 | } |
| 1234 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1235 | ass = codec->subsystem_id & 0xffff; |
Takashi Iwai | b6cbe51 | 2010-07-28 17:43:36 +0200 | [diff] [blame] | 1236 | if (ass != codec->bus->pci->subsystem_device && (ass & 1)) |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1237 | goto do_sku; |
| 1238 | |
| 1239 | nid = 0x1d; |
| 1240 | if (codec->vendor_id == 0x10ec0260) |
| 1241 | nid = 0x17; |
| 1242 | ass = snd_hda_codec_get_pincfg(codec, nid); |
| 1243 | |
| 1244 | if (!(ass & 1)) { |
| 1245 | printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n", |
| 1246 | codec->chip_name, ass); |
| 1247 | return -1; |
| 1248 | } |
| 1249 | |
| 1250 | /* check sum */ |
| 1251 | tmp = 0; |
| 1252 | for (i = 1; i < 16; i++) { |
| 1253 | if ((ass >> i) & 1) |
| 1254 | tmp++; |
| 1255 | } |
| 1256 | if (((ass >> 16) & 0xf) != tmp) |
| 1257 | return -1; |
| 1258 | |
| 1259 | spec->cdefine.port_connectivity = ass >> 30; |
| 1260 | spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20; |
| 1261 | spec->cdefine.check_sum = (ass >> 16) & 0xf; |
| 1262 | spec->cdefine.customization = ass >> 8; |
| 1263 | do_sku: |
| 1264 | spec->cdefine.sku_cfg = ass; |
| 1265 | spec->cdefine.external_amp = (ass & 0x38) >> 3; |
| 1266 | spec->cdefine.platform_type = (ass & 0x4) >> 2; |
| 1267 | spec->cdefine.swap = (ass & 0x2) >> 1; |
| 1268 | spec->cdefine.override = ass & 0x1; |
| 1269 | |
| 1270 | snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n", |
| 1271 | nid, spec->cdefine.sku_cfg); |
| 1272 | snd_printd("SKU: port_connectivity=0x%x\n", |
| 1273 | spec->cdefine.port_connectivity); |
| 1274 | snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep); |
| 1275 | snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum); |
| 1276 | snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization); |
| 1277 | snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp); |
| 1278 | snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type); |
| 1279 | snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap); |
| 1280 | snd_printd("SKU: override=0x%x\n", spec->cdefine.override); |
| 1281 | |
| 1282 | return 0; |
| 1283 | } |
| 1284 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1285 | /* return true if the given NID is found in the list */ |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1286 | static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 1287 | { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1288 | return find_idx_in_nid_list(nid, list, nums) >= 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1289 | } |
| 1290 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1291 | /* check subsystem ID and set up device-specific initialization; |
| 1292 | * return 1 if initialized, 0 if invalid SSID |
| 1293 | */ |
| 1294 | /* 32-bit subsystem ID for BIOS loading in HD Audio codec. |
| 1295 | * 31 ~ 16 : Manufacture ID |
| 1296 | * 15 ~ 8 : SKU ID |
| 1297 | * 7 ~ 0 : Assembly ID |
| 1298 | * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36 |
| 1299 | */ |
| 1300 | static int alc_subsystem_id(struct hda_codec *codec, |
| 1301 | hda_nid_t porta, hda_nid_t porte, |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1302 | hda_nid_t portd, hda_nid_t porti) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1303 | { |
| 1304 | unsigned int ass, tmp, i; |
| 1305 | unsigned nid; |
| 1306 | struct alc_spec *spec = codec->spec; |
| 1307 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1308 | if (spec->cdefine.fixup) { |
| 1309 | ass = spec->cdefine.sku_cfg; |
| 1310 | if (ass == ALC_FIXUP_SKU_IGNORE) |
| 1311 | return 0; |
| 1312 | goto do_sku; |
| 1313 | } |
| 1314 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1315 | ass = codec->subsystem_id & 0xffff; |
| 1316 | if ((ass != codec->bus->pci->subsystem_device) && (ass & 1)) |
| 1317 | goto do_sku; |
| 1318 | |
| 1319 | /* invalid SSID, check the special NID pin defcfg instead */ |
| 1320 | /* |
Sasha Alexandr | def319f | 2009-06-16 16:00:15 -0400 | [diff] [blame] | 1321 | * 31~30 : port connectivity |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1322 | * 29~21 : reserve |
| 1323 | * 20 : PCBEEP input |
| 1324 | * 19~16 : Check sum (15:1) |
| 1325 | * 15~1 : Custom |
| 1326 | * 0 : override |
| 1327 | */ |
| 1328 | nid = 0x1d; |
| 1329 | if (codec->vendor_id == 0x10ec0260) |
| 1330 | nid = 0x17; |
| 1331 | ass = snd_hda_codec_get_pincfg(codec, nid); |
| 1332 | snd_printd("realtek: No valid SSID, " |
| 1333 | "checking pincfg 0x%08x for NID 0x%x\n", |
Takashi Iwai | cb6605c | 2009-04-28 13:03:19 +0200 | [diff] [blame] | 1334 | ass, nid); |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1335 | if (!(ass & 1)) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1336 | return 0; |
| 1337 | if ((ass >> 30) != 1) /* no physical connection */ |
| 1338 | return 0; |
| 1339 | |
| 1340 | /* check sum */ |
| 1341 | tmp = 0; |
| 1342 | for (i = 1; i < 16; i++) { |
| 1343 | if ((ass >> i) & 1) |
| 1344 | tmp++; |
| 1345 | } |
| 1346 | if (((ass >> 16) & 0xf) != tmp) |
| 1347 | return 0; |
| 1348 | do_sku: |
| 1349 | snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n", |
| 1350 | ass & 0xffff, codec->vendor_id); |
| 1351 | /* |
| 1352 | * 0 : override |
| 1353 | * 1 : Swap Jack |
| 1354 | * 2 : 0 --> Desktop, 1 --> Laptop |
| 1355 | * 3~5 : External Amplifier control |
| 1356 | * 7~6 : Reserved |
| 1357 | */ |
| 1358 | tmp = (ass & 0x38) >> 3; /* external Amp control */ |
| 1359 | switch (tmp) { |
| 1360 | case 1: |
| 1361 | spec->init_amp = ALC_INIT_GPIO1; |
| 1362 | break; |
| 1363 | case 3: |
| 1364 | spec->init_amp = ALC_INIT_GPIO2; |
| 1365 | break; |
| 1366 | case 7: |
| 1367 | spec->init_amp = ALC_INIT_GPIO3; |
| 1368 | break; |
| 1369 | case 5: |
Takashi Iwai | 5a8cfb4 | 2010-11-26 17:11:18 +0100 | [diff] [blame] | 1370 | default: |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1371 | spec->init_amp = ALC_INIT_DEFAULT; |
| 1372 | break; |
| 1373 | } |
| 1374 | |
| 1375 | /* is laptop or Desktop and enable the function "Mute internal speaker |
| 1376 | * when the external headphone out jack is plugged" |
| 1377 | */ |
| 1378 | if (!(ass & 0x8000)) |
| 1379 | return 1; |
| 1380 | /* |
| 1381 | * 10~8 : Jack location |
| 1382 | * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered |
| 1383 | * 14~13: Resvered |
| 1384 | * 15 : 1 --> enable the function "Mute internal speaker |
| 1385 | * when the external headphone out jack is plugged" |
| 1386 | */ |
Takashi Iwai | 5fe6e01 | 2011-09-26 10:41:21 +0200 | [diff] [blame] | 1387 | if (!spec->autocfg.hp_pins[0] && |
| 1388 | !(spec->autocfg.line_out_pins[0] && |
| 1389 | spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) { |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1390 | hda_nid_t nid; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1391 | tmp = (ass >> 11) & 0x3; /* HP to chassis */ |
| 1392 | if (tmp == 0) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1393 | nid = porta; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1394 | else if (tmp == 1) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1395 | nid = porte; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1396 | else if (tmp == 2) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1397 | nid = portd; |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1398 | else if (tmp == 3) |
| 1399 | nid = porti; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1400 | else |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1401 | return 1; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1402 | if (found_in_nid_list(nid, spec->autocfg.line_out_pins, |
| 1403 | spec->autocfg.line_outs)) |
| 1404 | return 1; |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1405 | spec->autocfg.hp_pins[0] = nid; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1406 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1407 | return 1; |
| 1408 | } |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 1409 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 1410 | /* Check the validity of ALC subsystem-id |
| 1411 | * ports contains an array of 4 pin NIDs for port-A, E, D and I */ |
| 1412 | static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1413 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 1414 | if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) { |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1415 | struct alc_spec *spec = codec->spec; |
| 1416 | snd_printd("realtek: " |
| 1417 | "Enable default setup for auto mode as fallback\n"); |
| 1418 | spec->init_amp = ALC_INIT_DEFAULT; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1419 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1420 | } |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 1421 | |
Takashi Iwai | 41e41f1 | 2005-06-08 14:48:49 +0200 | [diff] [blame] | 1422 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1423 | * COEF access helper functions |
| 1424 | */ |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 1425 | static int alc_read_coef_idx(struct hda_codec *codec, |
| 1426 | unsigned int coef_idx) |
| 1427 | { |
| 1428 | unsigned int val; |
| 1429 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, |
| 1430 | coef_idx); |
| 1431 | val = snd_hda_codec_read(codec, 0x20, 0, |
| 1432 | AC_VERB_GET_PROC_COEF, 0); |
| 1433 | return val; |
| 1434 | } |
| 1435 | |
Kailang Yang | 977ddd6 | 2010-09-15 10:02:29 +0200 | [diff] [blame] | 1436 | static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx, |
| 1437 | unsigned int coef_val) |
| 1438 | { |
| 1439 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, |
| 1440 | coef_idx); |
| 1441 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, |
| 1442 | coef_val); |
| 1443 | } |
| 1444 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 1445 | /* a special bypass for COEF 0; read the cached value at the second time */ |
| 1446 | static unsigned int alc_get_coef0(struct hda_codec *codec) |
| 1447 | { |
| 1448 | struct alc_spec *spec = codec->spec; |
| 1449 | if (!spec->coef0) |
| 1450 | spec->coef0 = alc_read_coef_idx(codec, 0); |
| 1451 | return spec->coef0; |
| 1452 | } |
| 1453 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1454 | /* |
| 1455 | * Digital I/O handling |
| 1456 | */ |
| 1457 | |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1458 | /* set right pin controls for digital I/O */ |
| 1459 | static void alc_auto_init_digital(struct hda_codec *codec) |
| 1460 | { |
| 1461 | struct alc_spec *spec = codec->spec; |
| 1462 | int i; |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 1463 | hda_nid_t pin, dac; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1464 | |
| 1465 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
| 1466 | pin = spec->autocfg.dig_out_pins[i]; |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 1467 | if (!pin) |
| 1468 | continue; |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 1469 | snd_hda_set_pin_ctl(codec, pin, PIN_OUT); |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 1470 | if (!i) |
| 1471 | dac = spec->multiout.dig_out_nid; |
| 1472 | else |
| 1473 | dac = spec->slave_dig_outs[i - 1]; |
| 1474 | if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP)) |
| 1475 | continue; |
| 1476 | snd_hda_codec_write(codec, dac, 0, |
| 1477 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 1478 | AMP_OUT_UNMUTE); |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1479 | } |
| 1480 | pin = spec->autocfg.dig_in_pin; |
| 1481 | if (pin) |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 1482 | snd_hda_set_pin_ctl(codec, pin, PIN_IN); |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */ |
| 1486 | static void alc_auto_parse_digital(struct hda_codec *codec) |
| 1487 | { |
| 1488 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1489 | int i, err, nums; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1490 | hda_nid_t dig_nid; |
| 1491 | |
| 1492 | /* support multiple SPDIFs; the secondary is set up as a slave */ |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1493 | nums = 0; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1494 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1495 | hda_nid_t conn[4]; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1496 | err = snd_hda_get_connections(codec, |
| 1497 | spec->autocfg.dig_out_pins[i], |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1498 | conn, ARRAY_SIZE(conn)); |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1499 | if (err <= 0) |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1500 | continue; |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1501 | dig_nid = conn[0]; /* assume the first element is audio-out */ |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1502 | if (!nums) { |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1503 | spec->multiout.dig_out_nid = dig_nid; |
| 1504 | spec->dig_out_type = spec->autocfg.dig_out_type[0]; |
| 1505 | } else { |
| 1506 | spec->multiout.slave_dig_outs = spec->slave_dig_outs; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1507 | if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1) |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1508 | break; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1509 | spec->slave_dig_outs[nums - 1] = dig_nid; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1510 | } |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1511 | nums++; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | if (spec->autocfg.dig_in_pin) { |
Takashi Iwai | 01fdf18 | 2010-09-24 09:09:42 +0200 | [diff] [blame] | 1515 | dig_nid = codec->start_nid; |
| 1516 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { |
| 1517 | unsigned int wcaps = get_wcaps(codec, dig_nid); |
| 1518 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
| 1519 | continue; |
| 1520 | if (!(wcaps & AC_WCAP_DIGITAL)) |
| 1521 | continue; |
| 1522 | if (!(wcaps & AC_WCAP_CONN_LIST)) |
| 1523 | continue; |
| 1524 | err = get_connection_index(codec, dig_nid, |
| 1525 | spec->autocfg.dig_in_pin); |
| 1526 | if (err >= 0) { |
| 1527 | spec->dig_in_nid = dig_nid; |
| 1528 | break; |
| 1529 | } |
| 1530 | } |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1531 | } |
| 1532 | } |
| 1533 | |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1534 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1535 | * capture mixer elements |
Vincent Petry | ef8ef5f | 2008-11-23 11:31:41 +0800 | [diff] [blame] | 1536 | */ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1537 | static int alc_cap_vol_info(struct snd_kcontrol *kcontrol, |
| 1538 | struct snd_ctl_elem_info *uinfo) |
| 1539 | { |
| 1540 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1541 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1542 | unsigned long val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1543 | int err; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1544 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1545 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1546 | if (spec->vol_in_capsrc) |
| 1547 | val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT); |
| 1548 | else |
| 1549 | val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT); |
| 1550 | kcontrol->private_value = val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1551 | err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo); |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1552 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1553 | return err; |
| 1554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1556 | static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, |
| 1557 | unsigned int size, unsigned int __user *tlv) |
| 1558 | { |
| 1559 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1560 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1561 | unsigned long val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1562 | int err; |
| 1563 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1564 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1565 | if (spec->vol_in_capsrc) |
| 1566 | val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT); |
| 1567 | else |
| 1568 | val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT); |
| 1569 | kcontrol->private_value = val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1570 | err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv); |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1571 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1572 | return err; |
| 1573 | } |
| 1574 | |
| 1575 | typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol, |
| 1576 | struct snd_ctl_elem_value *ucontrol); |
| 1577 | |
| 1578 | static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol, |
| 1579 | struct snd_ctl_elem_value *ucontrol, |
Takashi Iwai | 125821a | 2012-06-22 14:30:29 +0200 | [diff] [blame] | 1580 | getput_call_t func, bool is_put) |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1581 | { |
| 1582 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1583 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1584 | int i, err = 0; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1585 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1586 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | 125821a | 2012-06-22 14:30:29 +0200 | [diff] [blame] | 1587 | if (is_put && spec->dyn_adc_switch) { |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1588 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 1589 | kcontrol->private_value = |
| 1590 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], |
| 1591 | 3, 0, HDA_INPUT); |
| 1592 | err = func(kcontrol, ucontrol); |
| 1593 | if (err < 0) |
| 1594 | goto error; |
| 1595 | } |
| 1596 | } else { |
| 1597 | i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1598 | if (spec->vol_in_capsrc) |
| 1599 | kcontrol->private_value = |
| 1600 | HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i], |
| 1601 | 3, 0, HDA_OUTPUT); |
| 1602 | else |
| 1603 | kcontrol->private_value = |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1604 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], |
| 1605 | 3, 0, HDA_INPUT); |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1606 | err = func(kcontrol, ucontrol); |
| 1607 | } |
Takashi Iwai | 125821a | 2012-06-22 14:30:29 +0200 | [diff] [blame] | 1608 | if (err >= 0 && is_put) |
| 1609 | alc_inv_dmic_sync(codec, false); |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1610 | error: |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1611 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1612 | return err; |
| 1613 | } |
| 1614 | |
| 1615 | static int alc_cap_vol_get(struct snd_kcontrol *kcontrol, |
| 1616 | struct snd_ctl_elem_value *ucontrol) |
| 1617 | { |
| 1618 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1619 | snd_hda_mixer_amp_volume_get, false); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | static int alc_cap_vol_put(struct snd_kcontrol *kcontrol, |
| 1623 | struct snd_ctl_elem_value *ucontrol) |
| 1624 | { |
| 1625 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1626 | snd_hda_mixer_amp_volume_put, true); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | /* capture mixer elements */ |
| 1630 | #define alc_cap_sw_info snd_ctl_boolean_stereo_info |
| 1631 | |
| 1632 | static int alc_cap_sw_get(struct snd_kcontrol *kcontrol, |
| 1633 | struct snd_ctl_elem_value *ucontrol) |
| 1634 | { |
| 1635 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1636 | snd_hda_mixer_amp_switch_get, false); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | static int alc_cap_sw_put(struct snd_kcontrol *kcontrol, |
| 1640 | struct snd_ctl_elem_value *ucontrol) |
| 1641 | { |
| 1642 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1643 | snd_hda_mixer_amp_switch_put, true); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1644 | } |
| 1645 | |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1646 | #define _DEFINE_CAPMIX(num) \ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1647 | { \ |
| 1648 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1649 | .name = "Capture Switch", \ |
| 1650 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \ |
| 1651 | .count = num, \ |
| 1652 | .info = alc_cap_sw_info, \ |
| 1653 | .get = alc_cap_sw_get, \ |
| 1654 | .put = alc_cap_sw_put, \ |
| 1655 | }, \ |
| 1656 | { \ |
| 1657 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1658 | .name = "Capture Volume", \ |
| 1659 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \ |
| 1660 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ |
| 1661 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \ |
| 1662 | .count = num, \ |
| 1663 | .info = alc_cap_vol_info, \ |
| 1664 | .get = alc_cap_vol_get, \ |
| 1665 | .put = alc_cap_vol_put, \ |
| 1666 | .tlv = { .c = alc_cap_vol_tlv }, \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | #define _DEFINE_CAPSRC(num) \ |
Takashi Iwai | 3c3e989 | 2008-10-31 17:48:56 +0100 | [diff] [blame] | 1670 | { \ |
| 1671 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1672 | /* .name = "Capture Source", */ \ |
| 1673 | .name = "Input Source", \ |
| 1674 | .count = num, \ |
| 1675 | .info = alc_mux_enum_info, \ |
| 1676 | .get = alc_mux_enum_get, \ |
| 1677 | .put = alc_mux_enum_put, \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | #define DEFINE_CAPMIX(num) \ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1681 | static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1682 | _DEFINE_CAPMIX(num), \ |
| 1683 | _DEFINE_CAPSRC(num), \ |
| 1684 | { } /* end */ \ |
| 1685 | } |
| 1686 | |
| 1687 | #define DEFINE_CAPMIX_NOSRC(num) \ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1688 | static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1689 | _DEFINE_CAPMIX(num), \ |
| 1690 | { } /* end */ \ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | /* up to three ADCs */ |
| 1694 | DEFINE_CAPMIX(1); |
| 1695 | DEFINE_CAPMIX(2); |
| 1696 | DEFINE_CAPMIX(3); |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1697 | DEFINE_CAPMIX_NOSRC(1); |
| 1698 | DEFINE_CAPMIX_NOSRC(2); |
| 1699 | DEFINE_CAPMIX_NOSRC(3); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1700 | |
| 1701 | /* |
Takashi Iwai | 125821a | 2012-06-22 14:30:29 +0200 | [diff] [blame] | 1702 | * Inverted digital-mic handling |
| 1703 | * |
| 1704 | * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch" |
| 1705 | * gives the additional mute only to the right channel of the digital mic |
| 1706 | * capture stream. This is a workaround for avoiding the almost silence |
| 1707 | * by summing the stereo stream from some (known to be ForteMedia) |
| 1708 | * digital mic unit. |
| 1709 | * |
| 1710 | * The logic is to call alc_inv_dmic_sync() after each action (possibly) |
| 1711 | * modifying ADC amp. When the mute flag is set, it mutes the R-channel |
| 1712 | * without caching so that the cache can still keep the original value. |
| 1713 | * The cached value is then restored when the flag is set off or any other |
| 1714 | * than d-mic is used as the current input source. |
| 1715 | */ |
| 1716 | static void alc_inv_dmic_sync(struct hda_codec *codec, bool force) |
| 1717 | { |
| 1718 | struct alc_spec *spec = codec->spec; |
| 1719 | int i; |
| 1720 | |
| 1721 | if (!spec->inv_dmic_fixup) |
| 1722 | return; |
| 1723 | if (!spec->inv_dmic_muted && !force) |
| 1724 | return; |
| 1725 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 1726 | int src = spec->dyn_adc_switch ? 0 : i; |
| 1727 | bool dmic_fixup = false; |
| 1728 | hda_nid_t nid; |
| 1729 | int parm, dir, v; |
| 1730 | |
| 1731 | if (spec->inv_dmic_muted && |
| 1732 | spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin) |
| 1733 | dmic_fixup = true; |
| 1734 | if (!dmic_fixup && !force) |
| 1735 | continue; |
| 1736 | if (spec->vol_in_capsrc) { |
| 1737 | nid = spec->capsrc_nids[i]; |
| 1738 | parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT; |
| 1739 | dir = HDA_OUTPUT; |
| 1740 | } else { |
| 1741 | nid = spec->adc_nids[i]; |
| 1742 | parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT; |
| 1743 | dir = HDA_INPUT; |
| 1744 | } |
| 1745 | /* we care only right channel */ |
| 1746 | v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0); |
| 1747 | if (v & 0x80) /* if already muted, we don't need to touch */ |
| 1748 | continue; |
| 1749 | if (dmic_fixup) /* add mute for d-mic */ |
| 1750 | v |= 0x80; |
| 1751 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 1752 | parm | v); |
| 1753 | } |
| 1754 | } |
| 1755 | |
| 1756 | static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol, |
| 1757 | struct snd_ctl_elem_value *ucontrol) |
| 1758 | { |
| 1759 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1760 | struct alc_spec *spec = codec->spec; |
| 1761 | |
| 1762 | ucontrol->value.integer.value[0] = !spec->inv_dmic_muted; |
| 1763 | return 0; |
| 1764 | } |
| 1765 | |
| 1766 | static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol, |
| 1767 | struct snd_ctl_elem_value *ucontrol) |
| 1768 | { |
| 1769 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1770 | struct alc_spec *spec = codec->spec; |
| 1771 | unsigned int val = !ucontrol->value.integer.value[0]; |
| 1772 | |
| 1773 | if (val == spec->inv_dmic_muted) |
| 1774 | return 0; |
| 1775 | spec->inv_dmic_muted = val; |
| 1776 | alc_inv_dmic_sync(codec, true); |
| 1777 | return 0; |
| 1778 | } |
| 1779 | |
| 1780 | static const struct snd_kcontrol_new alc_inv_dmic_sw = { |
| 1781 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1782 | .info = snd_ctl_boolean_mono_info, |
| 1783 | .get = alc_inv_dmic_sw_get, |
| 1784 | .put = alc_inv_dmic_sw_put, |
| 1785 | }; |
| 1786 | |
| 1787 | static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid) |
| 1788 | { |
| 1789 | struct alc_spec *spec = codec->spec; |
| 1790 | struct snd_kcontrol_new *knew = alc_kcontrol_new(spec); |
| 1791 | if (!knew) |
| 1792 | return -ENOMEM; |
| 1793 | *knew = alc_inv_dmic_sw; |
| 1794 | knew->name = kstrdup("Inverted Internal Mic Capture Switch", GFP_KERNEL); |
| 1795 | if (!knew->name) |
| 1796 | return -ENOMEM; |
| 1797 | spec->inv_dmic_fixup = 1; |
| 1798 | spec->inv_dmic_muted = 0; |
| 1799 | spec->inv_dmic_pin = nid; |
| 1800 | return 0; |
| 1801 | } |
| 1802 | |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 1803 | /* typically the digital mic is put at node 0x12 */ |
| 1804 | static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec, |
| 1805 | const struct alc_fixup *fix, int action) |
| 1806 | { |
| 1807 | if (action == ALC_FIXUP_ACT_PROBE) |
| 1808 | alc_add_inv_dmic_mixer(codec, 0x12); |
| 1809 | } |
| 1810 | |
Takashi Iwai | 125821a | 2012-06-22 14:30:29 +0200 | [diff] [blame] | 1811 | /* |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1812 | * virtual master controls |
| 1813 | */ |
| 1814 | |
| 1815 | /* |
| 1816 | * slave controls for virtual master |
| 1817 | */ |
Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 1818 | static const char * const alc_slave_pfxs[] = { |
| 1819 | "Front", "Surround", "Center", "LFE", "Side", |
Takashi Iwai | 7c58975 | 2012-03-02 09:00:33 +0100 | [diff] [blame] | 1820 | "Headphone", "Speaker", "Mono", "Line Out", |
Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 1821 | "CLFE", "Bass Speaker", "PCM", |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1822 | NULL, |
| 1823 | }; |
| 1824 | |
| 1825 | /* |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1826 | * build control elements |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | */ |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1828 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1829 | #define NID_MAPPING (-1) |
| 1830 | |
| 1831 | #define SUBDEV_SPEAKER_ (0 << 6) |
| 1832 | #define SUBDEV_HP_ (1 << 6) |
| 1833 | #define SUBDEV_LINE_ (2 << 6) |
| 1834 | #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f)) |
| 1835 | #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f)) |
| 1836 | #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f)) |
| 1837 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1838 | static void alc_free_kctls(struct hda_codec *codec); |
| 1839 | |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1840 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1841 | /* additional beep mixers; the actual parameters are overwritten at build */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1842 | static const struct snd_kcontrol_new alc_beep_mixer[] = { |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1843 | HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT), |
Jaroslav Kysela | 123c07a | 2009-10-21 14:48:23 +0200 | [diff] [blame] | 1844 | HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT), |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1845 | { } /* end */ |
| 1846 | }; |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1847 | #endif |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1848 | |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 1849 | static int __alc_build_controls(struct hda_codec *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | { |
| 1851 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2f44f84 | 2010-06-22 11:12:32 +0200 | [diff] [blame] | 1852 | struct snd_kcontrol *kctl = NULL; |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1853 | const struct snd_kcontrol_new *knew; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1854 | int i, j, err; |
| 1855 | unsigned int u; |
| 1856 | hda_nid_t nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | |
| 1858 | for (i = 0; i < spec->num_mixers; i++) { |
| 1859 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 1860 | if (err < 0) |
| 1861 | return err; |
| 1862 | } |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1863 | if (spec->cap_mixer) { |
| 1864 | err = snd_hda_add_new_ctls(codec, spec->cap_mixer); |
| 1865 | if (err < 0) |
| 1866 | return err; |
| 1867 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | if (spec->multiout.dig_out_nid) { |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 1869 | err = snd_hda_create_spdif_out_ctls(codec, |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 1870 | spec->multiout.dig_out_nid, |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 1871 | spec->multiout.dig_out_nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | if (err < 0) |
| 1873 | return err; |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1874 | if (!spec->no_analog) { |
| 1875 | err = snd_hda_create_spdif_share_sw(codec, |
| 1876 | &spec->multiout); |
| 1877 | if (err < 0) |
| 1878 | return err; |
| 1879 | spec->multiout.share_spdif = 1; |
| 1880 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | } |
| 1882 | if (spec->dig_in_nid) { |
| 1883 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); |
| 1884 | if (err < 0) |
| 1885 | return err; |
| 1886 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1887 | |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1888 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1889 | /* create beep controls if needed */ |
| 1890 | if (spec->beep_amp) { |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1891 | const struct snd_kcontrol_new *knew; |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1892 | for (knew = alc_beep_mixer; knew->name; knew++) { |
| 1893 | struct snd_kcontrol *kctl; |
| 1894 | kctl = snd_ctl_new1(knew, codec); |
| 1895 | if (!kctl) |
| 1896 | return -ENOMEM; |
| 1897 | kctl->private_value = spec->beep_amp; |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 1898 | err = snd_hda_ctl_add(codec, 0, kctl); |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1899 | if (err < 0) |
| 1900 | return err; |
| 1901 | } |
| 1902 | } |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1903 | #endif |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1904 | |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1905 | /* if we have no master control, let's create it */ |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1906 | if (!spec->no_analog && |
| 1907 | !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1908 | unsigned int vmaster_tlv[4]; |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1909 | snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1910 | HDA_OUTPUT, vmaster_tlv); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1911 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", |
Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 1912 | vmaster_tlv, alc_slave_pfxs, |
| 1913 | "Playback Volume"); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1914 | if (err < 0) |
| 1915 | return err; |
| 1916 | } |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1917 | if (!spec->no_analog && |
| 1918 | !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { |
Takashi Iwai | 420b0fe | 2012-03-12 12:35:27 +0100 | [diff] [blame] | 1919 | err = __snd_hda_add_vmaster(codec, "Master Playback Switch", |
| 1920 | NULL, alc_slave_pfxs, |
| 1921 | "Playback Switch", |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 1922 | true, &spec->vmaster_mute.sw_kctl); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1923 | if (err < 0) |
| 1924 | return err; |
| 1925 | } |
| 1926 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1927 | /* assign Capture Source enums to NID */ |
Takashi Iwai | fbe618f | 2010-06-11 11:24:58 +0200 | [diff] [blame] | 1928 | if (spec->capsrc_nids || spec->adc_nids) { |
| 1929 | kctl = snd_hda_find_mixer_ctl(codec, "Capture Source"); |
| 1930 | if (!kctl) |
| 1931 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); |
| 1932 | for (i = 0; kctl && i < kctl->count; i++) { |
Takashi Iwai | 6107159 | 2011-11-23 07:52:15 +0100 | [diff] [blame] | 1933 | err = snd_hda_add_nid(codec, kctl, i, |
| 1934 | get_capsrc(spec, i)); |
Takashi Iwai | fbe618f | 2010-06-11 11:24:58 +0200 | [diff] [blame] | 1935 | if (err < 0) |
| 1936 | return err; |
| 1937 | } |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1938 | } |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 1939 | if (spec->cap_mixer && spec->adc_nids) { |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1940 | const char *kname = kctl ? kctl->id.name : NULL; |
| 1941 | for (knew = spec->cap_mixer; knew->name; knew++) { |
| 1942 | if (kname && strcmp(knew->name, kname) == 0) |
| 1943 | continue; |
| 1944 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 1945 | for (i = 0; kctl && i < kctl->count; i++) { |
| 1946 | err = snd_hda_add_nid(codec, kctl, i, |
| 1947 | spec->adc_nids[i]); |
| 1948 | if (err < 0) |
| 1949 | return err; |
| 1950 | } |
| 1951 | } |
| 1952 | } |
| 1953 | |
| 1954 | /* other nid->control mapping */ |
| 1955 | for (i = 0; i < spec->num_mixers; i++) { |
| 1956 | for (knew = spec->mixers[i]; knew->name; knew++) { |
| 1957 | if (knew->iface != NID_MAPPING) |
| 1958 | continue; |
| 1959 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 1960 | if (kctl == NULL) |
| 1961 | continue; |
| 1962 | u = knew->subdevice; |
| 1963 | for (j = 0; j < 4; j++, u >>= 8) { |
| 1964 | nid = u & 0x3f; |
| 1965 | if (nid == 0) |
| 1966 | continue; |
| 1967 | switch (u & 0xc0) { |
| 1968 | case SUBDEV_SPEAKER_: |
| 1969 | nid = spec->autocfg.speaker_pins[nid]; |
| 1970 | break; |
| 1971 | case SUBDEV_LINE_: |
| 1972 | nid = spec->autocfg.line_out_pins[nid]; |
| 1973 | break; |
| 1974 | case SUBDEV_HP_: |
| 1975 | nid = spec->autocfg.hp_pins[nid]; |
| 1976 | break; |
| 1977 | default: |
| 1978 | continue; |
| 1979 | } |
| 1980 | err = snd_hda_add_nid(codec, kctl, 0, nid); |
| 1981 | if (err < 0) |
| 1982 | return err; |
| 1983 | } |
| 1984 | u = knew->private_value; |
| 1985 | for (j = 0; j < 4; j++, u >>= 8) { |
| 1986 | nid = u & 0xff; |
| 1987 | if (nid == 0) |
| 1988 | continue; |
| 1989 | err = snd_hda_add_nid(codec, kctl, 0, nid); |
| 1990 | if (err < 0) |
| 1991 | return err; |
| 1992 | } |
| 1993 | } |
| 1994 | } |
Takashi Iwai | bae84e7 | 2010-03-22 08:30:20 +0100 | [diff] [blame] | 1995 | |
| 1996 | alc_free_kctls(codec); /* no longer needed */ |
| 1997 | |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 1998 | return 0; |
| 1999 | } |
| 2000 | |
David Henningsson | 5780b62 | 2012-06-27 18:45:45 +0200 | [diff] [blame] | 2001 | static int alc_build_jacks(struct hda_codec *codec) |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 2002 | { |
| 2003 | struct alc_spec *spec = codec->spec; |
David Henningsson | 5780b62 | 2012-06-27 18:45:45 +0200 | [diff] [blame] | 2004 | |
| 2005 | if (spec->shared_mic_hp) { |
| 2006 | int err; |
| 2007 | int nid = spec->autocfg.inputs[1].pin; |
| 2008 | err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0); |
| 2009 | if (err < 0) |
| 2010 | return err; |
| 2011 | err = snd_hda_jack_detect_enable(codec, nid, 0); |
| 2012 | if (err < 0) |
| 2013 | return err; |
| 2014 | } |
| 2015 | |
| 2016 | return snd_hda_jack_add_kctls(codec, &spec->autocfg); |
| 2017 | } |
| 2018 | |
| 2019 | static int alc_build_controls(struct hda_codec *codec) |
| 2020 | { |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 2021 | int err = __alc_build_controls(codec); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 2022 | if (err < 0) |
| 2023 | return err; |
David Henningsson | 5780b62 | 2012-06-27 18:45:45 +0200 | [diff] [blame] | 2024 | |
| 2025 | err = alc_build_jacks(codec); |
Takashi Iwai | 420b0fe | 2012-03-12 12:35:27 +0100 | [diff] [blame] | 2026 | if (err < 0) |
| 2027 | return err; |
| 2028 | alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD); |
| 2029 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2032 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | /* |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2034 | * Common callbacks |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2035 | */ |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 2036 | |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 2037 | static void alc_init_special_input_src(struct hda_codec *codec); |
Takashi Iwai | 070cff4 | 2012-02-21 12:54:17 +0100 | [diff] [blame] | 2038 | static void alc_auto_init_std(struct hda_codec *codec); |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 2039 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | static int alc_init(struct hda_codec *codec) |
| 2041 | { |
| 2042 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2043 | |
Takashi Iwai | 546bb67 | 2012-03-07 08:37:19 +0100 | [diff] [blame] | 2044 | if (spec->init_hook) |
| 2045 | spec->init_hook(codec); |
Kailang Yang | 526af6e | 2012-03-07 08:25:20 +0100 | [diff] [blame] | 2046 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 2047 | alc_fix_pll(codec); |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 2048 | alc_auto_init_amp(codec, spec->init_amp); |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 2049 | |
Takashi Iwai | 2e8b2b2 | 2012-06-13 16:47:32 +0200 | [diff] [blame] | 2050 | snd_hda_gen_apply_verbs(codec); |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 2051 | alc_init_special_input_src(codec); |
Takashi Iwai | 070cff4 | 2012-02-21 12:54:17 +0100 | [diff] [blame] | 2052 | alc_auto_init_std(codec); |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2053 | |
Takashi Iwai | 5870112 | 2011-01-13 15:41:45 +0100 | [diff] [blame] | 2054 | alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT); |
| 2055 | |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 2056 | snd_hda_jack_report_sync(codec); |
| 2057 | |
Takashi Iwai | 9e5341b | 2010-09-21 09:57:06 +0200 | [diff] [blame] | 2058 | hda_call_check_power_status(codec, 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | return 0; |
| 2060 | } |
| 2061 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2062 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2063 | static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 2064 | { |
| 2065 | struct alc_spec *spec = codec->spec; |
| 2066 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); |
| 2067 | } |
| 2068 | #endif |
| 2069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | /* |
| 2071 | * Analog playback callbacks |
| 2072 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2073 | static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2075 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | { |
| 2077 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 2078 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 2079 | hinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | } |
| 2081 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2082 | static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | struct hda_codec *codec, |
| 2084 | unsigned int stream_tag, |
| 2085 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2086 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | { |
| 2088 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 2089 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, |
| 2090 | stream_tag, format, substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | } |
| 2092 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2093 | static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2095 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | { |
| 2097 | struct alc_spec *spec = codec->spec; |
| 2098 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
| 2099 | } |
| 2100 | |
| 2101 | /* |
| 2102 | * Digital out |
| 2103 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2104 | static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2106 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | { |
| 2108 | struct alc_spec *spec = codec->spec; |
| 2109 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 2110 | } |
| 2111 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2112 | static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 2113 | struct hda_codec *codec, |
| 2114 | unsigned int stream_tag, |
| 2115 | unsigned int format, |
| 2116 | struct snd_pcm_substream *substream) |
| 2117 | { |
| 2118 | struct alc_spec *spec = codec->spec; |
| 2119 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 2120 | stream_tag, format, substream); |
| 2121 | } |
| 2122 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2123 | static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 9b5f12e | 2009-02-13 11:47:37 +0100 | [diff] [blame] | 2124 | struct hda_codec *codec, |
| 2125 | struct snd_pcm_substream *substream) |
| 2126 | { |
| 2127 | struct alc_spec *spec = codec->spec; |
| 2128 | return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
| 2129 | } |
| 2130 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2131 | static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2133 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | { |
| 2135 | struct alc_spec *spec = codec->spec; |
| 2136 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 2137 | } |
| 2138 | |
| 2139 | /* |
| 2140 | * Analog capture |
| 2141 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2142 | static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | struct hda_codec *codec, |
| 2144 | unsigned int stream_tag, |
| 2145 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2146 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | { |
| 2148 | struct alc_spec *spec = codec->spec; |
| 2149 | |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2150 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | stream_tag, 0, format); |
| 2152 | return 0; |
| 2153 | } |
| 2154 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2155 | static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2157 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | { |
| 2159 | struct alc_spec *spec = codec->spec; |
| 2160 | |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 2161 | snd_hda_codec_cleanup_stream(codec, |
| 2162 | spec->adc_nids[substream->number + 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | return 0; |
| 2164 | } |
| 2165 | |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2166 | /* analog capture with dynamic dual-adc changes */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2167 | static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2168 | struct hda_codec *codec, |
| 2169 | unsigned int stream_tag, |
| 2170 | unsigned int format, |
| 2171 | struct snd_pcm_substream *substream) |
| 2172 | { |
| 2173 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2174 | spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]]; |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2175 | spec->cur_adc_stream_tag = stream_tag; |
| 2176 | spec->cur_adc_format = format; |
| 2177 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); |
| 2178 | return 0; |
| 2179 | } |
| 2180 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2181 | static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2182 | struct hda_codec *codec, |
| 2183 | struct snd_pcm_substream *substream) |
| 2184 | { |
| 2185 | struct alc_spec *spec = codec->spec; |
| 2186 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
| 2187 | spec->cur_adc = 0; |
| 2188 | return 0; |
| 2189 | } |
| 2190 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2191 | static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = { |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2192 | .substreams = 1, |
| 2193 | .channels_min = 2, |
| 2194 | .channels_max = 2, |
| 2195 | .nid = 0, /* fill later */ |
| 2196 | .ops = { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2197 | .prepare = dyn_adc_capture_pcm_prepare, |
| 2198 | .cleanup = dyn_adc_capture_pcm_cleanup |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2199 | }, |
| 2200 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | |
| 2202 | /* |
| 2203 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2204 | static const struct hda_pcm_stream alc_pcm_analog_playback = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | .substreams = 1, |
| 2206 | .channels_min = 2, |
| 2207 | .channels_max = 8, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2208 | /* NID is set in alc_build_pcms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2210 | .open = alc_playback_pcm_open, |
| 2211 | .prepare = alc_playback_pcm_prepare, |
| 2212 | .cleanup = alc_playback_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | }, |
| 2214 | }; |
| 2215 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2216 | static const struct hda_pcm_stream alc_pcm_analog_capture = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2217 | .substreams = 1, |
| 2218 | .channels_min = 2, |
| 2219 | .channels_max = 2, |
| 2220 | /* NID is set in alc_build_pcms */ |
| 2221 | }; |
| 2222 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2223 | static const struct hda_pcm_stream alc_pcm_analog_alt_playback = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2224 | .substreams = 1, |
| 2225 | .channels_min = 2, |
| 2226 | .channels_max = 2, |
| 2227 | /* NID is set in alc_build_pcms */ |
| 2228 | }; |
| 2229 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2230 | static const struct hda_pcm_stream alc_pcm_analog_alt_capture = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2231 | .substreams = 2, /* can be overridden */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | .channels_min = 2, |
| 2233 | .channels_max = 2, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2234 | /* NID is set in alc_build_pcms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2236 | .prepare = alc_alt_capture_pcm_prepare, |
| 2237 | .cleanup = alc_alt_capture_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | }, |
| 2239 | }; |
| 2240 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2241 | static const struct hda_pcm_stream alc_pcm_digital_playback = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | .substreams = 1, |
| 2243 | .channels_min = 2, |
| 2244 | .channels_max = 2, |
| 2245 | /* NID is set in alc_build_pcms */ |
| 2246 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2247 | .open = alc_dig_playback_pcm_open, |
| 2248 | .close = alc_dig_playback_pcm_close, |
| 2249 | .prepare = alc_dig_playback_pcm_prepare, |
| 2250 | .cleanup = alc_dig_playback_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | }, |
| 2252 | }; |
| 2253 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2254 | static const struct hda_pcm_stream alc_pcm_digital_capture = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | .substreams = 1, |
| 2256 | .channels_min = 2, |
| 2257 | .channels_max = 2, |
| 2258 | /* NID is set in alc_build_pcms */ |
| 2259 | }; |
| 2260 | |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 2261 | /* Used by alc_build_pcms to flag that a PCM has no playback stream */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 2262 | static const struct hda_pcm_stream alc_pcm_null_stream = { |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 2263 | .substreams = 0, |
| 2264 | .channels_min = 0, |
| 2265 | .channels_max = 0, |
| 2266 | }; |
| 2267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | static int alc_build_pcms(struct hda_codec *codec) |
| 2269 | { |
| 2270 | struct alc_spec *spec = codec->spec; |
| 2271 | struct hda_pcm *info = spec->pcm_rec; |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2272 | const struct hda_pcm_stream *p; |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2273 | bool have_multi_adcs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | int i; |
| 2275 | |
| 2276 | codec->num_pcms = 1; |
| 2277 | codec->pcm_info = info; |
| 2278 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2279 | if (spec->no_analog) |
| 2280 | goto skip_analog; |
| 2281 | |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 2282 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), |
| 2283 | "%s Analog", codec->chip_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | info->name = spec->stream_name_analog; |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 2285 | |
Takashi Iwai | eedec3d | 2012-02-06 10:24:04 +0100 | [diff] [blame] | 2286 | if (spec->multiout.num_dacs > 0) { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2287 | p = spec->stream_analog_playback; |
| 2288 | if (!p) |
| 2289 | p = &alc_pcm_analog_playback; |
| 2290 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2291 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; |
| 2292 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2293 | if (spec->adc_nids) { |
| 2294 | p = spec->stream_analog_capture; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2295 | if (!p) { |
| 2296 | if (spec->dyn_adc_switch) |
| 2297 | p = &dyn_adc_pcm_analog_capture; |
| 2298 | else |
| 2299 | p = &alc_pcm_analog_capture; |
| 2300 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2301 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2302 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 2303 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2305 | if (spec->channel_mode) { |
| 2306 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0; |
| 2307 | for (i = 0; i < spec->num_channel_mode; i++) { |
| 2308 | if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) { |
| 2309 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels; |
| 2310 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | } |
| 2312 | } |
| 2313 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2314 | skip_analog: |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2315 | /* SPDIF for stream index #1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 2317 | snprintf(spec->stream_name_digital, |
| 2318 | sizeof(spec->stream_name_digital), |
| 2319 | "%s Digital", codec->chip_name); |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2320 | codec->num_pcms = 2; |
Wu Fengguang | b25c9da | 2009-02-06 15:02:27 +0800 | [diff] [blame] | 2321 | codec->slave_dig_outs = spec->multiout.slave_dig_outs; |
Takashi Iwai | c06134d | 2006-10-11 18:49:13 +0200 | [diff] [blame] | 2322 | info = spec->pcm_rec + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | info->name = spec->stream_name_digital; |
Takashi Iwai | 8c44198 | 2009-01-20 18:30:20 +0100 | [diff] [blame] | 2324 | if (spec->dig_out_type) |
| 2325 | info->pcm_type = spec->dig_out_type; |
| 2326 | else |
| 2327 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2328 | if (spec->multiout.dig_out_nid) { |
| 2329 | p = spec->stream_digital_playback; |
| 2330 | if (!p) |
| 2331 | p = &alc_pcm_digital_playback; |
| 2332 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; |
| 2334 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2335 | if (spec->dig_in_nid) { |
| 2336 | p = spec->stream_digital_capture; |
| 2337 | if (!p) |
| 2338 | p = &alc_pcm_digital_capture; |
| 2339 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; |
| 2341 | } |
Takashi Iwai | 963f803 | 2008-08-11 10:04:40 +0200 | [diff] [blame] | 2342 | /* FIXME: do we need this for all Realtek codec models? */ |
| 2343 | codec->spdif_status_reset = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2346 | if (spec->no_analog) |
| 2347 | return 0; |
| 2348 | |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2349 | /* If the use of more than one ADC is requested for the current |
| 2350 | * model, configure a second analog capture-only PCM. |
| 2351 | */ |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2352 | have_multi_adcs = (spec->num_adc_nids > 1) && |
| 2353 | !spec->dyn_adc_switch && !spec->auto_mic && |
| 2354 | (!spec->input_mux || spec->input_mux->num_items > 1); |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2355 | /* Additional Analaog capture for index #2 */ |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2356 | if (spec->alt_dac_nid || have_multi_adcs) { |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2357 | codec->num_pcms = 3; |
Takashi Iwai | c06134d | 2006-10-11 18:49:13 +0200 | [diff] [blame] | 2358 | info = spec->pcm_rec + 2; |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2359 | info->name = spec->stream_name_analog; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2360 | if (spec->alt_dac_nid) { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2361 | p = spec->stream_analog_alt_playback; |
| 2362 | if (!p) |
| 2363 | p = &alc_pcm_analog_alt_playback; |
| 2364 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2365 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 2366 | spec->alt_dac_nid; |
| 2367 | } else { |
| 2368 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 2369 | alc_pcm_null_stream; |
| 2370 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0; |
| 2371 | } |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2372 | if (have_multi_adcs) { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2373 | p = spec->stream_analog_alt_capture; |
| 2374 | if (!p) |
| 2375 | p = &alc_pcm_analog_alt_capture; |
| 2376 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2377 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 2378 | spec->adc_nids[1]; |
| 2379 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = |
| 2380 | spec->num_adc_nids - 1; |
| 2381 | } else { |
| 2382 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 2383 | alc_pcm_null_stream; |
| 2384 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0; |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2385 | } |
| 2386 | } |
| 2387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | return 0; |
| 2389 | } |
| 2390 | |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2391 | static inline void alc_shutup(struct hda_codec *codec) |
| 2392 | { |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 2393 | struct alc_spec *spec = codec->spec; |
| 2394 | |
| 2395 | if (spec && spec->shutup) |
| 2396 | spec->shutup(codec); |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2397 | snd_hda_shutup_pins(codec); |
| 2398 | } |
| 2399 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2400 | static void alc_free_kctls(struct hda_codec *codec) |
| 2401 | { |
| 2402 | struct alc_spec *spec = codec->spec; |
| 2403 | |
| 2404 | if (spec->kctls.list) { |
| 2405 | struct snd_kcontrol_new *kctl = spec->kctls.list; |
| 2406 | int i; |
| 2407 | for (i = 0; i < spec->kctls.used; i++) |
| 2408 | kfree(kctl[i].name); |
| 2409 | } |
| 2410 | snd_array_free(&spec->kctls); |
| 2411 | } |
| 2412 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2413 | static void alc_free_bind_ctls(struct hda_codec *codec) |
| 2414 | { |
| 2415 | struct alc_spec *spec = codec->spec; |
| 2416 | if (spec->bind_ctls.list) { |
| 2417 | struct hda_bind_ctls **ctl = spec->bind_ctls.list; |
| 2418 | int i; |
| 2419 | for (i = 0; i < spec->bind_ctls.used; i++) |
| 2420 | kfree(ctl[i]); |
| 2421 | } |
| 2422 | snd_array_free(&spec->bind_ctls); |
| 2423 | } |
| 2424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | static void alc_free(struct hda_codec *codec) |
| 2426 | { |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2427 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2428 | |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2429 | if (!spec) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2430 | return; |
| 2431 | |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2432 | alc_shutup(codec); |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2433 | alc_free_kctls(codec); |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2434 | alc_free_bind_ctls(codec); |
Takashi Iwai | ee48df5 | 2012-06-26 14:54:32 +0200 | [diff] [blame] | 2435 | snd_hda_gen_free(&spec->gen); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2436 | kfree(spec); |
Kusanagi Kouichi | 680cd53 | 2009-02-05 00:00:58 +0900 | [diff] [blame] | 2437 | snd_hda_detach_beep_device(codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2440 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2441 | static void alc_power_eapd(struct hda_codec *codec) |
| 2442 | { |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 2443 | alc_auto_setup_eapd(codec, false); |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2444 | } |
| 2445 | |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2446 | static int alc_suspend(struct hda_codec *codec) |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2447 | { |
| 2448 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2449 | alc_shutup(codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2450 | if (spec && spec->power_hook) |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2451 | spec->power_hook(codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2452 | return 0; |
| 2453 | } |
| 2454 | #endif |
| 2455 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 2456 | #ifdef CONFIG_PM |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2457 | static int alc_resume(struct hda_codec *codec) |
| 2458 | { |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 2459 | msleep(150); /* to avoid pop noise */ |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2460 | codec->patch_ops.init(codec); |
| 2461 | snd_hda_codec_resume_amp(codec); |
| 2462 | snd_hda_codec_resume_cache(codec); |
Takashi Iwai | 125821a | 2012-06-22 14:30:29 +0200 | [diff] [blame] | 2463 | alc_inv_dmic_sync(codec, true); |
Takashi Iwai | 9e5341b | 2010-09-21 09:57:06 +0200 | [diff] [blame] | 2464 | hda_call_check_power_status(codec, 0x01); |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2465 | return 0; |
| 2466 | } |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2467 | #endif |
| 2468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | /* |
| 2470 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 2471 | static const struct hda_codec_ops alc_patch_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | .build_controls = alc_build_controls, |
| 2473 | .build_pcms = alc_build_pcms, |
| 2474 | .init = alc_init, |
| 2475 | .free = alc_free, |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2476 | .unsol_event = alc_unsol_event, |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 2477 | #ifdef CONFIG_PM |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2478 | .resume = alc_resume, |
| 2479 | #endif |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2480 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2481 | .suspend = alc_suspend, |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2482 | .check_power_status = alc_check_power_status, |
| 2483 | #endif |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2484 | .reboot_notify = alc_shutup, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | }; |
| 2486 | |
Kailang Yang | c027ddc | 2010-03-19 11:33:06 +0100 | [diff] [blame] | 2487 | /* replace the codec chip_name with the given string */ |
| 2488 | static int alc_codec_rename(struct hda_codec *codec, const char *name) |
| 2489 | { |
| 2490 | kfree(codec->chip_name); |
| 2491 | codec->chip_name = kstrdup(name, GFP_KERNEL); |
| 2492 | if (!codec->chip_name) { |
| 2493 | alc_free(codec); |
| 2494 | return -ENOMEM; |
| 2495 | } |
| 2496 | return 0; |
| 2497 | } |
| 2498 | |
Takashi Iwai | 2fa522b | 2005-05-12 14:51:12 +0200 | [diff] [blame] | 2499 | /* |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2500 | * Rename codecs appropriately from COEF value |
| 2501 | */ |
| 2502 | struct alc_codec_rename_table { |
| 2503 | unsigned int vendor_id; |
| 2504 | unsigned short coef_mask; |
| 2505 | unsigned short coef_bits; |
| 2506 | const char *name; |
| 2507 | }; |
| 2508 | |
| 2509 | static struct alc_codec_rename_table rename_tbl[] = { |
| 2510 | { 0x10ec0269, 0xfff0, 0x3010, "ALC277" }, |
| 2511 | { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" }, |
| 2512 | { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" }, |
| 2513 | { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" }, |
| 2514 | { 0x10ec0269, 0xffff, 0xa023, "ALC259" }, |
| 2515 | { 0x10ec0269, 0xffff, 0x6023, "ALC281X" }, |
| 2516 | { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" }, |
Kailang Yang | adcc70b | 2012-05-25 08:08:38 +0200 | [diff] [blame] | 2517 | { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2518 | { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" }, |
| 2519 | { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" }, |
| 2520 | { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" }, |
| 2521 | { 0x10ec0899, 0x2000, 0x2000, "ALC899" }, |
| 2522 | { 0x10ec0892, 0xffff, 0x8020, "ALC661" }, |
| 2523 | { 0x10ec0892, 0xffff, 0x8011, "ALC661" }, |
| 2524 | { 0x10ec0892, 0xffff, 0x4011, "ALC656" }, |
| 2525 | { } /* terminator */ |
| 2526 | }; |
| 2527 | |
| 2528 | static int alc_codec_rename_from_preset(struct hda_codec *codec) |
| 2529 | { |
| 2530 | const struct alc_codec_rename_table *p; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2531 | |
| 2532 | for (p = rename_tbl; p->vendor_id; p++) { |
| 2533 | if (p->vendor_id != codec->vendor_id) |
| 2534 | continue; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 2535 | if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits) |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2536 | return alc_codec_rename(codec, p->name); |
| 2537 | } |
| 2538 | return 0; |
| 2539 | } |
| 2540 | |
| 2541 | /* |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2542 | * Automatic parse of I/O pins from the BIOS configuration |
| 2543 | */ |
| 2544 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2545 | enum { |
| 2546 | ALC_CTL_WIDGET_VOL, |
| 2547 | ALC_CTL_WIDGET_MUTE, |
| 2548 | ALC_CTL_BIND_MUTE, |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2549 | ALC_CTL_BIND_VOL, |
| 2550 | ALC_CTL_BIND_SW, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2551 | }; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2552 | static const struct snd_kcontrol_new alc_control_templates[] = { |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2553 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
| 2554 | HDA_CODEC_MUTE(NULL, 0, 0, 0), |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2555 | HDA_BIND_MUTE(NULL, 0, 0, 0), |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2556 | HDA_BIND_VOL(NULL, 0), |
| 2557 | HDA_BIND_SW(NULL, 0), |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2558 | }; |
| 2559 | |
| 2560 | /* add dynamic controls */ |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2561 | static int add_control(struct alc_spec *spec, int type, const char *name, |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2562 | int cidx, unsigned long val) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2563 | { |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2564 | struct snd_kcontrol_new *knew; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2565 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2566 | knew = alc_kcontrol_new(spec); |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2567 | if (!knew) |
| 2568 | return -ENOMEM; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2569 | *knew = alc_control_templates[type]; |
Paulo Marques | 543537b | 2005-06-23 00:09:02 -0700 | [diff] [blame] | 2570 | knew->name = kstrdup(name, GFP_KERNEL); |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2571 | if (!knew->name) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2572 | return -ENOMEM; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2573 | knew->index = cidx; |
Jaroslav Kysela | 4d02d1b | 2009-11-12 10:15:48 +0100 | [diff] [blame] | 2574 | if (get_amp_nid_(val)) |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 2575 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2576 | knew->private_value = val; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2577 | return 0; |
| 2578 | } |
| 2579 | |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2580 | static int add_control_with_pfx(struct alc_spec *spec, int type, |
| 2581 | const char *pfx, const char *dir, |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2582 | const char *sfx, int cidx, unsigned long val) |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2583 | { |
| 2584 | char name[32]; |
| 2585 | snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx); |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2586 | return add_control(spec, type, name, cidx, val); |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2587 | } |
| 2588 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2589 | #define add_pb_vol_ctrl(spec, type, pfx, val) \ |
| 2590 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val) |
| 2591 | #define add_pb_sw_ctrl(spec, type, pfx, val) \ |
| 2592 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val) |
| 2593 | #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \ |
| 2594 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val) |
| 2595 | #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \ |
| 2596 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val) |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2597 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2598 | static const char * const channel_name[4] = { |
| 2599 | "Front", "Surround", "CLFE", "Side" |
| 2600 | }; |
| 2601 | |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2602 | static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch, |
| 2603 | bool can_be_master, int *index) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2604 | { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2605 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2606 | |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2607 | *index = 0; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2608 | if (cfg->line_outs == 1 && !spec->multi_ios && |
| 2609 | !cfg->hp_outs && !cfg->speaker_outs && can_be_master) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2610 | return "Master"; |
| 2611 | |
| 2612 | switch (cfg->line_out_type) { |
| 2613 | case AUTO_PIN_SPEAKER_OUT: |
David Henningsson | ebbeb3d | 2011-03-04 14:08:30 +0100 | [diff] [blame] | 2614 | if (cfg->line_outs == 1) |
| 2615 | return "Speaker"; |
Takashi Iwai | fbabc24 | 2011-12-07 17:14:20 +0100 | [diff] [blame] | 2616 | if (cfg->line_outs == 2) |
| 2617 | return ch ? "Bass Speaker" : "Speaker"; |
David Henningsson | ebbeb3d | 2011-03-04 14:08:30 +0100 | [diff] [blame] | 2618 | break; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2619 | case AUTO_PIN_HP_OUT: |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2620 | /* for multi-io case, only the primary out */ |
| 2621 | if (ch && spec->multi_ios) |
| 2622 | break; |
| 2623 | *index = ch; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2624 | return "Headphone"; |
| 2625 | default: |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2626 | if (cfg->line_outs == 1 && !spec->multi_ios) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2627 | return "PCM"; |
| 2628 | break; |
| 2629 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2630 | if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name))) |
| 2631 | return "PCM"; |
| 2632 | |
| 2633 | return channel_name[ch]; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2634 | } |
| 2635 | |
Takashi Iwai | 164f73e | 2012-02-21 11:27:09 +0100 | [diff] [blame] | 2636 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2637 | /* add the powersave loopback-list entry */ |
| 2638 | static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx) |
| 2639 | { |
| 2640 | struct hda_amp_list *list; |
| 2641 | |
| 2642 | if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1) |
| 2643 | return; |
| 2644 | list = spec->loopback_list + spec->num_loopbacks; |
| 2645 | list->nid = mix; |
| 2646 | list->dir = HDA_INPUT; |
| 2647 | list->idx = idx; |
| 2648 | spec->num_loopbacks++; |
| 2649 | spec->loopback.amplist = spec->loopback_list; |
| 2650 | } |
| 2651 | #else |
| 2652 | #define add_loopback_list(spec, mix, idx) /* NOP */ |
| 2653 | #endif |
| 2654 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2655 | /* create input playback/capture controls for the given pin */ |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2656 | static int new_analog_input(struct alc_spec *spec, hda_nid_t pin, |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2657 | const char *ctlname, int ctlidx, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 2658 | int idx, hda_nid_t mix_nid) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2659 | { |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 2660 | int err; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2661 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2662 | err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2663 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 2664 | if (err < 0) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2665 | return err; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2666 | err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2667 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 2668 | if (err < 0) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2669 | return err; |
Takashi Iwai | 164f73e | 2012-02-21 11:27:09 +0100 | [diff] [blame] | 2670 | add_loopback_list(spec, mix_nid, idx); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2671 | return 0; |
| 2672 | } |
| 2673 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2674 | static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2675 | { |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2676 | unsigned int pincap = snd_hda_query_pin_caps(codec, nid); |
| 2677 | return (pincap & AC_PINCAP_IN) != 0; |
| 2678 | } |
| 2679 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2680 | /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */ |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2681 | static int alc_auto_fill_adc_caps(struct hda_codec *codec) |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2682 | { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2683 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2684 | hda_nid_t nid; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2685 | hda_nid_t *adc_nids = spec->private_adc_nids; |
| 2686 | hda_nid_t *cap_nids = spec->private_capsrc_nids; |
| 2687 | int max_nums = ARRAY_SIZE(spec->private_adc_nids); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2688 | int i, nums = 0; |
| 2689 | |
| 2690 | nid = codec->start_nid; |
| 2691 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 2692 | hda_nid_t src; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2693 | unsigned int caps = get_wcaps(codec, nid); |
| 2694 | int type = get_wcaps_type(caps); |
| 2695 | |
| 2696 | if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL)) |
| 2697 | continue; |
| 2698 | adc_nids[nums] = nid; |
| 2699 | cap_nids[nums] = nid; |
| 2700 | src = nid; |
| 2701 | for (;;) { |
| 2702 | int n; |
| 2703 | type = get_wcaps_type(get_wcaps(codec, src)); |
| 2704 | if (type == AC_WID_PIN) |
| 2705 | break; |
| 2706 | if (type == AC_WID_AUD_SEL) { |
| 2707 | cap_nids[nums] = src; |
| 2708 | break; |
| 2709 | } |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 2710 | n = snd_hda_get_num_conns(codec, src); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2711 | if (n > 1) { |
| 2712 | cap_nids[nums] = src; |
| 2713 | break; |
| 2714 | } else if (n != 1) |
| 2715 | break; |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 2716 | if (snd_hda_get_connections(codec, src, &src, 1) != 1) |
| 2717 | break; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2718 | } |
| 2719 | if (++nums >= max_nums) |
| 2720 | break; |
| 2721 | } |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2722 | spec->adc_nids = spec->private_adc_nids; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2723 | spec->capsrc_nids = spec->private_capsrc_nids; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2724 | spec->num_adc_nids = nums; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2725 | return nums; |
| 2726 | } |
| 2727 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2728 | /* create playback/capture controls for input pins */ |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2729 | static int alc_auto_create_input_ctls(struct hda_codec *codec) |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2730 | { |
| 2731 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2732 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2733 | hda_nid_t mixer = spec->mixer_nid; |
Herton Ronaldo Krzesinski | 61b9b9b | 2009-01-28 09:16:33 -0200 | [diff] [blame] | 2734 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2735 | int num_adcs; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2736 | int i, c, err, idx, type_idx = 0; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2737 | const char *prev_label = NULL; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2738 | |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2739 | num_adcs = alc_auto_fill_adc_caps(codec); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2740 | if (num_adcs < 0) |
| 2741 | return 0; |
| 2742 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2743 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2744 | hda_nid_t pin; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2745 | const char *label; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2746 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2747 | pin = cfg->inputs[i].pin; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2748 | if (!alc_is_input_pin(codec, pin)) |
| 2749 | continue; |
| 2750 | |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2751 | label = hda_get_autocfg_input_label(codec, cfg, i); |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 2752 | if (spec->shared_mic_hp && !strcmp(label, "Misc")) |
| 2753 | label = "Headphone Mic"; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2754 | if (prev_label && !strcmp(label, prev_label)) |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2755 | type_idx++; |
| 2756 | else |
| 2757 | type_idx = 0; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2758 | prev_label = label; |
| 2759 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2760 | if (mixer) { |
| 2761 | idx = get_connection_index(codec, mixer, pin); |
| 2762 | if (idx >= 0) { |
| 2763 | err = new_analog_input(spec, pin, |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2764 | label, type_idx, |
| 2765 | idx, mixer); |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2766 | if (err < 0) |
| 2767 | return err; |
| 2768 | } |
| 2769 | } |
| 2770 | |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2771 | for (c = 0; c < num_adcs; c++) { |
Takashi Iwai | 6107159 | 2011-11-23 07:52:15 +0100 | [diff] [blame] | 2772 | hda_nid_t cap = get_capsrc(spec, c); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2773 | idx = get_connection_index(codec, cap, pin); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2774 | if (idx >= 0) { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2775 | spec->imux_pins[imux->num_items] = pin; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2776 | snd_hda_add_imux_item(imux, label, idx, NULL); |
| 2777 | break; |
| 2778 | } |
| 2779 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2780 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2781 | |
| 2782 | spec->num_mux_defs = 1; |
| 2783 | spec->input_mux = imux; |
| 2784 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2785 | return 0; |
| 2786 | } |
| 2787 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 2788 | /* create a shared input with the headphone out */ |
| 2789 | static int alc_auto_create_shared_input(struct hda_codec *codec) |
| 2790 | { |
| 2791 | struct alc_spec *spec = codec->spec; |
| 2792 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2793 | unsigned int defcfg; |
| 2794 | hda_nid_t nid; |
| 2795 | |
| 2796 | /* only one internal input pin? */ |
| 2797 | if (cfg->num_inputs != 1) |
| 2798 | return 0; |
| 2799 | defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin); |
| 2800 | if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT) |
| 2801 | return 0; |
| 2802 | |
| 2803 | if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) |
| 2804 | nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */ |
| 2805 | else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT) |
| 2806 | nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */ |
| 2807 | else |
| 2808 | return 0; /* both not available */ |
| 2809 | |
| 2810 | if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN)) |
| 2811 | return 0; /* no input */ |
| 2812 | |
| 2813 | cfg->inputs[1].pin = nid; |
| 2814 | cfg->inputs[1].type = AUTO_PIN_MIC; |
| 2815 | cfg->num_inputs = 2; |
| 2816 | spec->shared_mic_hp = 1; |
| 2817 | snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid); |
| 2818 | return 0; |
| 2819 | } |
| 2820 | |
Takashi Iwai | f6c7e54 | 2008-02-12 18:32:23 +0100 | [diff] [blame] | 2821 | static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid, |
| 2822 | unsigned int pin_type) |
| 2823 | { |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 2824 | snd_hda_set_pin_ctl(codec, nid, pin_type); |
Takashi Iwai | f6c7e54 | 2008-02-12 18:32:23 +0100 | [diff] [blame] | 2825 | /* unmute pin */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 2826 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
| 2827 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
Takashi Iwai | d260cdf | 2008-02-13 17:19:35 +0100 | [diff] [blame] | 2828 | AMP_OUT_UNMUTE); |
Takashi Iwai | f6c7e54 | 2008-02-12 18:32:23 +0100 | [diff] [blame] | 2829 | } |
| 2830 | |
Takashi Iwai | baba8ee | 2007-04-23 17:17:48 +0200 | [diff] [blame] | 2831 | static int get_pin_type(int line_out_type) |
| 2832 | { |
| 2833 | if (line_out_type == AUTO_PIN_HP_OUT) |
| 2834 | return PIN_HP; |
| 2835 | else |
| 2836 | return PIN_OUT; |
| 2837 | } |
| 2838 | |
Takashi Iwai | 0a7f532 | 2011-07-06 15:15:12 +0200 | [diff] [blame] | 2839 | static void alc_auto_init_analog_input(struct hda_codec *codec) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2840 | { |
| 2841 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2842 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2843 | int i; |
| 2844 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2845 | for (i = 0; i < cfg->num_inputs; i++) { |
| 2846 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2847 | if (alc_is_input_pin(codec, nid)) { |
Takashi Iwai | 30ea098 | 2010-09-16 18:47:56 +0200 | [diff] [blame] | 2848 | alc_set_input_pin(codec, nid, cfg->inputs[i].type); |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 2849 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2850 | snd_hda_codec_write(codec, nid, 0, |
| 2851 | AC_VERB_SET_AMP_GAIN_MUTE, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2852 | AMP_OUT_MUTE); |
| 2853 | } |
| 2854 | } |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 2855 | |
| 2856 | /* mute all loopback inputs */ |
| 2857 | if (spec->mixer_nid) { |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 2858 | int nums = snd_hda_get_num_conns(codec, spec->mixer_nid); |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 2859 | for (i = 0; i < nums; i++) |
| 2860 | snd_hda_codec_write(codec, spec->mixer_nid, 0, |
| 2861 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 2862 | AMP_IN_MUTE(i)); |
| 2863 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2864 | } |
| 2865 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2866 | /* convert from MIX nid to DAC */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2867 | static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2868 | { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2869 | hda_nid_t list[5]; |
Takashi Iwai | 1304ac8 | 2011-04-06 15:16:21 +0200 | [diff] [blame] | 2870 | int i, num; |
| 2871 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 2872 | if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT) |
| 2873 | return nid; |
Takashi Iwai | 1304ac8 | 2011-04-06 15:16:21 +0200 | [diff] [blame] | 2874 | num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list)); |
| 2875 | for (i = 0; i < num; i++) { |
| 2876 | if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT) |
| 2877 | return list[i]; |
| 2878 | } |
| 2879 | return 0; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2880 | } |
| 2881 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2882 | /* go down to the selector widget before the mixer */ |
| 2883 | static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin) |
| 2884 | { |
| 2885 | hda_nid_t srcs[5]; |
| 2886 | int num = snd_hda_get_connections(codec, pin, srcs, |
| 2887 | ARRAY_SIZE(srcs)); |
| 2888 | if (num != 1 || |
| 2889 | get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL) |
| 2890 | return pin; |
| 2891 | return srcs[0]; |
| 2892 | } |
| 2893 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2894 | /* get MIX nid connected to the given pin targeted to DAC */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2895 | static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2896 | hda_nid_t dac) |
| 2897 | { |
David Henningsson | cc1c452 | 2010-11-24 14:17:47 +0100 | [diff] [blame] | 2898 | hda_nid_t mix[5]; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2899 | int i, num; |
| 2900 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2901 | pin = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2902 | num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); |
| 2903 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2904 | if (alc_auto_mix_to_dac(codec, mix[i]) == dac) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2905 | return mix[i]; |
| 2906 | } |
| 2907 | return 0; |
| 2908 | } |
| 2909 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2910 | /* select the connection from pin to DAC if needed */ |
| 2911 | static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin, |
| 2912 | hda_nid_t dac) |
| 2913 | { |
| 2914 | hda_nid_t mix[5]; |
| 2915 | int i, num; |
| 2916 | |
| 2917 | pin = alc_go_down_to_selector(codec, pin); |
| 2918 | num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); |
| 2919 | if (num < 2) |
| 2920 | return 0; |
| 2921 | for (i = 0; i < num; i++) { |
| 2922 | if (alc_auto_mix_to_dac(codec, mix[i]) == dac) { |
| 2923 | snd_hda_codec_update_cache(codec, pin, 0, |
| 2924 | AC_VERB_SET_CONNECT_SEL, i); |
| 2925 | return 0; |
| 2926 | } |
| 2927 | } |
| 2928 | return 0; |
| 2929 | } |
| 2930 | |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 2931 | static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid) |
| 2932 | { |
| 2933 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 2934 | int i; |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 2935 | if (found_in_nid_list(nid, spec->multiout.dac_nids, |
| 2936 | ARRAY_SIZE(spec->private_dac_nids)) || |
| 2937 | found_in_nid_list(nid, spec->multiout.hp_out_nid, |
| 2938 | ARRAY_SIZE(spec->multiout.hp_out_nid)) || |
| 2939 | found_in_nid_list(nid, spec->multiout.extra_out_nid, |
| 2940 | ARRAY_SIZE(spec->multiout.extra_out_nid))) |
| 2941 | return true; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 2942 | for (i = 0; i < spec->multi_ios; i++) { |
| 2943 | if (spec->multi_io[i].dac == nid) |
| 2944 | return true; |
| 2945 | } |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 2946 | return false; |
| 2947 | } |
| 2948 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2949 | /* look for an empty DAC slot */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2950 | static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2951 | { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2952 | hda_nid_t srcs[5]; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2953 | int i, num; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2954 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2955 | pin = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2956 | num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs)); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2957 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2958 | hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2959 | if (!nid) |
| 2960 | continue; |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 2961 | if (!alc_is_dac_already_used(codec, nid)) |
| 2962 | return nid; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2963 | } |
| 2964 | return 0; |
| 2965 | } |
| 2966 | |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 2967 | /* check whether the DAC is reachable from the pin */ |
| 2968 | static bool alc_auto_is_dac_reachable(struct hda_codec *codec, |
| 2969 | hda_nid_t pin, hda_nid_t dac) |
| 2970 | { |
| 2971 | hda_nid_t srcs[5]; |
| 2972 | int i, num; |
| 2973 | |
Takashi Iwai | dc31b58 | 2012-02-17 17:27:53 +0100 | [diff] [blame] | 2974 | if (!pin || !dac) |
| 2975 | return false; |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 2976 | pin = alc_go_down_to_selector(codec, pin); |
| 2977 | num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs)); |
| 2978 | for (i = 0; i < num; i++) { |
| 2979 | hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]); |
| 2980 | if (nid == dac) |
| 2981 | return true; |
| 2982 | } |
| 2983 | return false; |
| 2984 | } |
| 2985 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2986 | static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin) |
| 2987 | { |
Takashi Iwai | 140547e | 2012-02-16 17:23:46 +0100 | [diff] [blame] | 2988 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2989 | hda_nid_t sel = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 2990 | hda_nid_t nid, nid_found, srcs[5]; |
| 2991 | int i, num = snd_hda_get_connections(codec, sel, srcs, |
Takashi Iwai | 140547e | 2012-02-16 17:23:46 +0100 | [diff] [blame] | 2992 | ARRAY_SIZE(srcs)); |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 2993 | if (num == 1) |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2994 | return alc_auto_look_for_dac(codec, pin); |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 2995 | nid_found = 0; |
| 2996 | for (i = 0; i < num; i++) { |
| 2997 | if (srcs[i] == spec->mixer_nid) |
| 2998 | continue; |
| 2999 | nid = alc_auto_mix_to_dac(codec, srcs[i]); |
| 3000 | if (nid && !alc_is_dac_already_used(codec, nid)) { |
| 3001 | if (nid_found) |
| 3002 | return 0; |
| 3003 | nid_found = nid; |
| 3004 | } |
| 3005 | } |
| 3006 | return nid_found; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3007 | } |
| 3008 | |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3009 | /* mark up volume and mute control NIDs: used during badness parsing and |
| 3010 | * at creating actual controls |
| 3011 | */ |
| 3012 | static inline unsigned int get_ctl_pos(unsigned int data) |
| 3013 | { |
| 3014 | hda_nid_t nid = get_amp_nid_(data); |
| 3015 | unsigned int dir; |
| 3016 | if (snd_BUG_ON(nid >= MAX_VOL_NIDS)) |
| 3017 | return 0; |
| 3018 | dir = get_amp_direction_(data); |
| 3019 | return (nid << 1) | dir; |
| 3020 | } |
| 3021 | |
| 3022 | #define is_ctl_used(bits, data) \ |
| 3023 | test_bit(get_ctl_pos(data), bits) |
| 3024 | #define mark_ctl_usage(bits, data) \ |
| 3025 | set_bit(get_ctl_pos(data), bits) |
| 3026 | |
| 3027 | static void clear_vol_marks(struct hda_codec *codec) |
| 3028 | { |
| 3029 | struct alc_spec *spec = codec->spec; |
| 3030 | memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls)); |
| 3031 | memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls)); |
| 3032 | } |
| 3033 | |
| 3034 | /* badness definition */ |
| 3035 | enum { |
| 3036 | /* No primary DAC is found for the main output */ |
| 3037 | BAD_NO_PRIMARY_DAC = 0x10000, |
| 3038 | /* No DAC is found for the extra output */ |
| 3039 | BAD_NO_DAC = 0x4000, |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3040 | /* No possible multi-ios */ |
| 3041 | BAD_MULTI_IO = 0x103, |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3042 | /* No individual DAC for extra output */ |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3043 | BAD_NO_EXTRA_DAC = 0x102, |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3044 | /* No individual DAC for extra surrounds */ |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3045 | BAD_NO_EXTRA_SURR_DAC = 0x101, |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3046 | /* Primary DAC shared with main surrounds */ |
| 3047 | BAD_SHARED_SURROUND = 0x100, |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3048 | /* Primary DAC shared with main CLFE */ |
| 3049 | BAD_SHARED_CLFE = 0x10, |
| 3050 | /* Primary DAC shared with extra surrounds */ |
| 3051 | BAD_SHARED_EXTRA_SURROUND = 0x10, |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3052 | /* Volume widget is shared */ |
| 3053 | BAD_SHARED_VOL = 0x10, |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3054 | }; |
| 3055 | |
| 3056 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, |
| 3057 | hda_nid_t pin, hda_nid_t dac); |
| 3058 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, |
| 3059 | hda_nid_t pin, hda_nid_t dac); |
| 3060 | |
| 3061 | static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin, |
| 3062 | hda_nid_t dac) |
| 3063 | { |
| 3064 | struct alc_spec *spec = codec->spec; |
| 3065 | hda_nid_t nid; |
| 3066 | unsigned int val; |
| 3067 | int badness = 0; |
| 3068 | |
| 3069 | nid = alc_look_for_out_vol_nid(codec, pin, dac); |
| 3070 | if (nid) { |
| 3071 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); |
| 3072 | if (is_ctl_used(spec->vol_ctls, nid)) |
| 3073 | badness += BAD_SHARED_VOL; |
| 3074 | else |
| 3075 | mark_ctl_usage(spec->vol_ctls, val); |
| 3076 | } else |
| 3077 | badness += BAD_SHARED_VOL; |
| 3078 | nid = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3079 | if (nid) { |
| 3080 | unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid)); |
| 3081 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) |
| 3082 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); |
| 3083 | else |
| 3084 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT); |
| 3085 | if (is_ctl_used(spec->sw_ctls, val)) |
| 3086 | badness += BAD_SHARED_VOL; |
| 3087 | else |
| 3088 | mark_ctl_usage(spec->sw_ctls, val); |
| 3089 | } else |
| 3090 | badness += BAD_SHARED_VOL; |
| 3091 | return badness; |
| 3092 | } |
| 3093 | |
Takashi Iwai | dc31b58 | 2012-02-17 17:27:53 +0100 | [diff] [blame] | 3094 | struct badness_table { |
| 3095 | int no_primary_dac; /* no primary DAC */ |
| 3096 | int no_dac; /* no secondary DACs */ |
| 3097 | int shared_primary; /* primary DAC is shared with main output */ |
| 3098 | int shared_surr; /* secondary DAC shared with main or primary */ |
| 3099 | int shared_clfe; /* third DAC shared with main or primary */ |
| 3100 | int shared_surr_main; /* secondary DAC sahred with main/DAC0 */ |
| 3101 | }; |
| 3102 | |
| 3103 | static struct badness_table main_out_badness = { |
| 3104 | .no_primary_dac = BAD_NO_PRIMARY_DAC, |
| 3105 | .no_dac = BAD_NO_DAC, |
| 3106 | .shared_primary = BAD_NO_PRIMARY_DAC, |
| 3107 | .shared_surr = BAD_SHARED_SURROUND, |
| 3108 | .shared_clfe = BAD_SHARED_CLFE, |
| 3109 | .shared_surr_main = BAD_SHARED_SURROUND, |
| 3110 | }; |
| 3111 | |
| 3112 | static struct badness_table extra_out_badness = { |
| 3113 | .no_primary_dac = BAD_NO_DAC, |
| 3114 | .no_dac = BAD_NO_DAC, |
| 3115 | .shared_primary = BAD_NO_EXTRA_DAC, |
| 3116 | .shared_surr = BAD_SHARED_EXTRA_SURROUND, |
| 3117 | .shared_clfe = BAD_SHARED_EXTRA_SURROUND, |
| 3118 | .shared_surr_main = BAD_NO_EXTRA_SURR_DAC, |
| 3119 | }; |
| 3120 | |
| 3121 | /* try to assign DACs to pins and return the resultant badness */ |
| 3122 | static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs, |
| 3123 | const hda_nid_t *pins, hda_nid_t *dacs, |
| 3124 | const struct badness_table *bad) |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3125 | { |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3126 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | dc31b58 | 2012-02-17 17:27:53 +0100 | [diff] [blame] | 3127 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3128 | int i, j; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3129 | int badness = 0; |
| 3130 | hda_nid_t dac; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3131 | |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 3132 | if (!num_outs) |
| 3133 | return 0; |
| 3134 | |
Takashi Iwai | dc31b58 | 2012-02-17 17:27:53 +0100 | [diff] [blame] | 3135 | for (i = 0; i < num_outs; i++) { |
| 3136 | hda_nid_t pin = pins[i]; |
| 3137 | if (!dacs[i]) |
| 3138 | dacs[i] = alc_auto_look_for_dac(codec, pin); |
| 3139 | if (!dacs[i] && !i) { |
| 3140 | for (j = 1; j < num_outs; j++) { |
| 3141 | if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) { |
| 3142 | dacs[0] = dacs[j]; |
| 3143 | dacs[j] = 0; |
| 3144 | break; |
| 3145 | } |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 3146 | } |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3147 | } |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3148 | dac = dacs[i]; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3149 | if (!dac) { |
Takashi Iwai | dc31b58 | 2012-02-17 17:27:53 +0100 | [diff] [blame] | 3150 | if (alc_auto_is_dac_reachable(codec, pin, dacs[0])) |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3151 | dac = dacs[0]; |
Takashi Iwai | dc31b58 | 2012-02-17 17:27:53 +0100 | [diff] [blame] | 3152 | else if (cfg->line_outs > i && |
| 3153 | alc_auto_is_dac_reachable(codec, pin, |
| 3154 | spec->private_dac_nids[i])) |
| 3155 | dac = spec->private_dac_nids[i]; |
| 3156 | if (dac) { |
| 3157 | if (!i) |
| 3158 | badness += bad->shared_primary; |
| 3159 | else if (i == 1) |
| 3160 | badness += bad->shared_surr; |
| 3161 | else |
| 3162 | badness += bad->shared_clfe; |
| 3163 | } else if (alc_auto_is_dac_reachable(codec, pin, |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3164 | spec->private_dac_nids[0])) { |
| 3165 | dac = spec->private_dac_nids[0]; |
Takashi Iwai | dc31b58 | 2012-02-17 17:27:53 +0100 | [diff] [blame] | 3166 | badness += bad->shared_surr_main; |
| 3167 | } else if (!i) |
| 3168 | badness += bad->no_primary_dac; |
| 3169 | else |
| 3170 | badness += bad->no_dac; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3171 | } |
| 3172 | if (dac) |
Takashi Iwai | dc31b58 | 2012-02-17 17:27:53 +0100 | [diff] [blame] | 3173 | badness += eval_shared_vol_badness(codec, pin, dac); |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3174 | } |
Takashi Iwai | dc31b58 | 2012-02-17 17:27:53 +0100 | [diff] [blame] | 3175 | |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3176 | return badness; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3177 | } |
| 3178 | |
| 3179 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3180 | hda_nid_t reference_pin, |
| 3181 | bool hardwired, int offset); |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3182 | |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 3183 | static bool alc_map_singles(struct hda_codec *codec, int outs, |
| 3184 | const hda_nid_t *pins, hda_nid_t *dacs) |
| 3185 | { |
| 3186 | int i; |
| 3187 | bool found = false; |
| 3188 | for (i = 0; i < outs; i++) { |
| 3189 | if (dacs[i]) |
| 3190 | continue; |
| 3191 | dacs[i] = get_dac_if_single(codec, pins[i]); |
| 3192 | if (dacs[i]) |
| 3193 | found = true; |
| 3194 | } |
| 3195 | return found; |
| 3196 | } |
| 3197 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3198 | /* fill in the dac_nids table from the parsed pin configuration */ |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3199 | static int fill_and_eval_dacs(struct hda_codec *codec, |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3200 | bool fill_hardwired, |
| 3201 | bool fill_mio_first) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3202 | { |
| 3203 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 0a34b42 | 2011-12-07 17:20:30 +0100 | [diff] [blame] | 3204 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | dc31b58 | 2012-02-17 17:27:53 +0100 | [diff] [blame] | 3205 | int i, err, badness; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3206 | |
Takashi Iwai | 8f398ae | 2011-07-23 18:57:11 +0200 | [diff] [blame] | 3207 | /* set num_dacs once to full for alc_auto_look_for_dac() */ |
| 3208 | spec->multiout.num_dacs = cfg->line_outs; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3209 | spec->multiout.dac_nids = spec->private_dac_nids; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3210 | memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids)); |
| 3211 | memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid)); |
| 3212 | memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid)); |
Takashi Iwai | 0a34b42 | 2011-12-07 17:20:30 +0100 | [diff] [blame] | 3213 | spec->multi_ios = 0; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3214 | clear_vol_marks(codec); |
| 3215 | badness = 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3216 | |
| 3217 | /* fill hard-wired DACs first */ |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3218 | if (fill_hardwired) { |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 3219 | bool mapped; |
| 3220 | do { |
| 3221 | mapped = alc_map_singles(codec, cfg->line_outs, |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3222 | cfg->line_out_pins, |
| 3223 | spec->private_dac_nids); |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 3224 | mapped |= alc_map_singles(codec, cfg->hp_outs, |
| 3225 | cfg->hp_pins, |
| 3226 | spec->multiout.hp_out_nid); |
| 3227 | mapped |= alc_map_singles(codec, cfg->speaker_outs, |
| 3228 | cfg->speaker_pins, |
| 3229 | spec->multiout.extra_out_nid); |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3230 | if (fill_mio_first && cfg->line_outs == 1 && |
| 3231 | cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
| 3232 | err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0); |
| 3233 | if (!err) |
| 3234 | mapped = true; |
| 3235 | } |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 3236 | } while (mapped); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3237 | } |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3238 | |
Takashi Iwai | dc31b58 | 2012-02-17 17:27:53 +0100 | [diff] [blame] | 3239 | badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins, |
| 3240 | spec->private_dac_nids, |
| 3241 | &main_out_badness); |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3242 | |
Takashi Iwai | 8f398ae | 2011-07-23 18:57:11 +0200 | [diff] [blame] | 3243 | /* re-count num_dacs and squash invalid entries */ |
| 3244 | spec->multiout.num_dacs = 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3245 | for (i = 0; i < cfg->line_outs; i++) { |
| 3246 | if (spec->private_dac_nids[i]) |
| 3247 | spec->multiout.num_dacs++; |
Takashi Iwai | 0a34b42 | 2011-12-07 17:20:30 +0100 | [diff] [blame] | 3248 | else { |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3249 | memmove(spec->private_dac_nids + i, |
| 3250 | spec->private_dac_nids + i + 1, |
| 3251 | sizeof(hda_nid_t) * (cfg->line_outs - i - 1)); |
Takashi Iwai | 0a34b42 | 2011-12-07 17:20:30 +0100 | [diff] [blame] | 3252 | spec->private_dac_nids[cfg->line_outs - 1] = 0; |
| 3253 | } |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3254 | } |
| 3255 | |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3256 | if (fill_mio_first && |
| 3257 | cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3258 | /* try to fill multi-io first */ |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3259 | err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3260 | if (err < 0) |
| 3261 | return err; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3262 | /* we don't count badness at this stage yet */ |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3263 | } |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3264 | |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3265 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) { |
Takashi Iwai | dc31b58 | 2012-02-17 17:27:53 +0100 | [diff] [blame] | 3266 | err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins, |
| 3267 | spec->multiout.hp_out_nid, |
| 3268 | &extra_out_badness); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3269 | if (err < 0) |
| 3270 | return err; |
| 3271 | badness += err; |
| 3272 | } |
Takashi Iwai | 0a34b42 | 2011-12-07 17:20:30 +0100 | [diff] [blame] | 3273 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
Takashi Iwai | dc31b58 | 2012-02-17 17:27:53 +0100 | [diff] [blame] | 3274 | err = alc_auto_fill_dacs(codec, cfg->speaker_outs, |
| 3275 | cfg->speaker_pins, |
| 3276 | spec->multiout.extra_out_nid, |
| 3277 | &extra_out_badness); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3278 | if (err < 0) |
| 3279 | return err; |
| 3280 | badness += err; |
| 3281 | } |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3282 | if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
| 3283 | err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3284 | if (err < 0) |
| 3285 | return err; |
| 3286 | badness += err; |
| 3287 | } |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3288 | if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { |
| 3289 | /* try multi-ios with HP + inputs */ |
Takashi Iwai | f568291 | 2012-02-21 12:37:00 +0100 | [diff] [blame] | 3290 | int offset = 0; |
| 3291 | if (cfg->line_outs >= 3) |
| 3292 | offset = 1; |
| 3293 | err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false, |
| 3294 | offset); |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3295 | if (err < 0) |
| 3296 | return err; |
| 3297 | badness += err; |
| 3298 | } |
| 3299 | |
| 3300 | if (spec->multi_ios == 2) { |
| 3301 | for (i = 0; i < 2; i++) |
| 3302 | spec->private_dac_nids[spec->multiout.num_dacs++] = |
| 3303 | spec->multi_io[i].dac; |
| 3304 | spec->ext_channel_count = 2; |
| 3305 | } else if (spec->multi_ios) { |
| 3306 | spec->multi_ios = 0; |
| 3307 | badness += BAD_MULTI_IO; |
| 3308 | } |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3309 | |
| 3310 | return badness; |
| 3311 | } |
| 3312 | |
| 3313 | #define DEBUG_BADNESS |
| 3314 | |
| 3315 | #ifdef DEBUG_BADNESS |
| 3316 | #define debug_badness snd_printdd |
| 3317 | #else |
| 3318 | #define debug_badness(...) |
| 3319 | #endif |
| 3320 | |
| 3321 | static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg) |
| 3322 | { |
| 3323 | debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n", |
| 3324 | cfg->line_out_pins[0], cfg->line_out_pins[1], |
| 3325 | cfg->line_out_pins[2], cfg->line_out_pins[2], |
| 3326 | spec->multiout.dac_nids[0], |
| 3327 | spec->multiout.dac_nids[1], |
| 3328 | spec->multiout.dac_nids[2], |
| 3329 | spec->multiout.dac_nids[3]); |
Takashi Iwai | 6f45304 | 2012-02-17 14:09:20 +0100 | [diff] [blame] | 3330 | if (spec->multi_ios > 0) |
| 3331 | debug_badness("multi_ios(%d) = %x/%x : %x/%x\n", |
| 3332 | spec->multi_ios, |
| 3333 | spec->multi_io[0].pin, spec->multi_io[1].pin, |
| 3334 | spec->multi_io[0].dac, spec->multi_io[1].dac); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3335 | debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n", |
| 3336 | cfg->hp_pins[0], cfg->hp_pins[1], |
| 3337 | cfg->hp_pins[2], cfg->hp_pins[2], |
| 3338 | spec->multiout.hp_out_nid[0], |
| 3339 | spec->multiout.hp_out_nid[1], |
| 3340 | spec->multiout.hp_out_nid[2], |
| 3341 | spec->multiout.hp_out_nid[3]); |
| 3342 | debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n", |
| 3343 | cfg->speaker_pins[0], cfg->speaker_pins[1], |
| 3344 | cfg->speaker_pins[2], cfg->speaker_pins[3], |
| 3345 | spec->multiout.extra_out_nid[0], |
| 3346 | spec->multiout.extra_out_nid[1], |
| 3347 | spec->multiout.extra_out_nid[2], |
| 3348 | spec->multiout.extra_out_nid[3]); |
| 3349 | } |
| 3350 | |
| 3351 | static int alc_auto_fill_dac_nids(struct hda_codec *codec) |
| 3352 | { |
| 3353 | struct alc_spec *spec = codec->spec; |
| 3354 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3355 | struct auto_pin_cfg *best_cfg; |
| 3356 | int best_badness = INT_MAX; |
| 3357 | int badness; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3358 | bool fill_hardwired = true, fill_mio_first = true; |
| 3359 | bool best_wired = true, best_mio = true; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3360 | bool hp_spk_swapped = false; |
| 3361 | |
| 3362 | best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL); |
| 3363 | if (!best_cfg) |
| 3364 | return -ENOMEM; |
| 3365 | *best_cfg = *cfg; |
| 3366 | |
| 3367 | for (;;) { |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3368 | badness = fill_and_eval_dacs(codec, fill_hardwired, |
| 3369 | fill_mio_first); |
Jesper Juhl | 7d7eb9e | 2012-04-12 22:11:25 +0200 | [diff] [blame] | 3370 | if (badness < 0) { |
| 3371 | kfree(best_cfg); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3372 | return badness; |
Jesper Juhl | 7d7eb9e | 2012-04-12 22:11:25 +0200 | [diff] [blame] | 3373 | } |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3374 | debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n", |
| 3375 | cfg->line_out_type, fill_hardwired, fill_mio_first, |
| 3376 | badness); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3377 | debug_show_configs(spec, cfg); |
| 3378 | if (badness < best_badness) { |
| 3379 | best_badness = badness; |
| 3380 | *best_cfg = *cfg; |
| 3381 | best_wired = fill_hardwired; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3382 | best_mio = fill_mio_first; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3383 | } |
| 3384 | if (!badness) |
| 3385 | break; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3386 | fill_mio_first = !fill_mio_first; |
| 3387 | if (!fill_mio_first) |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3388 | continue; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3389 | fill_hardwired = !fill_hardwired; |
| 3390 | if (!fill_hardwired) |
| 3391 | continue; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3392 | if (hp_spk_swapped) |
| 3393 | break; |
| 3394 | hp_spk_swapped = true; |
| 3395 | if (cfg->speaker_outs > 0 && |
Takashi Iwai | 0a34b42 | 2011-12-07 17:20:30 +0100 | [diff] [blame] | 3396 | cfg->line_out_type == AUTO_PIN_HP_OUT) { |
| 3397 | cfg->hp_outs = cfg->line_outs; |
| 3398 | memcpy(cfg->hp_pins, cfg->line_out_pins, |
| 3399 | sizeof(cfg->hp_pins)); |
| 3400 | cfg->line_outs = cfg->speaker_outs; |
| 3401 | memcpy(cfg->line_out_pins, cfg->speaker_pins, |
| 3402 | sizeof(cfg->speaker_pins)); |
| 3403 | cfg->speaker_outs = 0; |
| 3404 | memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins)); |
| 3405 | cfg->line_out_type = AUTO_PIN_SPEAKER_OUT; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3406 | fill_hardwired = true; |
| 3407 | continue; |
Jesper Juhl | 7d7eb9e | 2012-04-12 22:11:25 +0200 | [diff] [blame] | 3408 | } |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3409 | if (cfg->hp_outs > 0 && |
| 3410 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { |
| 3411 | cfg->speaker_outs = cfg->line_outs; |
| 3412 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 3413 | sizeof(cfg->speaker_pins)); |
| 3414 | cfg->line_outs = cfg->hp_outs; |
| 3415 | memcpy(cfg->line_out_pins, cfg->hp_pins, |
| 3416 | sizeof(cfg->hp_pins)); |
| 3417 | cfg->hp_outs = 0; |
| 3418 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); |
| 3419 | cfg->line_out_type = AUTO_PIN_HP_OUT; |
| 3420 | fill_hardwired = true; |
| 3421 | continue; |
Jesper Juhl | 7d7eb9e | 2012-04-12 22:11:25 +0200 | [diff] [blame] | 3422 | } |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3423 | break; |
Takashi Iwai | 0a34b42 | 2011-12-07 17:20:30 +0100 | [diff] [blame] | 3424 | } |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3425 | |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3426 | if (badness) { |
| 3427 | *cfg = *best_cfg; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3428 | fill_and_eval_dacs(codec, best_wired, best_mio); |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3429 | } |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3430 | debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n", |
| 3431 | cfg->line_out_type, best_wired, best_mio); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3432 | debug_show_configs(spec, cfg); |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3433 | |
David Henningsson | fde48a1 | 2011-12-09 18:27:42 +0800 | [diff] [blame] | 3434 | if (cfg->line_out_pins[0]) |
| 3435 | spec->vmaster_nid = |
| 3436 | alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0], |
| 3437 | spec->multiout.dac_nids[0]); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3438 | |
| 3439 | /* clear the bitmap flags for creating controls */ |
| 3440 | clear_vol_marks(codec); |
| 3441 | kfree(best_cfg); |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3442 | return 0; |
| 3443 | } |
| 3444 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3445 | static int alc_auto_add_vol_ctl(struct hda_codec *codec, |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3446 | const char *pfx, int cidx, |
| 3447 | hda_nid_t nid, unsigned int chs) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3448 | { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3449 | struct alc_spec *spec = codec->spec; |
| 3450 | unsigned int val; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3451 | if (!nid) |
| 3452 | return 0; |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3453 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); |
| 3454 | if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */ |
| 3455 | return 0; |
| 3456 | mark_ctl_usage(spec->vol_ctls, val); |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3457 | return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3458 | val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3459 | } |
| 3460 | |
Takashi Iwai | e29d377 | 2011-11-14 17:13:23 +0100 | [diff] [blame] | 3461 | static int alc_auto_add_stereo_vol(struct hda_codec *codec, |
| 3462 | const char *pfx, int cidx, |
| 3463 | hda_nid_t nid) |
| 3464 | { |
| 3465 | int chs = 1; |
| 3466 | if (get_wcaps(codec, nid) & AC_WCAP_STEREO) |
| 3467 | chs = 3; |
| 3468 | return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs); |
| 3469 | } |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3470 | |
| 3471 | /* create a mute-switch for the given mixer widget; |
| 3472 | * if it has multiple sources (e.g. DAC and loopback), create a bind-mute |
| 3473 | */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3474 | static int alc_auto_add_sw_ctl(struct hda_codec *codec, |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3475 | const char *pfx, int cidx, |
| 3476 | hda_nid_t nid, unsigned int chs) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3477 | { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3478 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3479 | int wid_type; |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3480 | int type; |
| 3481 | unsigned long val; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3482 | if (!nid) |
| 3483 | return 0; |
| 3484 | wid_type = get_wcaps_type(get_wcaps(codec, nid)); |
| 3485 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) { |
| 3486 | type = ALC_CTL_WIDGET_MUTE; |
| 3487 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 3488 | } else if (snd_hda_get_num_conns(codec, nid) == 1) { |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3489 | type = ALC_CTL_WIDGET_MUTE; |
| 3490 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT); |
| 3491 | } else { |
| 3492 | type = ALC_CTL_BIND_MUTE; |
| 3493 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT); |
| 3494 | } |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3495 | if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */ |
| 3496 | return 0; |
| 3497 | mark_ctl_usage(spec->sw_ctls, val); |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3498 | return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3499 | } |
| 3500 | |
Takashi Iwai | e29d377 | 2011-11-14 17:13:23 +0100 | [diff] [blame] | 3501 | static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx, |
| 3502 | int cidx, hda_nid_t nid) |
| 3503 | { |
| 3504 | int chs = 1; |
| 3505 | if (get_wcaps(codec, nid) & AC_WCAP_STEREO) |
| 3506 | chs = 3; |
| 3507 | return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs); |
| 3508 | } |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3509 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3510 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, |
| 3511 | hda_nid_t pin, hda_nid_t dac) |
| 3512 | { |
| 3513 | hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac); |
| 3514 | if (nid_has_mute(codec, pin, HDA_OUTPUT)) |
| 3515 | return pin; |
| 3516 | else if (mix && nid_has_mute(codec, mix, HDA_INPUT)) |
| 3517 | return mix; |
| 3518 | else if (nid_has_mute(codec, dac, HDA_OUTPUT)) |
| 3519 | return dac; |
| 3520 | return 0; |
| 3521 | } |
| 3522 | |
| 3523 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, |
| 3524 | hda_nid_t pin, hda_nid_t dac) |
| 3525 | { |
| 3526 | hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac); |
| 3527 | if (nid_has_volume(codec, dac, HDA_OUTPUT)) |
| 3528 | return dac; |
| 3529 | else if (nid_has_volume(codec, mix, HDA_OUTPUT)) |
| 3530 | return mix; |
| 3531 | else if (nid_has_volume(codec, pin, HDA_OUTPUT)) |
| 3532 | return pin; |
| 3533 | return 0; |
| 3534 | } |
| 3535 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3536 | /* add playback controls from the parsed DAC table */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3537 | static int alc_auto_create_multi_out_ctls(struct hda_codec *codec, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3538 | const struct auto_pin_cfg *cfg) |
| 3539 | { |
| 3540 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3541 | int i, err, noutputs; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3542 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3543 | noutputs = cfg->line_outs; |
Takashi Iwai | b90bf1d | 2012-01-19 11:42:55 +0100 | [diff] [blame] | 3544 | if (spec->multi_ios > 0 && cfg->line_outs < 3) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3545 | noutputs += spec->multi_ios; |
| 3546 | |
| 3547 | for (i = 0; i < noutputs; i++) { |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 3548 | const char *name; |
| 3549 | int index; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3550 | hda_nid_t dac, pin; |
| 3551 | hda_nid_t sw, vol; |
| 3552 | |
| 3553 | dac = spec->multiout.dac_nids[i]; |
| 3554 | if (!dac) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3555 | continue; |
Takashi Iwai | 689cabf | 2012-02-21 12:35:27 +0100 | [diff] [blame] | 3556 | if (i >= cfg->line_outs) { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3557 | pin = spec->multi_io[i - 1].pin; |
Takashi Iwai | 689cabf | 2012-02-21 12:35:27 +0100 | [diff] [blame] | 3558 | index = 0; |
| 3559 | name = channel_name[i]; |
| 3560 | } else { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3561 | pin = cfg->line_out_pins[i]; |
Takashi Iwai | 689cabf | 2012-02-21 12:35:27 +0100 | [diff] [blame] | 3562 | name = alc_get_line_out_pfx(spec, i, true, &index); |
| 3563 | } |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3564 | |
| 3565 | sw = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3566 | vol = alc_look_for_out_vol_nid(codec, pin, dac); |
Takashi Iwai | 9c4e84d | 2011-08-24 17:27:52 +0200 | [diff] [blame] | 3567 | if (!name || !strcmp(name, "CLFE")) { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3568 | /* Center/LFE */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3569 | err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3570 | if (err < 0) |
| 3571 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3572 | err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3573 | if (err < 0) |
| 3574 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3575 | err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3576 | if (err < 0) |
| 3577 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3578 | err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3579 | if (err < 0) |
| 3580 | return err; |
| 3581 | } else { |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3582 | err = alc_auto_add_stereo_vol(codec, name, index, vol); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3583 | if (err < 0) |
| 3584 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3585 | err = alc_auto_add_stereo_sw(codec, name, index, sw); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3586 | if (err < 0) |
| 3587 | return err; |
| 3588 | } |
| 3589 | } |
| 3590 | return 0; |
| 3591 | } |
| 3592 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3593 | static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin, |
Takashi Iwai | 766ddee | 2011-12-07 16:55:19 +0100 | [diff] [blame] | 3594 | hda_nid_t dac, const char *pfx, |
| 3595 | int cidx) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3596 | { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3597 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3598 | hda_nid_t sw, vol; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3599 | int err; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3600 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3601 | if (!dac) { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3602 | unsigned int val; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3603 | /* the corresponding DAC is already occupied */ |
| 3604 | if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)) |
| 3605 | return 0; /* no way */ |
| 3606 | /* create a switch only */ |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3607 | val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT); |
| 3608 | if (is_ctl_used(spec->sw_ctls, val)) |
| 3609 | return 0; /* already created */ |
| 3610 | mark_ctl_usage(spec->sw_ctls, val); |
Takashi Iwai | 766ddee | 2011-12-07 16:55:19 +0100 | [diff] [blame] | 3611 | return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3612 | } |
| 3613 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3614 | sw = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3615 | vol = alc_look_for_out_vol_nid(codec, pin, dac); |
Takashi Iwai | 766ddee | 2011-12-07 16:55:19 +0100 | [diff] [blame] | 3616 | err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3617 | if (err < 0) |
Takashi Iwai | 24fb917 | 2008-09-02 14:48:20 +0200 | [diff] [blame] | 3618 | return err; |
Takashi Iwai | 766ddee | 2011-12-07 16:55:19 +0100 | [diff] [blame] | 3619 | err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3620 | if (err < 0) |
| 3621 | return err; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3622 | return 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3623 | } |
| 3624 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3625 | static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec, |
| 3626 | unsigned int nums, |
| 3627 | struct hda_ctl_ops *ops) |
| 3628 | { |
| 3629 | struct alc_spec *spec = codec->spec; |
| 3630 | struct hda_bind_ctls **ctlp, *ctl; |
| 3631 | snd_array_init(&spec->bind_ctls, sizeof(ctl), 8); |
| 3632 | ctlp = snd_array_new(&spec->bind_ctls); |
| 3633 | if (!ctlp) |
| 3634 | return NULL; |
| 3635 | ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL); |
| 3636 | *ctlp = ctl; |
| 3637 | if (ctl) |
| 3638 | ctl->ops = ops; |
| 3639 | return ctl; |
| 3640 | } |
| 3641 | |
| 3642 | /* add playback controls for speaker and HP outputs */ |
| 3643 | static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins, |
| 3644 | const hda_nid_t *pins, |
| 3645 | const hda_nid_t *dacs, |
| 3646 | const char *pfx) |
| 3647 | { |
| 3648 | struct alc_spec *spec = codec->spec; |
| 3649 | struct hda_bind_ctls *ctl; |
| 3650 | char name[32]; |
| 3651 | int i, n, err; |
| 3652 | |
| 3653 | if (!num_pins || !pins[0]) |
| 3654 | return 0; |
| 3655 | |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3656 | if (num_pins == 1) { |
| 3657 | hda_nid_t dac = *dacs; |
| 3658 | if (!dac) |
| 3659 | dac = spec->multiout.dac_nids[0]; |
Takashi Iwai | 766ddee | 2011-12-07 16:55:19 +0100 | [diff] [blame] | 3660 | return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0); |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3661 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3662 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3663 | for (i = 0; i < num_pins; i++) { |
Takashi Iwai | c96f0bf | 2012-02-21 12:12:57 +0100 | [diff] [blame] | 3664 | hda_nid_t dac; |
| 3665 | if (dacs[num_pins - 1]) |
| 3666 | dac = dacs[i]; /* with individual volumes */ |
| 3667 | else |
| 3668 | dac = 0; |
| 3669 | if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) { |
| 3670 | err = alc_auto_create_extra_out(codec, pins[i], dac, |
| 3671 | "Bass Speaker", 0); |
| 3672 | } else if (num_pins >= 3) { |
| 3673 | snprintf(name, sizeof(name), "%s %s", |
| 3674 | pfx, channel_name[i]); |
| 3675 | err = alc_auto_create_extra_out(codec, pins[i], dac, |
| 3676 | name, 0); |
| 3677 | } else { |
| 3678 | err = alc_auto_create_extra_out(codec, pins[i], dac, |
| 3679 | pfx, i); |
| 3680 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3681 | if (err < 0) |
| 3682 | return err; |
| 3683 | } |
Takashi Iwai | c96f0bf | 2012-02-21 12:12:57 +0100 | [diff] [blame] | 3684 | if (dacs[num_pins - 1]) |
| 3685 | return 0; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3686 | |
Takashi Iwai | c96f0bf | 2012-02-21 12:12:57 +0100 | [diff] [blame] | 3687 | /* Let's create a bind-controls for volumes */ |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3688 | ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol); |
| 3689 | if (!ctl) |
| 3690 | return -ENOMEM; |
| 3691 | n = 0; |
| 3692 | for (i = 0; i < num_pins; i++) { |
| 3693 | hda_nid_t vol; |
| 3694 | if (!pins[i] || !dacs[i]) |
| 3695 | continue; |
| 3696 | vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]); |
| 3697 | if (vol) |
| 3698 | ctl->values[n++] = |
| 3699 | HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT); |
| 3700 | } |
| 3701 | if (n) { |
| 3702 | snprintf(name, sizeof(name), "%s Playback Volume", pfx); |
| 3703 | err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl); |
| 3704 | if (err < 0) |
| 3705 | return err; |
| 3706 | } |
| 3707 | return 0; |
| 3708 | } |
| 3709 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3710 | static int alc_auto_create_hp_out(struct hda_codec *codec) |
| 3711 | { |
| 3712 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3713 | return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs, |
| 3714 | spec->autocfg.hp_pins, |
| 3715 | spec->multiout.hp_out_nid, |
| 3716 | "Headphone"); |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3717 | } |
| 3718 | |
| 3719 | static int alc_auto_create_speaker_out(struct hda_codec *codec) |
| 3720 | { |
| 3721 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3722 | return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs, |
| 3723 | spec->autocfg.speaker_pins, |
| 3724 | spec->multiout.extra_out_nid, |
| 3725 | "Speaker"); |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3726 | } |
| 3727 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3728 | static void alc_auto_set_output_and_unmute(struct hda_codec *codec, |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3729 | hda_nid_t pin, int pin_type, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3730 | hda_nid_t dac) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3731 | { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3732 | int i, num; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3733 | hda_nid_t nid, mix = 0; |
Takashi Iwai | ce503f3 | 2010-07-30 10:37:29 +0200 | [diff] [blame] | 3734 | hda_nid_t srcs[HDA_MAX_CONNECTIONS]; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3735 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3736 | alc_set_pin_output(codec, pin, pin_type); |
| 3737 | nid = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3738 | num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs)); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3739 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 3740 | if (alc_auto_mix_to_dac(codec, srcs[i]) != dac) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3741 | continue; |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3742 | mix = srcs[i]; |
| 3743 | break; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3744 | } |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3745 | if (!mix) |
| 3746 | return; |
| 3747 | |
| 3748 | /* need the manual connection? */ |
| 3749 | if (num > 1) |
| 3750 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i); |
| 3751 | /* unmute mixer widget inputs */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3752 | if (nid_has_mute(codec, mix, HDA_INPUT)) { |
| 3753 | snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3754 | AMP_IN_UNMUTE(0)); |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3755 | snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3756 | AMP_IN_UNMUTE(1)); |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3757 | } |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3758 | /* initialize volume */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3759 | nid = alc_look_for_out_vol_nid(codec, pin, dac); |
| 3760 | if (nid) |
| 3761 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 3762 | AMP_OUT_ZERO); |
Takashi Iwai | 43dea22 | 2011-11-06 11:25:34 +0100 | [diff] [blame] | 3763 | |
| 3764 | /* unmute DAC if it's not assigned to a mixer */ |
| 3765 | nid = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3766 | if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT)) |
| 3767 | snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 3768 | AMP_OUT_ZERO); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3769 | } |
| 3770 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3771 | static void alc_auto_init_multi_out(struct hda_codec *codec) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3772 | { |
| 3773 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3774 | int pin_type = get_pin_type(spec->autocfg.line_out_type); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3775 | int i; |
| 3776 | |
| 3777 | for (i = 0; i <= HDA_SIDE; i++) { |
| 3778 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; |
| 3779 | if (nid) |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3780 | alc_auto_set_output_and_unmute(codec, nid, pin_type, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3781 | spec->multiout.dac_nids[i]); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3782 | } |
| 3783 | } |
| 3784 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3785 | static void alc_auto_init_extra_out(struct hda_codec *codec) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3786 | { |
| 3787 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3788 | int i; |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3789 | hda_nid_t pin, dac; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3790 | |
David Henningsson | 636030e | 2011-10-12 19:26:03 +0200 | [diff] [blame] | 3791 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3792 | if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT) |
| 3793 | break; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3794 | pin = spec->autocfg.hp_pins[i]; |
| 3795 | if (!pin) |
| 3796 | break; |
| 3797 | dac = spec->multiout.hp_out_nid[i]; |
| 3798 | if (!dac) { |
| 3799 | if (i > 0 && spec->multiout.hp_out_nid[0]) |
| 3800 | dac = spec->multiout.hp_out_nid[0]; |
| 3801 | else |
| 3802 | dac = spec->multiout.dac_nids[0]; |
| 3803 | } |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3804 | alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac); |
| 3805 | } |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3806 | for (i = 0; i < spec->autocfg.speaker_outs; i++) { |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3807 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) |
| 3808 | break; |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3809 | pin = spec->autocfg.speaker_pins[i]; |
| 3810 | if (!pin) |
| 3811 | break; |
| 3812 | dac = spec->multiout.extra_out_nid[i]; |
| 3813 | if (!dac) { |
| 3814 | if (i > 0 && spec->multiout.extra_out_nid[0]) |
| 3815 | dac = spec->multiout.extra_out_nid[0]; |
| 3816 | else |
| 3817 | dac = spec->multiout.dac_nids[0]; |
| 3818 | } |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3819 | alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac); |
| 3820 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3821 | } |
| 3822 | |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3823 | /* check whether the given pin can be a multi-io pin */ |
| 3824 | static bool can_be_multiio_pin(struct hda_codec *codec, |
| 3825 | unsigned int location, hda_nid_t nid) |
| 3826 | { |
| 3827 | unsigned int defcfg, caps; |
| 3828 | |
| 3829 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
| 3830 | if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX) |
| 3831 | return false; |
| 3832 | if (location && get_defcfg_location(defcfg) != location) |
| 3833 | return false; |
| 3834 | caps = snd_hda_query_pin_caps(codec, nid); |
| 3835 | if (!(caps & AC_PINCAP_OUT)) |
| 3836 | return false; |
| 3837 | return true; |
| 3838 | } |
| 3839 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3840 | /* |
| 3841 | * multi-io helper |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3842 | * |
| 3843 | * When hardwired is set, try to fill ony hardwired pins, and returns |
| 3844 | * zero if any pins are filled, non-zero if nothing found. |
| 3845 | * When hardwired is off, try to fill possible input pins, and returns |
| 3846 | * the badness value. |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3847 | */ |
| 3848 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3849 | hda_nid_t reference_pin, |
| 3850 | bool hardwired, int offset) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3851 | { |
| 3852 | struct alc_spec *spec = codec->spec; |
| 3853 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3854 | int type, i, j, dacs, num_pins, old_pins; |
| 3855 | unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin); |
| 3856 | unsigned int location = get_defcfg_location(defcfg); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3857 | int badness = 0; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3858 | |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3859 | old_pins = spec->multi_ios; |
| 3860 | if (old_pins >= 2) |
| 3861 | goto end_fill; |
| 3862 | |
| 3863 | num_pins = 0; |
| 3864 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { |
| 3865 | for (i = 0; i < cfg->num_inputs; i++) { |
| 3866 | if (cfg->inputs[i].type != type) |
| 3867 | continue; |
| 3868 | if (can_be_multiio_pin(codec, location, |
| 3869 | cfg->inputs[i].pin)) |
| 3870 | num_pins++; |
| 3871 | } |
| 3872 | } |
| 3873 | if (num_pins < 2) |
| 3874 | goto end_fill; |
| 3875 | |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3876 | dacs = spec->multiout.num_dacs; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3877 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { |
| 3878 | for (i = 0; i < cfg->num_inputs; i++) { |
| 3879 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3880 | hda_nid_t dac = 0; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3881 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3882 | if (cfg->inputs[i].type != type) |
| 3883 | continue; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3884 | if (!can_be_multiio_pin(codec, location, nid)) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3885 | continue; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3886 | for (j = 0; j < spec->multi_ios; j++) { |
| 3887 | if (nid == spec->multi_io[j].pin) |
| 3888 | break; |
| 3889 | } |
| 3890 | if (j < spec->multi_ios) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3891 | continue; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3892 | |
| 3893 | if (offset && offset + spec->multi_ios < dacs) { |
| 3894 | dac = spec->private_dac_nids[offset + spec->multi_ios]; |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3895 | if (!alc_auto_is_dac_reachable(codec, nid, dac)) |
| 3896 | dac = 0; |
| 3897 | } |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3898 | if (hardwired) |
| 3899 | dac = get_dac_if_single(codec, nid); |
| 3900 | else if (!dac) |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3901 | dac = alc_auto_look_for_dac(codec, nid); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3902 | if (!dac) { |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3903 | badness++; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3904 | continue; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3905 | } |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3906 | spec->multi_io[spec->multi_ios].pin = nid; |
| 3907 | spec->multi_io[spec->multi_ios].dac = dac; |
| 3908 | spec->multi_ios++; |
| 3909 | if (spec->multi_ios >= 2) |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3910 | break; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3911 | } |
| 3912 | } |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3913 | end_fill: |
| 3914 | if (badness) |
| 3915 | badness = BAD_MULTI_IO; |
| 3916 | if (old_pins == spec->multi_ios) { |
| 3917 | if (hardwired) |
| 3918 | return 1; /* nothing found */ |
| 3919 | else |
| 3920 | return badness; /* no badness if nothing found */ |
| 3921 | } |
| 3922 | if (!hardwired && spec->multi_ios < 2) { |
| 3923 | spec->multi_ios = old_pins; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3924 | return badness; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3925 | } |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3926 | |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3927 | return 0; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3928 | } |
| 3929 | |
| 3930 | static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol, |
| 3931 | struct snd_ctl_elem_info *uinfo) |
| 3932 | { |
| 3933 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3934 | struct alc_spec *spec = codec->spec; |
| 3935 | |
| 3936 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 3937 | uinfo->count = 1; |
| 3938 | uinfo->value.enumerated.items = spec->multi_ios + 1; |
| 3939 | if (uinfo->value.enumerated.item > spec->multi_ios) |
| 3940 | uinfo->value.enumerated.item = spec->multi_ios; |
| 3941 | sprintf(uinfo->value.enumerated.name, "%dch", |
| 3942 | (uinfo->value.enumerated.item + 1) * 2); |
| 3943 | return 0; |
| 3944 | } |
| 3945 | |
| 3946 | static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol, |
| 3947 | struct snd_ctl_elem_value *ucontrol) |
| 3948 | { |
| 3949 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3950 | struct alc_spec *spec = codec->spec; |
| 3951 | ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2; |
| 3952 | return 0; |
| 3953 | } |
| 3954 | |
| 3955 | static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output) |
| 3956 | { |
| 3957 | struct alc_spec *spec = codec->spec; |
| 3958 | hda_nid_t nid = spec->multi_io[idx].pin; |
| 3959 | |
| 3960 | if (!spec->multi_io[idx].ctl_in) |
| 3961 | spec->multi_io[idx].ctl_in = |
| 3962 | snd_hda_codec_read(codec, nid, 0, |
| 3963 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 3964 | if (output) { |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 3965 | snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT); |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3966 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
| 3967 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
| 3968 | HDA_AMP_MUTE, 0); |
| 3969 | alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac); |
| 3970 | } else { |
| 3971 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
| 3972 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
| 3973 | HDA_AMP_MUTE, HDA_AMP_MUTE); |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 3974 | snd_hda_set_pin_ctl_cache(codec, nid, |
| 3975 | spec->multi_io[idx].ctl_in); |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3976 | } |
| 3977 | return 0; |
| 3978 | } |
| 3979 | |
| 3980 | static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol, |
| 3981 | struct snd_ctl_elem_value *ucontrol) |
| 3982 | { |
| 3983 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3984 | struct alc_spec *spec = codec->spec; |
| 3985 | int i, ch; |
| 3986 | |
| 3987 | ch = ucontrol->value.enumerated.item[0]; |
| 3988 | if (ch < 0 || ch > spec->multi_ios) |
| 3989 | return -EINVAL; |
| 3990 | if (ch == (spec->ext_channel_count - 1) / 2) |
| 3991 | return 0; |
| 3992 | spec->ext_channel_count = (ch + 1) * 2; |
| 3993 | for (i = 0; i < spec->multi_ios; i++) |
| 3994 | alc_set_multi_io(codec, i, i < ch); |
| 3995 | spec->multiout.max_channels = spec->ext_channel_count; |
Takashi Iwai | 7b1655f | 2011-07-14 15:31:21 +0200 | [diff] [blame] | 3996 | if (spec->need_dac_fix && !spec->const_channel_count) |
| 3997 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3998 | return 1; |
| 3999 | } |
| 4000 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 4001 | static const struct snd_kcontrol_new alc_auto_channel_mode_enum = { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 4002 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 4003 | .name = "Channel Mode", |
| 4004 | .info = alc_auto_ch_mode_info, |
| 4005 | .get = alc_auto_ch_mode_get, |
| 4006 | .put = alc_auto_ch_mode_put, |
| 4007 | }; |
| 4008 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 4009 | static int alc_auto_add_multi_channel_mode(struct hda_codec *codec) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 4010 | { |
| 4011 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 4012 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 4013 | if (spec->multi_ios > 0) { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 4014 | struct snd_kcontrol_new *knew; |
| 4015 | |
| 4016 | knew = alc_kcontrol_new(spec); |
| 4017 | if (!knew) |
| 4018 | return -ENOMEM; |
| 4019 | *knew = alc_auto_channel_mode_enum; |
| 4020 | knew->name = kstrdup("Channel Mode", GFP_KERNEL); |
| 4021 | if (!knew->name) |
| 4022 | return -ENOMEM; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 4023 | } |
| 4024 | return 0; |
| 4025 | } |
| 4026 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4027 | /* filter out invalid adc_nids (and capsrc_nids) that don't give all |
| 4028 | * active input pins |
| 4029 | */ |
| 4030 | static void alc_remove_invalid_adc_nids(struct hda_codec *codec) |
| 4031 | { |
| 4032 | struct alc_spec *spec = codec->spec; |
| 4033 | const struct hda_input_mux *imux; |
| 4034 | hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)]; |
| 4035 | hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)]; |
| 4036 | int i, n, nums; |
| 4037 | |
| 4038 | imux = spec->input_mux; |
| 4039 | if (!imux) |
| 4040 | return; |
| 4041 | if (spec->dyn_adc_switch) |
| 4042 | return; |
| 4043 | |
Takashi Iwai | 26acaf0 | 2012-03-22 14:36:50 +0100 | [diff] [blame] | 4044 | again: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4045 | nums = 0; |
| 4046 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 4047 | hda_nid_t cap = spec->private_capsrc_nids[n]; |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 4048 | int num_conns = snd_hda_get_num_conns(codec, cap); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4049 | for (i = 0; i < imux->num_items; i++) { |
| 4050 | hda_nid_t pin = spec->imux_pins[i]; |
| 4051 | if (pin) { |
| 4052 | if (get_connection_index(codec, cap, pin) < 0) |
| 4053 | break; |
| 4054 | } else if (num_conns <= imux->items[i].index) |
| 4055 | break; |
| 4056 | } |
| 4057 | if (i >= imux->num_items) { |
| 4058 | adc_nids[nums] = spec->private_adc_nids[n]; |
| 4059 | capsrc_nids[nums++] = cap; |
| 4060 | } |
| 4061 | } |
| 4062 | if (!nums) { |
| 4063 | /* check whether ADC-switch is possible */ |
| 4064 | if (!alc_check_dyn_adc_switch(codec)) { |
Takashi Iwai | 26acaf0 | 2012-03-22 14:36:50 +0100 | [diff] [blame] | 4065 | if (spec->shared_mic_hp) { |
| 4066 | spec->shared_mic_hp = 0; |
| 4067 | spec->private_imux[0].num_items = 1; |
| 4068 | goto again; |
| 4069 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4070 | printk(KERN_WARNING "hda_codec: %s: no valid ADC found;" |
| 4071 | " using fallback 0x%x\n", |
| 4072 | codec->chip_name, spec->private_adc_nids[0]); |
| 4073 | spec->num_adc_nids = 1; |
| 4074 | spec->auto_mic = 0; |
| 4075 | return; |
| 4076 | } |
| 4077 | } else if (nums != spec->num_adc_nids) { |
| 4078 | memcpy(spec->private_adc_nids, adc_nids, |
| 4079 | nums * sizeof(hda_nid_t)); |
| 4080 | memcpy(spec->private_capsrc_nids, capsrc_nids, |
| 4081 | nums * sizeof(hda_nid_t)); |
| 4082 | spec->num_adc_nids = nums; |
| 4083 | } |
| 4084 | |
| 4085 | if (spec->auto_mic) |
| 4086 | alc_auto_mic_check_imux(codec); /* check auto-mic setups */ |
Takashi Iwai | 26acaf0 | 2012-03-22 14:36:50 +0100 | [diff] [blame] | 4087 | else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4088 | spec->num_adc_nids = 1; /* reduce to a single ADC */ |
| 4089 | } |
| 4090 | |
| 4091 | /* |
| 4092 | * initialize ADC paths |
| 4093 | */ |
| 4094 | static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx) |
| 4095 | { |
| 4096 | struct alc_spec *spec = codec->spec; |
| 4097 | hda_nid_t nid; |
| 4098 | |
| 4099 | nid = spec->adc_nids[adc_idx]; |
| 4100 | /* mute ADC */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 4101 | if (nid_has_mute(codec, nid, HDA_INPUT)) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4102 | snd_hda_codec_write(codec, nid, 0, |
| 4103 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 4104 | AMP_IN_MUTE(0)); |
| 4105 | return; |
| 4106 | } |
| 4107 | if (!spec->capsrc_nids) |
| 4108 | return; |
| 4109 | nid = spec->capsrc_nids[adc_idx]; |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 4110 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4111 | snd_hda_codec_write(codec, nid, 0, |
| 4112 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 4113 | AMP_OUT_MUTE); |
| 4114 | } |
| 4115 | |
| 4116 | static void alc_auto_init_input_src(struct hda_codec *codec) |
| 4117 | { |
| 4118 | struct alc_spec *spec = codec->spec; |
| 4119 | int c, nums; |
| 4120 | |
| 4121 | for (c = 0; c < spec->num_adc_nids; c++) |
| 4122 | alc_auto_init_adc(codec, c); |
| 4123 | if (spec->dyn_adc_switch) |
| 4124 | nums = 1; |
| 4125 | else |
| 4126 | nums = spec->num_adc_nids; |
| 4127 | for (c = 0; c < nums; c++) |
Takashi Iwai | 068b939 | 2012-02-25 11:13:16 +0100 | [diff] [blame] | 4128 | alc_mux_select(codec, c, spec->cur_mux[c], true); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | /* add mic boosts if needed */ |
| 4132 | static int alc_auto_add_mic_boost(struct hda_codec *codec) |
| 4133 | { |
| 4134 | struct alc_spec *spec = codec->spec; |
| 4135 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 4136 | int i, err; |
| 4137 | int type_idx = 0; |
| 4138 | hda_nid_t nid; |
| 4139 | const char *prev_label = NULL; |
| 4140 | |
| 4141 | for (i = 0; i < cfg->num_inputs; i++) { |
| 4142 | if (cfg->inputs[i].type > AUTO_PIN_MIC) |
| 4143 | break; |
| 4144 | nid = cfg->inputs[i].pin; |
| 4145 | if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { |
| 4146 | const char *label; |
| 4147 | char boost_label[32]; |
| 4148 | |
| 4149 | label = hda_get_autocfg_input_label(codec, cfg, i); |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 4150 | if (spec->shared_mic_hp && !strcmp(label, "Misc")) |
| 4151 | label = "Headphone Mic"; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4152 | if (prev_label && !strcmp(label, prev_label)) |
| 4153 | type_idx++; |
| 4154 | else |
| 4155 | type_idx = 0; |
| 4156 | prev_label = label; |
| 4157 | |
| 4158 | snprintf(boost_label, sizeof(boost_label), |
| 4159 | "%s Boost Volume", label); |
| 4160 | err = add_control(spec, ALC_CTL_WIDGET_VOL, |
| 4161 | boost_label, type_idx, |
| 4162 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT)); |
| 4163 | if (err < 0) |
| 4164 | return err; |
| 4165 | } |
| 4166 | } |
| 4167 | return 0; |
| 4168 | } |
| 4169 | |
| 4170 | /* select or unmute the given capsrc route */ |
| 4171 | static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap, |
| 4172 | int idx) |
| 4173 | { |
| 4174 | if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) { |
| 4175 | snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx, |
| 4176 | HDA_AMP_MUTE, 0); |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 4177 | } else if (snd_hda_get_num_conns(codec, cap) > 1) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4178 | snd_hda_codec_write_cache(codec, cap, 0, |
| 4179 | AC_VERB_SET_CONNECT_SEL, idx); |
| 4180 | } |
| 4181 | } |
| 4182 | |
| 4183 | /* set the default connection to that pin */ |
| 4184 | static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin) |
| 4185 | { |
| 4186 | struct alc_spec *spec = codec->spec; |
| 4187 | int i; |
| 4188 | |
| 4189 | if (!pin) |
| 4190 | return 0; |
| 4191 | for (i = 0; i < spec->num_adc_nids; i++) { |
Takashi Iwai | 6107159 | 2011-11-23 07:52:15 +0100 | [diff] [blame] | 4192 | hda_nid_t cap = get_capsrc(spec, i); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4193 | int idx; |
| 4194 | |
| 4195 | idx = get_connection_index(codec, cap, pin); |
| 4196 | if (idx < 0) |
| 4197 | continue; |
| 4198 | select_or_unmute_capsrc(codec, cap, idx); |
| 4199 | return i; /* return the found index */ |
| 4200 | } |
| 4201 | return -1; /* not found */ |
| 4202 | } |
| 4203 | |
| 4204 | /* initialize some special cases for input sources */ |
| 4205 | static void alc_init_special_input_src(struct hda_codec *codec) |
| 4206 | { |
| 4207 | struct alc_spec *spec = codec->spec; |
| 4208 | int i; |
| 4209 | |
| 4210 | for (i = 0; i < spec->autocfg.num_inputs; i++) |
| 4211 | init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin); |
| 4212 | } |
| 4213 | |
| 4214 | /* assign appropriate capture mixers */ |
| 4215 | static void set_capture_mixer(struct hda_codec *codec) |
| 4216 | { |
| 4217 | struct alc_spec *spec = codec->spec; |
| 4218 | static const struct snd_kcontrol_new *caps[2][3] = { |
| 4219 | { alc_capture_mixer_nosrc1, |
| 4220 | alc_capture_mixer_nosrc2, |
| 4221 | alc_capture_mixer_nosrc3 }, |
| 4222 | { alc_capture_mixer1, |
| 4223 | alc_capture_mixer2, |
| 4224 | alc_capture_mixer3 }, |
| 4225 | }; |
| 4226 | |
| 4227 | /* check whether either of ADC or MUX has a volume control */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 4228 | if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4229 | if (!spec->capsrc_nids) |
| 4230 | return; /* no volume */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 4231 | if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT)) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4232 | return; /* no volume in capsrc, too */ |
| 4233 | spec->vol_in_capsrc = 1; |
| 4234 | } |
| 4235 | |
| 4236 | if (spec->num_adc_nids > 0) { |
| 4237 | int mux = 0; |
| 4238 | int num_adcs = 0; |
| 4239 | |
| 4240 | if (spec->input_mux && spec->input_mux->num_items > 1) |
| 4241 | mux = 1; |
| 4242 | if (spec->auto_mic) { |
| 4243 | num_adcs = 1; |
| 4244 | mux = 0; |
| 4245 | } else if (spec->dyn_adc_switch) |
| 4246 | num_adcs = 1; |
| 4247 | if (!num_adcs) { |
| 4248 | if (spec->num_adc_nids > 3) |
| 4249 | spec->num_adc_nids = 3; |
| 4250 | else if (!spec->num_adc_nids) |
| 4251 | return; |
| 4252 | num_adcs = spec->num_adc_nids; |
| 4253 | } |
| 4254 | spec->cap_mixer = caps[mux][num_adcs - 1]; |
| 4255 | } |
| 4256 | } |
| 4257 | |
| 4258 | /* |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 4259 | * standard auto-parser initializations |
| 4260 | */ |
| 4261 | static void alc_auto_init_std(struct hda_codec *codec) |
| 4262 | { |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 4263 | alc_auto_init_multi_out(codec); |
| 4264 | alc_auto_init_extra_out(codec); |
| 4265 | alc_auto_init_analog_input(codec); |
| 4266 | alc_auto_init_input_src(codec); |
| 4267 | alc_auto_init_digital(codec); |
David Henningsson | a7a0a64 | 2012-07-05 12:00:12 +0200 | [diff] [blame] | 4268 | alc_inithook(codec); |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4272 | * Digital-beep handlers |
| 4273 | */ |
| 4274 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
| 4275 | #define set_beep_amp(spec, nid, idx, dir) \ |
| 4276 | ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir)) |
| 4277 | |
| 4278 | static const struct snd_pci_quirk beep_white_list[] = { |
| 4279 | SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1), |
| 4280 | SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1), |
| 4281 | SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1), |
| 4282 | SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1), |
Takashi Iwai | 78f8baf | 2012-03-06 14:02:32 +0100 | [diff] [blame] | 4283 | SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4284 | SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1), |
| 4285 | {} |
| 4286 | }; |
| 4287 | |
| 4288 | static inline int has_cdefine_beep(struct hda_codec *codec) |
| 4289 | { |
| 4290 | struct alc_spec *spec = codec->spec; |
| 4291 | const struct snd_pci_quirk *q; |
| 4292 | q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list); |
| 4293 | if (q) |
| 4294 | return q->value; |
| 4295 | return spec->cdefine.enable_pcbeep; |
| 4296 | } |
| 4297 | #else |
| 4298 | #define set_beep_amp(spec, nid, idx, dir) /* NOP */ |
| 4299 | #define has_cdefine_beep(codec) 0 |
| 4300 | #endif |
| 4301 | |
| 4302 | /* parse the BIOS configuration and set up the alc_spec */ |
| 4303 | /* return 1 if successful, 0 if the proper config is not found, |
| 4304 | * or a negative error code |
| 4305 | */ |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4306 | static int alc_parse_auto_config(struct hda_codec *codec, |
| 4307 | const hda_nid_t *ignore_nids, |
| 4308 | const hda_nid_t *ssid_nids) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4309 | { |
| 4310 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 4311 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4312 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4313 | |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 4314 | err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids, |
| 4315 | spec->parse_flags); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4316 | if (err < 0) |
| 4317 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 4318 | if (!cfg->line_outs) { |
| 4319 | if (cfg->dig_outs || cfg->dig_in_pin) { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4320 | spec->multiout.max_channels = 2; |
| 4321 | spec->no_analog = 1; |
| 4322 | goto dig_only; |
| 4323 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4324 | return 0; /* can't find valid BIOS pin config */ |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4325 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 4326 | |
Takashi Iwai | e427c23 | 2012-07-29 10:04:08 +0200 | [diff] [blame] | 4327 | if (!spec->no_primary_hp && |
| 4328 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && |
Takashi Iwai | 0650367 | 2011-10-06 08:27:19 +0200 | [diff] [blame] | 4329 | cfg->line_outs <= cfg->hp_outs) { |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 4330 | /* use HP as primary out */ |
| 4331 | cfg->speaker_outs = cfg->line_outs; |
| 4332 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 4333 | sizeof(cfg->speaker_pins)); |
| 4334 | cfg->line_outs = cfg->hp_outs; |
| 4335 | memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins)); |
| 4336 | cfg->hp_outs = 0; |
| 4337 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); |
| 4338 | cfg->line_out_type = AUTO_PIN_HP_OUT; |
| 4339 | } |
| 4340 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4341 | err = alc_auto_fill_dac_nids(codec); |
| 4342 | if (err < 0) |
| 4343 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 4344 | err = alc_auto_add_multi_channel_mode(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4345 | if (err < 0) |
| 4346 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 4347 | err = alc_auto_create_multi_out_ctls(codec, cfg); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4348 | if (err < 0) |
| 4349 | return err; |
| 4350 | err = alc_auto_create_hp_out(codec); |
| 4351 | if (err < 0) |
| 4352 | return err; |
| 4353 | err = alc_auto_create_speaker_out(codec); |
| 4354 | if (err < 0) |
| 4355 | return err; |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 4356 | err = alc_auto_create_shared_input(codec); |
| 4357 | if (err < 0) |
| 4358 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4359 | err = alc_auto_create_input_ctls(codec); |
| 4360 | if (err < 0) |
| 4361 | return err; |
| 4362 | |
| 4363 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 4364 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4365 | dig_only: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4366 | alc_auto_parse_digital(codec); |
| 4367 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4368 | if (!spec->no_analog) |
| 4369 | alc_remove_invalid_adc_nids(codec); |
| 4370 | |
| 4371 | if (ssid_nids) |
| 4372 | alc_ssid_check(codec, ssid_nids); |
| 4373 | |
| 4374 | if (!spec->no_analog) { |
| 4375 | alc_auto_check_switches(codec); |
| 4376 | err = alc_auto_add_mic_boost(codec); |
| 4377 | if (err < 0) |
| 4378 | return err; |
| 4379 | } |
| 4380 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4381 | if (spec->kctls.list) |
| 4382 | add_mixer(spec, spec->kctls.list); |
| 4383 | |
Takashi Iwai | 070cff4 | 2012-02-21 12:54:17 +0100 | [diff] [blame] | 4384 | if (!spec->no_analog && !spec->cap_mixer) |
| 4385 | set_capture_mixer(codec); |
| 4386 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4387 | return 1; |
| 4388 | } |
| 4389 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 4390 | /* common preparation job for alc_spec */ |
| 4391 | static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid) |
| 4392 | { |
| 4393 | struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4394 | int err; |
| 4395 | |
| 4396 | if (!spec) |
| 4397 | return -ENOMEM; |
| 4398 | codec->spec = spec; |
| 4399 | spec->mixer_nid = mixer_nid; |
Takashi Iwai | ee48df5 | 2012-06-26 14:54:32 +0200 | [diff] [blame] | 4400 | snd_hda_gen_init(&spec->gen); |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 4401 | |
| 4402 | err = alc_codec_rename_from_preset(codec); |
| 4403 | if (err < 0) { |
| 4404 | kfree(spec); |
| 4405 | return err; |
| 4406 | } |
| 4407 | return 0; |
| 4408 | } |
| 4409 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4410 | static int alc880_parse_auto_config(struct hda_codec *codec) |
| 4411 | { |
| 4412 | static const hda_nid_t alc880_ignore[] = { 0x1d, 0 }; |
Jesper Juhl | 7d7eb9e | 2012-04-12 22:11:25 +0200 | [diff] [blame] | 4413 | static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4414 | return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids); |
| 4415 | } |
| 4416 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4417 | /* |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4418 | * ALC880 fix-ups |
| 4419 | */ |
| 4420 | enum { |
Takashi Iwai | 411225a | 2012-02-20 17:48:19 +0100 | [diff] [blame] | 4421 | ALC880_FIXUP_GPIO1, |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4422 | ALC880_FIXUP_GPIO2, |
| 4423 | ALC880_FIXUP_MEDION_RIM, |
Takashi Iwai | dc6af52 | 2012-02-17 16:18:59 +0100 | [diff] [blame] | 4424 | ALC880_FIXUP_LG, |
Takashi Iwai | f02aab5 | 2012-02-17 16:33:56 +0100 | [diff] [blame] | 4425 | ALC880_FIXUP_W810, |
Takashi Iwai | 27e917f | 2012-02-17 17:49:54 +0100 | [diff] [blame] | 4426 | ALC880_FIXUP_EAPD_COEF, |
Takashi Iwai | b9368f5 | 2012-02-17 17:54:44 +0100 | [diff] [blame] | 4427 | ALC880_FIXUP_TCL_S700, |
Takashi Iwai | cf5a227 | 2012-02-20 16:31:07 +0100 | [diff] [blame] | 4428 | ALC880_FIXUP_VOL_KNOB, |
| 4429 | ALC880_FIXUP_FUJITSU, |
Takashi Iwai | ba53381 | 2012-02-20 16:36:52 +0100 | [diff] [blame] | 4430 | ALC880_FIXUP_F1734, |
Takashi Iwai | 817de92 | 2012-02-20 17:20:48 +0100 | [diff] [blame] | 4431 | ALC880_FIXUP_UNIWILL, |
Takashi Iwai | 967b88c | 2012-02-20 17:31:02 +0100 | [diff] [blame] | 4432 | ALC880_FIXUP_UNIWILL_DIG, |
Takashi Iwai | 96e225f | 2012-02-20 17:41:51 +0100 | [diff] [blame] | 4433 | ALC880_FIXUP_Z71V, |
Takashi Iwai | 67b6ec3 | 2012-02-20 18:20:42 +0100 | [diff] [blame] | 4434 | ALC880_FIXUP_3ST_BASE, |
| 4435 | ALC880_FIXUP_3ST, |
| 4436 | ALC880_FIXUP_3ST_DIG, |
| 4437 | ALC880_FIXUP_5ST_BASE, |
| 4438 | ALC880_FIXUP_5ST, |
| 4439 | ALC880_FIXUP_5ST_DIG, |
| 4440 | ALC880_FIXUP_6ST_BASE, |
| 4441 | ALC880_FIXUP_6ST, |
| 4442 | ALC880_FIXUP_6ST_DIG, |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4443 | }; |
| 4444 | |
Takashi Iwai | cf5a227 | 2012-02-20 16:31:07 +0100 | [diff] [blame] | 4445 | /* enable the volume-knob widget support on NID 0x21 */ |
| 4446 | static void alc880_fixup_vol_knob(struct hda_codec *codec, |
| 4447 | const struct alc_fixup *fix, int action) |
| 4448 | { |
| 4449 | if (action == ALC_FIXUP_ACT_PROBE) |
| 4450 | snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT); |
| 4451 | } |
| 4452 | |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4453 | static const struct alc_fixup alc880_fixups[] = { |
Takashi Iwai | 411225a | 2012-02-20 17:48:19 +0100 | [diff] [blame] | 4454 | [ALC880_FIXUP_GPIO1] = { |
| 4455 | .type = ALC_FIXUP_VERBS, |
| 4456 | .v.verbs = alc_gpio1_init_verbs, |
| 4457 | }, |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4458 | [ALC880_FIXUP_GPIO2] = { |
| 4459 | .type = ALC_FIXUP_VERBS, |
| 4460 | .v.verbs = alc_gpio2_init_verbs, |
| 4461 | }, |
| 4462 | [ALC880_FIXUP_MEDION_RIM] = { |
| 4463 | .type = ALC_FIXUP_VERBS, |
| 4464 | .v.verbs = (const struct hda_verb[]) { |
| 4465 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4466 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 }, |
| 4467 | { } |
| 4468 | }, |
| 4469 | .chained = true, |
| 4470 | .chain_id = ALC880_FIXUP_GPIO2, |
| 4471 | }, |
Takashi Iwai | dc6af52 | 2012-02-17 16:18:59 +0100 | [diff] [blame] | 4472 | [ALC880_FIXUP_LG] = { |
| 4473 | .type = ALC_FIXUP_PINS, |
| 4474 | .v.pins = (const struct alc_pincfg[]) { |
| 4475 | /* disable bogus unused pins */ |
| 4476 | { 0x16, 0x411111f0 }, |
| 4477 | { 0x18, 0x411111f0 }, |
| 4478 | { 0x1a, 0x411111f0 }, |
| 4479 | { } |
| 4480 | } |
| 4481 | }, |
Takashi Iwai | f02aab5 | 2012-02-17 16:33:56 +0100 | [diff] [blame] | 4482 | [ALC880_FIXUP_W810] = { |
| 4483 | .type = ALC_FIXUP_PINS, |
| 4484 | .v.pins = (const struct alc_pincfg[]) { |
| 4485 | /* disable bogus unused pins */ |
| 4486 | { 0x17, 0x411111f0 }, |
| 4487 | { } |
| 4488 | }, |
| 4489 | .chained = true, |
| 4490 | .chain_id = ALC880_FIXUP_GPIO2, |
| 4491 | }, |
Takashi Iwai | 27e917f | 2012-02-17 17:49:54 +0100 | [diff] [blame] | 4492 | [ALC880_FIXUP_EAPD_COEF] = { |
| 4493 | .type = ALC_FIXUP_VERBS, |
| 4494 | .v.verbs = (const struct hda_verb[]) { |
| 4495 | /* change to EAPD mode */ |
| 4496 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4497 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 }, |
| 4498 | {} |
| 4499 | }, |
| 4500 | }, |
Takashi Iwai | b9368f5 | 2012-02-17 17:54:44 +0100 | [diff] [blame] | 4501 | [ALC880_FIXUP_TCL_S700] = { |
| 4502 | .type = ALC_FIXUP_VERBS, |
| 4503 | .v.verbs = (const struct hda_verb[]) { |
| 4504 | /* change to EAPD mode */ |
| 4505 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4506 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, |
| 4507 | {} |
| 4508 | }, |
| 4509 | .chained = true, |
| 4510 | .chain_id = ALC880_FIXUP_GPIO2, |
| 4511 | }, |
Takashi Iwai | cf5a227 | 2012-02-20 16:31:07 +0100 | [diff] [blame] | 4512 | [ALC880_FIXUP_VOL_KNOB] = { |
| 4513 | .type = ALC_FIXUP_FUNC, |
| 4514 | .v.func = alc880_fixup_vol_knob, |
| 4515 | }, |
| 4516 | [ALC880_FIXUP_FUJITSU] = { |
| 4517 | /* override all pins as BIOS on old Amilo is broken */ |
| 4518 | .type = ALC_FIXUP_PINS, |
| 4519 | .v.pins = (const struct alc_pincfg[]) { |
| 4520 | { 0x14, 0x0121411f }, /* HP */ |
| 4521 | { 0x15, 0x99030120 }, /* speaker */ |
| 4522 | { 0x16, 0x99030130 }, /* bass speaker */ |
| 4523 | { 0x17, 0x411111f0 }, /* N/A */ |
| 4524 | { 0x18, 0x411111f0 }, /* N/A */ |
| 4525 | { 0x19, 0x01a19950 }, /* mic-in */ |
| 4526 | { 0x1a, 0x411111f0 }, /* N/A */ |
| 4527 | { 0x1b, 0x411111f0 }, /* N/A */ |
| 4528 | { 0x1c, 0x411111f0 }, /* N/A */ |
| 4529 | { 0x1d, 0x411111f0 }, /* N/A */ |
| 4530 | { 0x1e, 0x01454140 }, /* SPDIF out */ |
| 4531 | { } |
| 4532 | }, |
| 4533 | .chained = true, |
| 4534 | .chain_id = ALC880_FIXUP_VOL_KNOB, |
| 4535 | }, |
Takashi Iwai | ba53381 | 2012-02-20 16:36:52 +0100 | [diff] [blame] | 4536 | [ALC880_FIXUP_F1734] = { |
| 4537 | /* almost compatible with FUJITSU, but no bass and SPDIF */ |
| 4538 | .type = ALC_FIXUP_PINS, |
| 4539 | .v.pins = (const struct alc_pincfg[]) { |
| 4540 | { 0x14, 0x0121411f }, /* HP */ |
| 4541 | { 0x15, 0x99030120 }, /* speaker */ |
| 4542 | { 0x16, 0x411111f0 }, /* N/A */ |
| 4543 | { 0x17, 0x411111f0 }, /* N/A */ |
| 4544 | { 0x18, 0x411111f0 }, /* N/A */ |
| 4545 | { 0x19, 0x01a19950 }, /* mic-in */ |
| 4546 | { 0x1a, 0x411111f0 }, /* N/A */ |
| 4547 | { 0x1b, 0x411111f0 }, /* N/A */ |
| 4548 | { 0x1c, 0x411111f0 }, /* N/A */ |
| 4549 | { 0x1d, 0x411111f0 }, /* N/A */ |
| 4550 | { 0x1e, 0x411111f0 }, /* N/A */ |
| 4551 | { } |
| 4552 | }, |
| 4553 | .chained = true, |
| 4554 | .chain_id = ALC880_FIXUP_VOL_KNOB, |
| 4555 | }, |
Takashi Iwai | 817de92 | 2012-02-20 17:20:48 +0100 | [diff] [blame] | 4556 | [ALC880_FIXUP_UNIWILL] = { |
| 4557 | /* need to fix HP and speaker pins to be parsed correctly */ |
| 4558 | .type = ALC_FIXUP_PINS, |
| 4559 | .v.pins = (const struct alc_pincfg[]) { |
| 4560 | { 0x14, 0x0121411f }, /* HP */ |
| 4561 | { 0x15, 0x99030120 }, /* speaker */ |
| 4562 | { 0x16, 0x99030130 }, /* bass speaker */ |
| 4563 | { } |
| 4564 | }, |
| 4565 | }, |
Takashi Iwai | 967b88c | 2012-02-20 17:31:02 +0100 | [diff] [blame] | 4566 | [ALC880_FIXUP_UNIWILL_DIG] = { |
| 4567 | .type = ALC_FIXUP_PINS, |
| 4568 | .v.pins = (const struct alc_pincfg[]) { |
| 4569 | /* disable bogus unused pins */ |
| 4570 | { 0x17, 0x411111f0 }, |
| 4571 | { 0x19, 0x411111f0 }, |
| 4572 | { 0x1b, 0x411111f0 }, |
| 4573 | { 0x1f, 0x411111f0 }, |
| 4574 | { } |
| 4575 | } |
| 4576 | }, |
Takashi Iwai | 96e225f | 2012-02-20 17:41:51 +0100 | [diff] [blame] | 4577 | [ALC880_FIXUP_Z71V] = { |
| 4578 | .type = ALC_FIXUP_PINS, |
| 4579 | .v.pins = (const struct alc_pincfg[]) { |
| 4580 | /* set up the whole pins as BIOS is utterly broken */ |
| 4581 | { 0x14, 0x99030120 }, /* speaker */ |
| 4582 | { 0x15, 0x0121411f }, /* HP */ |
| 4583 | { 0x16, 0x411111f0 }, /* N/A */ |
| 4584 | { 0x17, 0x411111f0 }, /* N/A */ |
| 4585 | { 0x18, 0x01a19950 }, /* mic-in */ |
| 4586 | { 0x19, 0x411111f0 }, /* N/A */ |
| 4587 | { 0x1a, 0x01813031 }, /* line-in */ |
| 4588 | { 0x1b, 0x411111f0 }, /* N/A */ |
| 4589 | { 0x1c, 0x411111f0 }, /* N/A */ |
| 4590 | { 0x1d, 0x411111f0 }, /* N/A */ |
| 4591 | { 0x1e, 0x0144111e }, /* SPDIF */ |
| 4592 | { } |
| 4593 | } |
| 4594 | }, |
Takashi Iwai | 67b6ec3 | 2012-02-20 18:20:42 +0100 | [diff] [blame] | 4595 | [ALC880_FIXUP_3ST_BASE] = { |
| 4596 | .type = ALC_FIXUP_PINS, |
| 4597 | .v.pins = (const struct alc_pincfg[]) { |
| 4598 | { 0x14, 0x01014010 }, /* line-out */ |
| 4599 | { 0x15, 0x411111f0 }, /* N/A */ |
| 4600 | { 0x16, 0x411111f0 }, /* N/A */ |
| 4601 | { 0x17, 0x411111f0 }, /* N/A */ |
| 4602 | { 0x18, 0x01a19c30 }, /* mic-in */ |
| 4603 | { 0x19, 0x0121411f }, /* HP */ |
| 4604 | { 0x1a, 0x01813031 }, /* line-in */ |
| 4605 | { 0x1b, 0x02a19c40 }, /* front-mic */ |
| 4606 | { 0x1c, 0x411111f0 }, /* N/A */ |
| 4607 | { 0x1d, 0x411111f0 }, /* N/A */ |
| 4608 | /* 0x1e is filled in below */ |
| 4609 | { 0x1f, 0x411111f0 }, /* N/A */ |
| 4610 | { } |
| 4611 | } |
| 4612 | }, |
| 4613 | [ALC880_FIXUP_3ST] = { |
| 4614 | .type = ALC_FIXUP_PINS, |
| 4615 | .v.pins = (const struct alc_pincfg[]) { |
| 4616 | { 0x1e, 0x411111f0 }, /* N/A */ |
| 4617 | { } |
| 4618 | }, |
| 4619 | .chained = true, |
| 4620 | .chain_id = ALC880_FIXUP_3ST_BASE, |
| 4621 | }, |
| 4622 | [ALC880_FIXUP_3ST_DIG] = { |
| 4623 | .type = ALC_FIXUP_PINS, |
| 4624 | .v.pins = (const struct alc_pincfg[]) { |
| 4625 | { 0x1e, 0x0144111e }, /* SPDIF */ |
| 4626 | { } |
| 4627 | }, |
| 4628 | .chained = true, |
| 4629 | .chain_id = ALC880_FIXUP_3ST_BASE, |
| 4630 | }, |
| 4631 | [ALC880_FIXUP_5ST_BASE] = { |
| 4632 | .type = ALC_FIXUP_PINS, |
| 4633 | .v.pins = (const struct alc_pincfg[]) { |
| 4634 | { 0x14, 0x01014010 }, /* front */ |
| 4635 | { 0x15, 0x411111f0 }, /* N/A */ |
| 4636 | { 0x16, 0x01011411 }, /* CLFE */ |
| 4637 | { 0x17, 0x01016412 }, /* surr */ |
| 4638 | { 0x18, 0x01a19c30 }, /* mic-in */ |
| 4639 | { 0x19, 0x0121411f }, /* HP */ |
| 4640 | { 0x1a, 0x01813031 }, /* line-in */ |
| 4641 | { 0x1b, 0x02a19c40 }, /* front-mic */ |
| 4642 | { 0x1c, 0x411111f0 }, /* N/A */ |
| 4643 | { 0x1d, 0x411111f0 }, /* N/A */ |
| 4644 | /* 0x1e is filled in below */ |
| 4645 | { 0x1f, 0x411111f0 }, /* N/A */ |
| 4646 | { } |
| 4647 | } |
| 4648 | }, |
| 4649 | [ALC880_FIXUP_5ST] = { |
| 4650 | .type = ALC_FIXUP_PINS, |
| 4651 | .v.pins = (const struct alc_pincfg[]) { |
| 4652 | { 0x1e, 0x411111f0 }, /* N/A */ |
| 4653 | { } |
| 4654 | }, |
| 4655 | .chained = true, |
| 4656 | .chain_id = ALC880_FIXUP_5ST_BASE, |
| 4657 | }, |
| 4658 | [ALC880_FIXUP_5ST_DIG] = { |
| 4659 | .type = ALC_FIXUP_PINS, |
| 4660 | .v.pins = (const struct alc_pincfg[]) { |
| 4661 | { 0x1e, 0x0144111e }, /* SPDIF */ |
| 4662 | { } |
| 4663 | }, |
| 4664 | .chained = true, |
| 4665 | .chain_id = ALC880_FIXUP_5ST_BASE, |
| 4666 | }, |
| 4667 | [ALC880_FIXUP_6ST_BASE] = { |
| 4668 | .type = ALC_FIXUP_PINS, |
| 4669 | .v.pins = (const struct alc_pincfg[]) { |
| 4670 | { 0x14, 0x01014010 }, /* front */ |
| 4671 | { 0x15, 0x01016412 }, /* surr */ |
| 4672 | { 0x16, 0x01011411 }, /* CLFE */ |
| 4673 | { 0x17, 0x01012414 }, /* side */ |
| 4674 | { 0x18, 0x01a19c30 }, /* mic-in */ |
| 4675 | { 0x19, 0x02a19c40 }, /* front-mic */ |
| 4676 | { 0x1a, 0x01813031 }, /* line-in */ |
| 4677 | { 0x1b, 0x0121411f }, /* HP */ |
| 4678 | { 0x1c, 0x411111f0 }, /* N/A */ |
| 4679 | { 0x1d, 0x411111f0 }, /* N/A */ |
| 4680 | /* 0x1e is filled in below */ |
| 4681 | { 0x1f, 0x411111f0 }, /* N/A */ |
| 4682 | { } |
| 4683 | } |
| 4684 | }, |
| 4685 | [ALC880_FIXUP_6ST] = { |
| 4686 | .type = ALC_FIXUP_PINS, |
| 4687 | .v.pins = (const struct alc_pincfg[]) { |
| 4688 | { 0x1e, 0x411111f0 }, /* N/A */ |
| 4689 | { } |
| 4690 | }, |
| 4691 | .chained = true, |
| 4692 | .chain_id = ALC880_FIXUP_6ST_BASE, |
| 4693 | }, |
| 4694 | [ALC880_FIXUP_6ST_DIG] = { |
| 4695 | .type = ALC_FIXUP_PINS, |
| 4696 | .v.pins = (const struct alc_pincfg[]) { |
| 4697 | { 0x1e, 0x0144111e }, /* SPDIF */ |
| 4698 | { } |
| 4699 | }, |
| 4700 | .chained = true, |
| 4701 | .chain_id = ALC880_FIXUP_6ST_BASE, |
| 4702 | }, |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4703 | }; |
| 4704 | |
| 4705 | static const struct snd_pci_quirk alc880_fixup_tbl[] = { |
Takashi Iwai | f02aab5 | 2012-02-17 16:33:56 +0100 | [diff] [blame] | 4706 | SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810), |
Takashi Iwai | 96e225f | 2012-02-20 17:41:51 +0100 | [diff] [blame] | 4707 | SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V), |
Takashi Iwai | 29e3fdc | 2012-02-20 17:56:57 +0100 | [diff] [blame] | 4708 | SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1), |
| 4709 | SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2), |
Takashi Iwai | 27e917f | 2012-02-17 17:49:54 +0100 | [diff] [blame] | 4710 | SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF), |
Takashi Iwai | 967b88c | 2012-02-20 17:31:02 +0100 | [diff] [blame] | 4711 | SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG), |
Takashi Iwai | ba53381 | 2012-02-20 16:36:52 +0100 | [diff] [blame] | 4712 | SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734), |
Takashi Iwai | 817de92 | 2012-02-20 17:20:48 +0100 | [diff] [blame] | 4713 | SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL), |
Takashi Iwai | 7833c7e | 2012-02-20 17:11:38 +0100 | [diff] [blame] | 4714 | SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB), |
Takashi Iwai | f02aab5 | 2012-02-17 16:33:56 +0100 | [diff] [blame] | 4715 | SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810), |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4716 | SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM), |
Takashi Iwai | ba53381 | 2012-02-20 16:36:52 +0100 | [diff] [blame] | 4717 | SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734), |
Takashi Iwai | cf5a227 | 2012-02-20 16:31:07 +0100 | [diff] [blame] | 4718 | SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU), |
Takashi Iwai | ba53381 | 2012-02-20 16:36:52 +0100 | [diff] [blame] | 4719 | SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734), |
Takashi Iwai | cf5a227 | 2012-02-20 16:31:07 +0100 | [diff] [blame] | 4720 | SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU), |
Takashi Iwai | dc6af52 | 2012-02-17 16:18:59 +0100 | [diff] [blame] | 4721 | SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG), |
| 4722 | SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG), |
| 4723 | SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG), |
Takashi Iwai | b9368f5 | 2012-02-17 17:54:44 +0100 | [diff] [blame] | 4724 | SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700), |
Takashi Iwai | 67b6ec3 | 2012-02-20 18:20:42 +0100 | [diff] [blame] | 4725 | |
| 4726 | /* Below is the copied entries from alc880_quirks.c. |
| 4727 | * It's not quite sure whether BIOS sets the correct pin-config table |
| 4728 | * on these machines, thus they are kept to be compatible with |
| 4729 | * the old static quirks. Once when it's confirmed to work without |
| 4730 | * these overrides, it'd be better to remove. |
| 4731 | */ |
| 4732 | SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG), |
| 4733 | SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST), |
| 4734 | SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG), |
| 4735 | SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG), |
| 4736 | SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG), |
| 4737 | SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG), |
| 4738 | SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG), |
| 4739 | SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST), |
| 4740 | SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG), |
| 4741 | SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST), |
| 4742 | SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST), |
| 4743 | SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST), |
| 4744 | SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST), |
| 4745 | SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST), |
| 4746 | SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG), |
| 4747 | SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG), |
| 4748 | SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG), |
| 4749 | SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG), |
| 4750 | SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG), |
| 4751 | SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG), |
| 4752 | SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG), |
| 4753 | SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */ |
| 4754 | SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG), |
| 4755 | SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG), |
| 4756 | SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG), |
| 4757 | SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG), |
| 4758 | SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG), |
| 4759 | SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG), |
| 4760 | SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG), |
| 4761 | SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG), |
| 4762 | SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG), |
| 4763 | SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG), |
| 4764 | SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG), |
| 4765 | /* default Intel */ |
| 4766 | SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST), |
| 4767 | SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG), |
| 4768 | SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG), |
| 4769 | {} |
| 4770 | }; |
| 4771 | |
| 4772 | static const struct alc_model_fixup alc880_fixup_models[] = { |
| 4773 | {.id = ALC880_FIXUP_3ST, .name = "3stack"}, |
| 4774 | {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"}, |
| 4775 | {.id = ALC880_FIXUP_5ST, .name = "5stack"}, |
| 4776 | {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"}, |
| 4777 | {.id = ALC880_FIXUP_6ST, .name = "6stack"}, |
| 4778 | {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"}, |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4779 | {} |
| 4780 | }; |
| 4781 | |
| 4782 | |
| 4783 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4784 | * OK, here we have finally the patch for ALC880 |
| 4785 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4786 | static int patch_alc880(struct hda_codec *codec) |
| 4787 | { |
| 4788 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4789 | int err; |
| 4790 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 4791 | err = alc_alloc_spec(codec, 0x0b); |
| 4792 | if (err < 0) |
| 4793 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4794 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 4795 | spec = codec->spec; |
Takashi Iwai | 7b1655f | 2011-07-14 15:31:21 +0200 | [diff] [blame] | 4796 | spec->need_dac_fix = 1; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4797 | |
Takashi Iwai | 67b6ec3 | 2012-02-20 18:20:42 +0100 | [diff] [blame] | 4798 | alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl, |
| 4799 | alc880_fixups); |
| 4800 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4801 | |
Takashi Iwai | 67b6ec3 | 2012-02-20 18:20:42 +0100 | [diff] [blame] | 4802 | /* automatic parse from the BIOS config */ |
| 4803 | err = alc880_parse_auto_config(codec); |
| 4804 | if (err < 0) |
| 4805 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4806 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4807 | if (!spec->no_analog) { |
| 4808 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4809 | if (err < 0) |
| 4810 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4811 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 4812 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4813 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4814 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4815 | |
Takashi Iwai | 589876e | 2012-02-20 15:47:55 +0100 | [diff] [blame] | 4816 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4817 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4818 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4819 | |
| 4820 | error: |
| 4821 | alc_free(codec); |
| 4822 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4823 | } |
| 4824 | |
| 4825 | |
| 4826 | /* |
| 4827 | * ALC260 support |
| 4828 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4829 | static int alc260_parse_auto_config(struct hda_codec *codec) |
| 4830 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4831 | static const hda_nid_t alc260_ignore[] = { 0x17, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4832 | static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 }; |
| 4833 | return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4834 | } |
| 4835 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4836 | /* |
| 4837 | * Pin config fixes |
| 4838 | */ |
| 4839 | enum { |
Takashi Iwai | ca8f042 | 2012-02-16 11:51:19 +0100 | [diff] [blame] | 4840 | ALC260_FIXUP_HP_DC5750, |
| 4841 | ALC260_FIXUP_HP_PIN_0F, |
| 4842 | ALC260_FIXUP_COEF, |
Takashi Iwai | 15317ab | 2012-02-16 12:02:53 +0100 | [diff] [blame] | 4843 | ALC260_FIXUP_GPIO1, |
Takashi Iwai | 20f7d92 | 2012-02-16 12:35:16 +0100 | [diff] [blame] | 4844 | ALC260_FIXUP_GPIO1_TOGGLE, |
| 4845 | ALC260_FIXUP_REPLACER, |
Takashi Iwai | 0a1c4fa | 2012-02-16 12:42:30 +0100 | [diff] [blame] | 4846 | ALC260_FIXUP_HP_B1900, |
Takashi Iwai | 118cb4a | 2012-04-19 07:33:27 +0200 | [diff] [blame] | 4847 | ALC260_FIXUP_KN1, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4848 | }; |
| 4849 | |
Takashi Iwai | 20f7d92 | 2012-02-16 12:35:16 +0100 | [diff] [blame] | 4850 | static void alc260_gpio1_automute(struct hda_codec *codec) |
| 4851 | { |
| 4852 | struct alc_spec *spec = codec->spec; |
| 4853 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, |
| 4854 | spec->hp_jack_present); |
| 4855 | } |
| 4856 | |
| 4857 | static void alc260_fixup_gpio1_toggle(struct hda_codec *codec, |
| 4858 | const struct alc_fixup *fix, int action) |
| 4859 | { |
| 4860 | struct alc_spec *spec = codec->spec; |
| 4861 | if (action == ALC_FIXUP_ACT_PROBE) { |
| 4862 | /* although the machine has only one output pin, we need to |
| 4863 | * toggle GPIO1 according to the jack state |
| 4864 | */ |
| 4865 | spec->automute_hook = alc260_gpio1_automute; |
| 4866 | spec->detect_hp = 1; |
| 4867 | spec->automute_speaker = 1; |
| 4868 | spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */ |
| 4869 | snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT); |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 4870 | snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs); |
Takashi Iwai | 20f7d92 | 2012-02-16 12:35:16 +0100 | [diff] [blame] | 4871 | } |
| 4872 | } |
| 4873 | |
Takashi Iwai | 118cb4a | 2012-04-19 07:33:27 +0200 | [diff] [blame] | 4874 | static void alc260_fixup_kn1(struct hda_codec *codec, |
| 4875 | const struct alc_fixup *fix, int action) |
| 4876 | { |
| 4877 | struct alc_spec *spec = codec->spec; |
| 4878 | static const struct alc_pincfg pincfgs[] = { |
| 4879 | { 0x0f, 0x02214000 }, /* HP/speaker */ |
| 4880 | { 0x12, 0x90a60160 }, /* int mic */ |
| 4881 | { 0x13, 0x02a19000 }, /* ext mic */ |
| 4882 | { 0x18, 0x01446000 }, /* SPDIF out */ |
| 4883 | /* disable bogus I/O pins */ |
| 4884 | { 0x10, 0x411111f0 }, |
| 4885 | { 0x11, 0x411111f0 }, |
| 4886 | { 0x14, 0x411111f0 }, |
| 4887 | { 0x15, 0x411111f0 }, |
| 4888 | { 0x16, 0x411111f0 }, |
| 4889 | { 0x17, 0x411111f0 }, |
| 4890 | { 0x19, 0x411111f0 }, |
| 4891 | { } |
| 4892 | }; |
| 4893 | |
| 4894 | switch (action) { |
| 4895 | case ALC_FIXUP_ACT_PRE_PROBE: |
| 4896 | alc_apply_pincfgs(codec, pincfgs); |
| 4897 | break; |
| 4898 | case ALC_FIXUP_ACT_PROBE: |
| 4899 | spec->init_amp = ALC_INIT_NONE; |
| 4900 | break; |
| 4901 | } |
| 4902 | } |
| 4903 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4904 | static const struct alc_fixup alc260_fixups[] = { |
Takashi Iwai | ca8f042 | 2012-02-16 11:51:19 +0100 | [diff] [blame] | 4905 | [ALC260_FIXUP_HP_DC5750] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4906 | .type = ALC_FIXUP_PINS, |
| 4907 | .v.pins = (const struct alc_pincfg[]) { |
| 4908 | { 0x11, 0x90130110 }, /* speaker */ |
| 4909 | { } |
| 4910 | } |
| 4911 | }, |
Takashi Iwai | ca8f042 | 2012-02-16 11:51:19 +0100 | [diff] [blame] | 4912 | [ALC260_FIXUP_HP_PIN_0F] = { |
| 4913 | .type = ALC_FIXUP_PINS, |
| 4914 | .v.pins = (const struct alc_pincfg[]) { |
| 4915 | { 0x0f, 0x01214000 }, /* HP */ |
| 4916 | { } |
| 4917 | } |
| 4918 | }, |
| 4919 | [ALC260_FIXUP_COEF] = { |
| 4920 | .type = ALC_FIXUP_VERBS, |
| 4921 | .v.verbs = (const struct hda_verb[]) { |
| 4922 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4923 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 }, |
| 4924 | { } |
| 4925 | }, |
| 4926 | .chained = true, |
| 4927 | .chain_id = ALC260_FIXUP_HP_PIN_0F, |
| 4928 | }, |
Takashi Iwai | 15317ab | 2012-02-16 12:02:53 +0100 | [diff] [blame] | 4929 | [ALC260_FIXUP_GPIO1] = { |
| 4930 | .type = ALC_FIXUP_VERBS, |
| 4931 | .v.verbs = alc_gpio1_init_verbs, |
| 4932 | }, |
Takashi Iwai | 20f7d92 | 2012-02-16 12:35:16 +0100 | [diff] [blame] | 4933 | [ALC260_FIXUP_GPIO1_TOGGLE] = { |
| 4934 | .type = ALC_FIXUP_FUNC, |
| 4935 | .v.func = alc260_fixup_gpio1_toggle, |
| 4936 | .chained = true, |
| 4937 | .chain_id = ALC260_FIXUP_HP_PIN_0F, |
| 4938 | }, |
| 4939 | [ALC260_FIXUP_REPLACER] = { |
| 4940 | .type = ALC_FIXUP_VERBS, |
| 4941 | .v.verbs = (const struct hda_verb[]) { |
| 4942 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4943 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, |
| 4944 | { } |
| 4945 | }, |
| 4946 | .chained = true, |
| 4947 | .chain_id = ALC260_FIXUP_GPIO1_TOGGLE, |
| 4948 | }, |
Takashi Iwai | 0a1c4fa | 2012-02-16 12:42:30 +0100 | [diff] [blame] | 4949 | [ALC260_FIXUP_HP_B1900] = { |
| 4950 | .type = ALC_FIXUP_FUNC, |
| 4951 | .v.func = alc260_fixup_gpio1_toggle, |
| 4952 | .chained = true, |
| 4953 | .chain_id = ALC260_FIXUP_COEF, |
Takashi Iwai | 118cb4a | 2012-04-19 07:33:27 +0200 | [diff] [blame] | 4954 | }, |
| 4955 | [ALC260_FIXUP_KN1] = { |
| 4956 | .type = ALC_FIXUP_FUNC, |
| 4957 | .v.func = alc260_fixup_kn1, |
| 4958 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4959 | }; |
| 4960 | |
| 4961 | static const struct snd_pci_quirk alc260_fixup_tbl[] = { |
Takashi Iwai | 15317ab | 2012-02-16 12:02:53 +0100 | [diff] [blame] | 4962 | SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1), |
Takashi Iwai | ca8f042 | 2012-02-16 11:51:19 +0100 | [diff] [blame] | 4963 | SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF), |
Takashi Iwai | 15317ab | 2012-02-16 12:02:53 +0100 | [diff] [blame] | 4964 | SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1), |
Takashi Iwai | ca8f042 | 2012-02-16 11:51:19 +0100 | [diff] [blame] | 4965 | SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750), |
Takashi Iwai | 0a1c4fa | 2012-02-16 12:42:30 +0100 | [diff] [blame] | 4966 | SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900), |
Takashi Iwai | b1f5808 | 2012-02-16 12:45:03 +0100 | [diff] [blame] | 4967 | SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1), |
Takashi Iwai | 118cb4a | 2012-04-19 07:33:27 +0200 | [diff] [blame] | 4968 | SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1), |
Takashi Iwai | 20f7d92 | 2012-02-16 12:35:16 +0100 | [diff] [blame] | 4969 | SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER), |
Takashi Iwai | ca8f042 | 2012-02-16 11:51:19 +0100 | [diff] [blame] | 4970 | SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4971 | {} |
| 4972 | }; |
| 4973 | |
| 4974 | /* |
| 4975 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4976 | static int patch_alc260(struct hda_codec *codec) |
| 4977 | { |
| 4978 | struct alc_spec *spec; |
Takashi Iwai | c3c2c9e | 2012-02-16 12:59:55 +0100 | [diff] [blame] | 4979 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4980 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 4981 | err = alc_alloc_spec(codec, 0x07); |
| 4982 | if (err < 0) |
| 4983 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4984 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 4985 | spec = codec->spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4986 | |
Takashi Iwai | c3c2c9e | 2012-02-16 12:59:55 +0100 | [diff] [blame] | 4987 | alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); |
| 4988 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4989 | |
Takashi Iwai | c3c2c9e | 2012-02-16 12:59:55 +0100 | [diff] [blame] | 4990 | /* automatic parse from the BIOS config */ |
| 4991 | err = alc260_parse_auto_config(codec); |
| 4992 | if (err < 0) |
| 4993 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4994 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4995 | if (!spec->no_analog) { |
| 4996 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4997 | if (err < 0) |
| 4998 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4999 | set_beep_amp(spec, 0x07, 0x05, HDA_INPUT); |
| 5000 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5001 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5002 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5003 | spec->shutup = alc_eapd_shutup; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5004 | |
Takashi Iwai | 589876e | 2012-02-20 15:47:55 +0100 | [diff] [blame] | 5005 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5006 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5007 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5008 | |
| 5009 | error: |
| 5010 | alc_free(codec); |
| 5011 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5012 | } |
| 5013 | |
| 5014 | |
| 5015 | /* |
| 5016 | * ALC882/883/885/888/889 support |
| 5017 | * |
| 5018 | * ALC882 is almost identical with ALC880 but has cleaner and more flexible |
| 5019 | * configuration. Each pin widget can choose any input DACs and a mixer. |
| 5020 | * Each ADC is connected from a mixer of all inputs. This makes possible |
| 5021 | * 6-channel independent captures. |
| 5022 | * |
| 5023 | * In addition, an independent DAC for the multi-playback (not used in this |
| 5024 | * driver yet). |
| 5025 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5026 | |
| 5027 | /* |
| 5028 | * Pin config fixes |
| 5029 | */ |
| 5030 | enum { |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 5031 | ALC882_FIXUP_ABIT_AW9D_MAX, |
| 5032 | ALC882_FIXUP_LENOVO_Y530, |
| 5033 | ALC882_FIXUP_PB_M5210, |
| 5034 | ALC882_FIXUP_ACER_ASPIRE_7736, |
| 5035 | ALC882_FIXUP_ASUS_W90V, |
Marton Balint | 8f23921 | 2012-03-05 21:33:23 +0100 | [diff] [blame] | 5036 | ALC889_FIXUP_CD, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 5037 | ALC889_FIXUP_VAIO_TT, |
Takashi Iwai | 0e7cc2e | 2011-11-09 12:42:48 +0100 | [diff] [blame] | 5038 | ALC888_FIXUP_EEE1601, |
Takashi Iwai | 177943a | 2011-11-09 12:55:18 +0100 | [diff] [blame] | 5039 | ALC882_FIXUP_EAPD, |
Takashi Iwai | 7a6069b | 2011-11-09 15:22:01 +0100 | [diff] [blame] | 5040 | ALC883_FIXUP_EAPD, |
Takashi Iwai | 8812c4f | 2011-11-09 17:39:15 +0100 | [diff] [blame] | 5041 | ALC883_FIXUP_ACER_EAPD, |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5042 | ALC882_FIXUP_GPIO1, |
| 5043 | ALC882_FIXUP_GPIO2, |
Takashi Iwai | eb844d5 | 2011-11-09 18:03:07 +0100 | [diff] [blame] | 5044 | ALC882_FIXUP_GPIO3, |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 5045 | ALC889_FIXUP_COEF, |
| 5046 | ALC882_FIXUP_ASUS_W2JC, |
Takashi Iwai | c3e837b | 2011-11-10 16:01:47 +0100 | [diff] [blame] | 5047 | ALC882_FIXUP_ACER_ASPIRE_4930G, |
| 5048 | ALC882_FIXUP_ACER_ASPIRE_8930G, |
| 5049 | ALC882_FIXUP_ASPIRE_8930G_VERBS, |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 5050 | ALC885_FIXUP_MACPRO_GPIO, |
Takashi Iwai | 02a237b | 2012-02-13 15:25:07 +0100 | [diff] [blame] | 5051 | ALC889_FIXUP_DAC_ROUTE, |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5052 | ALC889_FIXUP_MBP_VREF, |
| 5053 | ALC889_FIXUP_IMAC91_VREF, |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 5054 | ALC882_FIXUP_INV_DMIC, |
Takashi Iwai | e427c23 | 2012-07-29 10:04:08 +0200 | [diff] [blame] | 5055 | ALC882_FIXUP_NO_PRIMARY_HP, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5056 | }; |
| 5057 | |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 5058 | static void alc889_fixup_coef(struct hda_codec *codec, |
| 5059 | const struct alc_fixup *fix, int action) |
| 5060 | { |
| 5061 | if (action != ALC_FIXUP_ACT_INIT) |
| 5062 | return; |
| 5063 | alc889_coef_init(codec); |
| 5064 | } |
| 5065 | |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 5066 | /* toggle speaker-output according to the hp-jack state */ |
| 5067 | static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted) |
| 5068 | { |
| 5069 | unsigned int gpiostate, gpiomask, gpiodir; |
| 5070 | |
| 5071 | gpiostate = snd_hda_codec_read(codec, codec->afg, 0, |
| 5072 | AC_VERB_GET_GPIO_DATA, 0); |
| 5073 | |
| 5074 | if (!muted) |
| 5075 | gpiostate |= (1 << pin); |
| 5076 | else |
| 5077 | gpiostate &= ~(1 << pin); |
| 5078 | |
| 5079 | gpiomask = snd_hda_codec_read(codec, codec->afg, 0, |
| 5080 | AC_VERB_GET_GPIO_MASK, 0); |
| 5081 | gpiomask |= (1 << pin); |
| 5082 | |
| 5083 | gpiodir = snd_hda_codec_read(codec, codec->afg, 0, |
| 5084 | AC_VERB_GET_GPIO_DIRECTION, 0); |
| 5085 | gpiodir |= (1 << pin); |
| 5086 | |
| 5087 | |
| 5088 | snd_hda_codec_write(codec, codec->afg, 0, |
| 5089 | AC_VERB_SET_GPIO_MASK, gpiomask); |
| 5090 | snd_hda_codec_write(codec, codec->afg, 0, |
| 5091 | AC_VERB_SET_GPIO_DIRECTION, gpiodir); |
| 5092 | |
| 5093 | msleep(1); |
| 5094 | |
| 5095 | snd_hda_codec_write(codec, codec->afg, 0, |
| 5096 | AC_VERB_SET_GPIO_DATA, gpiostate); |
| 5097 | } |
| 5098 | |
| 5099 | /* set up GPIO at initialization */ |
| 5100 | static void alc885_fixup_macpro_gpio(struct hda_codec *codec, |
| 5101 | const struct alc_fixup *fix, int action) |
| 5102 | { |
| 5103 | if (action != ALC_FIXUP_ACT_INIT) |
| 5104 | return; |
| 5105 | alc882_gpio_mute(codec, 0, 0); |
| 5106 | alc882_gpio_mute(codec, 1, 0); |
| 5107 | } |
| 5108 | |
Takashi Iwai | 02a237b | 2012-02-13 15:25:07 +0100 | [diff] [blame] | 5109 | /* Fix the connection of some pins for ALC889: |
| 5110 | * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't |
| 5111 | * work correctly (bko#42740) |
| 5112 | */ |
| 5113 | static void alc889_fixup_dac_route(struct hda_codec *codec, |
| 5114 | const struct alc_fixup *fix, int action) |
| 5115 | { |
| 5116 | if (action == ALC_FIXUP_ACT_PRE_PROBE) { |
Takashi Iwai | ef8d60f | 2012-02-17 10:12:38 +0100 | [diff] [blame] | 5117 | /* fake the connections during parsing the tree */ |
Takashi Iwai | 02a237b | 2012-02-13 15:25:07 +0100 | [diff] [blame] | 5118 | hda_nid_t conn1[2] = { 0x0c, 0x0d }; |
| 5119 | hda_nid_t conn2[2] = { 0x0e, 0x0f }; |
| 5120 | snd_hda_override_conn_list(codec, 0x14, 2, conn1); |
| 5121 | snd_hda_override_conn_list(codec, 0x15, 2, conn1); |
| 5122 | snd_hda_override_conn_list(codec, 0x18, 2, conn2); |
| 5123 | snd_hda_override_conn_list(codec, 0x1a, 2, conn2); |
Takashi Iwai | ef8d60f | 2012-02-17 10:12:38 +0100 | [diff] [blame] | 5124 | } else if (action == ALC_FIXUP_ACT_PROBE) { |
| 5125 | /* restore the connections */ |
| 5126 | hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 }; |
| 5127 | snd_hda_override_conn_list(codec, 0x14, 5, conn); |
| 5128 | snd_hda_override_conn_list(codec, 0x15, 5, conn); |
| 5129 | snd_hda_override_conn_list(codec, 0x18, 5, conn); |
| 5130 | snd_hda_override_conn_list(codec, 0x1a, 5, conn); |
Takashi Iwai | 02a237b | 2012-02-13 15:25:07 +0100 | [diff] [blame] | 5131 | } |
| 5132 | } |
| 5133 | |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5134 | /* Set VREF on HP pin */ |
| 5135 | static void alc889_fixup_mbp_vref(struct hda_codec *codec, |
| 5136 | const struct alc_fixup *fix, int action) |
| 5137 | { |
| 5138 | struct alc_spec *spec = codec->spec; |
| 5139 | static hda_nid_t nids[2] = { 0x14, 0x15 }; |
| 5140 | int i; |
| 5141 | |
| 5142 | if (action != ALC_FIXUP_ACT_INIT) |
| 5143 | return; |
| 5144 | for (i = 0; i < ARRAY_SIZE(nids); i++) { |
| 5145 | unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]); |
| 5146 | if (get_defcfg_device(val) != AC_JACK_HP_OUT) |
| 5147 | continue; |
| 5148 | val = snd_hda_codec_read(codec, nids[i], 0, |
| 5149 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 5150 | val |= AC_PINCTL_VREF_80; |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 5151 | snd_hda_set_pin_ctl(codec, nids[i], val); |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5152 | spec->keep_vref_in_automute = 1; |
| 5153 | break; |
| 5154 | } |
| 5155 | } |
| 5156 | |
| 5157 | /* Set VREF on speaker pins on imac91 */ |
| 5158 | static void alc889_fixup_imac91_vref(struct hda_codec *codec, |
| 5159 | const struct alc_fixup *fix, int action) |
| 5160 | { |
| 5161 | struct alc_spec *spec = codec->spec; |
| 5162 | static hda_nid_t nids[2] = { 0x18, 0x1a }; |
| 5163 | int i; |
| 5164 | |
| 5165 | if (action != ALC_FIXUP_ACT_INIT) |
| 5166 | return; |
| 5167 | for (i = 0; i < ARRAY_SIZE(nids); i++) { |
| 5168 | unsigned int val; |
| 5169 | val = snd_hda_codec_read(codec, nids[i], 0, |
| 5170 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 5171 | val |= AC_PINCTL_VREF_50; |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 5172 | snd_hda_set_pin_ctl(codec, nids[i], val); |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5173 | } |
| 5174 | spec->keep_vref_in_automute = 1; |
| 5175 | } |
| 5176 | |
Takashi Iwai | e427c23 | 2012-07-29 10:04:08 +0200 | [diff] [blame] | 5177 | /* Don't take HP output as primary |
| 5178 | * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05 |
| 5179 | */ |
| 5180 | static void alc882_fixup_no_primary_hp(struct hda_codec *codec, |
| 5181 | const struct alc_fixup *fix, int action) |
| 5182 | { |
| 5183 | struct alc_spec *spec = codec->spec; |
| 5184 | if (action == ALC_FIXUP_ACT_PRE_PROBE) |
| 5185 | spec->no_primary_hp = 1; |
| 5186 | } |
| 5187 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5188 | static const struct alc_fixup alc882_fixups[] = { |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 5189 | [ALC882_FIXUP_ABIT_AW9D_MAX] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5190 | .type = ALC_FIXUP_PINS, |
| 5191 | .v.pins = (const struct alc_pincfg[]) { |
| 5192 | { 0x15, 0x01080104 }, /* side */ |
| 5193 | { 0x16, 0x01011012 }, /* rear */ |
| 5194 | { 0x17, 0x01016011 }, /* clfe */ |
| 5195 | { } |
| 5196 | } |
| 5197 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 5198 | [ALC882_FIXUP_LENOVO_Y530] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5199 | .type = ALC_FIXUP_PINS, |
| 5200 | .v.pins = (const struct alc_pincfg[]) { |
| 5201 | { 0x15, 0x99130112 }, /* rear int speakers */ |
| 5202 | { 0x16, 0x99130111 }, /* subwoofer */ |
| 5203 | { } |
| 5204 | } |
| 5205 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 5206 | [ALC882_FIXUP_PB_M5210] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5207 | .type = ALC_FIXUP_VERBS, |
| 5208 | .v.verbs = (const struct hda_verb[]) { |
| 5209 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, |
| 5210 | {} |
| 5211 | } |
| 5212 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 5213 | [ALC882_FIXUP_ACER_ASPIRE_7736] = { |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 5214 | .type = ALC_FIXUP_FUNC, |
| 5215 | .v.func = alc_fixup_sku_ignore, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5216 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 5217 | [ALC882_FIXUP_ASUS_W90V] = { |
Takashi Iwai | 5cdf745 | 2011-10-26 23:04:08 +0200 | [diff] [blame] | 5218 | .type = ALC_FIXUP_PINS, |
| 5219 | .v.pins = (const struct alc_pincfg[]) { |
| 5220 | { 0x16, 0x99130110 }, /* fix sequence for CLFE */ |
| 5221 | { } |
| 5222 | } |
| 5223 | }, |
Marton Balint | 8f23921 | 2012-03-05 21:33:23 +0100 | [diff] [blame] | 5224 | [ALC889_FIXUP_CD] = { |
| 5225 | .type = ALC_FIXUP_PINS, |
| 5226 | .v.pins = (const struct alc_pincfg[]) { |
| 5227 | { 0x1c, 0x993301f0 }, /* CD */ |
| 5228 | { } |
| 5229 | } |
| 5230 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 5231 | [ALC889_FIXUP_VAIO_TT] = { |
| 5232 | .type = ALC_FIXUP_PINS, |
| 5233 | .v.pins = (const struct alc_pincfg[]) { |
| 5234 | { 0x17, 0x90170111 }, /* hidden surround speaker */ |
| 5235 | { } |
| 5236 | } |
| 5237 | }, |
Takashi Iwai | 0e7cc2e | 2011-11-09 12:42:48 +0100 | [diff] [blame] | 5238 | [ALC888_FIXUP_EEE1601] = { |
| 5239 | .type = ALC_FIXUP_VERBS, |
| 5240 | .v.verbs = (const struct hda_verb[]) { |
| 5241 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b }, |
| 5242 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 }, |
| 5243 | { } |
| 5244 | } |
Takashi Iwai | 177943a | 2011-11-09 12:55:18 +0100 | [diff] [blame] | 5245 | }, |
| 5246 | [ALC882_FIXUP_EAPD] = { |
| 5247 | .type = ALC_FIXUP_VERBS, |
| 5248 | .v.verbs = (const struct hda_verb[]) { |
| 5249 | /* change to EAPD mode */ |
| 5250 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 5251 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 }, |
| 5252 | { } |
| 5253 | } |
| 5254 | }, |
Takashi Iwai | 7a6069b | 2011-11-09 15:22:01 +0100 | [diff] [blame] | 5255 | [ALC883_FIXUP_EAPD] = { |
| 5256 | .type = ALC_FIXUP_VERBS, |
| 5257 | .v.verbs = (const struct hda_verb[]) { |
| 5258 | /* change to EAPD mode */ |
| 5259 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 5260 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, |
| 5261 | { } |
| 5262 | } |
| 5263 | }, |
Takashi Iwai | 8812c4f | 2011-11-09 17:39:15 +0100 | [diff] [blame] | 5264 | [ALC883_FIXUP_ACER_EAPD] = { |
| 5265 | .type = ALC_FIXUP_VERBS, |
| 5266 | .v.verbs = (const struct hda_verb[]) { |
| 5267 | /* eanable EAPD on Acer laptops */ |
| 5268 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 5269 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, |
| 5270 | { } |
| 5271 | } |
| 5272 | }, |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5273 | [ALC882_FIXUP_GPIO1] = { |
| 5274 | .type = ALC_FIXUP_VERBS, |
| 5275 | .v.verbs = alc_gpio1_init_verbs, |
| 5276 | }, |
| 5277 | [ALC882_FIXUP_GPIO2] = { |
| 5278 | .type = ALC_FIXUP_VERBS, |
| 5279 | .v.verbs = alc_gpio2_init_verbs, |
| 5280 | }, |
Takashi Iwai | eb844d5 | 2011-11-09 18:03:07 +0100 | [diff] [blame] | 5281 | [ALC882_FIXUP_GPIO3] = { |
| 5282 | .type = ALC_FIXUP_VERBS, |
| 5283 | .v.verbs = alc_gpio3_init_verbs, |
| 5284 | }, |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 5285 | [ALC882_FIXUP_ASUS_W2JC] = { |
| 5286 | .type = ALC_FIXUP_VERBS, |
| 5287 | .v.verbs = alc_gpio1_init_verbs, |
| 5288 | .chained = true, |
| 5289 | .chain_id = ALC882_FIXUP_EAPD, |
| 5290 | }, |
| 5291 | [ALC889_FIXUP_COEF] = { |
| 5292 | .type = ALC_FIXUP_FUNC, |
| 5293 | .v.func = alc889_fixup_coef, |
| 5294 | }, |
Takashi Iwai | c3e837b | 2011-11-10 16:01:47 +0100 | [diff] [blame] | 5295 | [ALC882_FIXUP_ACER_ASPIRE_4930G] = { |
| 5296 | .type = ALC_FIXUP_PINS, |
| 5297 | .v.pins = (const struct alc_pincfg[]) { |
| 5298 | { 0x16, 0x99130111 }, /* CLFE speaker */ |
| 5299 | { 0x17, 0x99130112 }, /* surround speaker */ |
| 5300 | { } |
Takashi Iwai | 038d4fe | 2012-04-11 17:18:12 +0200 | [diff] [blame] | 5301 | }, |
| 5302 | .chained = true, |
| 5303 | .chain_id = ALC882_FIXUP_GPIO1, |
Takashi Iwai | c3e837b | 2011-11-10 16:01:47 +0100 | [diff] [blame] | 5304 | }, |
| 5305 | [ALC882_FIXUP_ACER_ASPIRE_8930G] = { |
| 5306 | .type = ALC_FIXUP_PINS, |
| 5307 | .v.pins = (const struct alc_pincfg[]) { |
| 5308 | { 0x16, 0x99130111 }, /* CLFE speaker */ |
| 5309 | { 0x1b, 0x99130112 }, /* surround speaker */ |
| 5310 | { } |
| 5311 | }, |
| 5312 | .chained = true, |
| 5313 | .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS, |
| 5314 | }, |
| 5315 | [ALC882_FIXUP_ASPIRE_8930G_VERBS] = { |
| 5316 | /* additional init verbs for Acer Aspire 8930G */ |
| 5317 | .type = ALC_FIXUP_VERBS, |
| 5318 | .v.verbs = (const struct hda_verb[]) { |
| 5319 | /* Enable all DACs */ |
| 5320 | /* DAC DISABLE/MUTE 1? */ |
| 5321 | /* setting bits 1-5 disables DAC nids 0x02-0x06 |
| 5322 | * apparently. Init=0x38 */ |
| 5323 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 }, |
| 5324 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 }, |
| 5325 | /* DAC DISABLE/MUTE 2? */ |
| 5326 | /* some bit here disables the other DACs. |
| 5327 | * Init=0x4900 */ |
| 5328 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 }, |
| 5329 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 }, |
| 5330 | /* DMIC fix |
| 5331 | * This laptop has a stereo digital microphone. |
| 5332 | * The mics are only 1cm apart which makes the stereo |
| 5333 | * useless. However, either the mic or the ALC889 |
| 5334 | * makes the signal become a difference/sum signal |
| 5335 | * instead of standard stereo, which is annoying. |
| 5336 | * So instead we flip this bit which makes the |
| 5337 | * codec replicate the sum signal to both channels, |
| 5338 | * turning it into a normal mono mic. |
| 5339 | */ |
| 5340 | /* DMIC_CONTROL? Init value = 0x0001 */ |
| 5341 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b }, |
| 5342 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 }, |
| 5343 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 5344 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, |
| 5345 | { } |
Takashi Iwai | 038d4fe | 2012-04-11 17:18:12 +0200 | [diff] [blame] | 5346 | }, |
| 5347 | .chained = true, |
| 5348 | .chain_id = ALC882_FIXUP_GPIO1, |
Takashi Iwai | c3e837b | 2011-11-10 16:01:47 +0100 | [diff] [blame] | 5349 | }, |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 5350 | [ALC885_FIXUP_MACPRO_GPIO] = { |
| 5351 | .type = ALC_FIXUP_FUNC, |
| 5352 | .v.func = alc885_fixup_macpro_gpio, |
| 5353 | }, |
Takashi Iwai | 02a237b | 2012-02-13 15:25:07 +0100 | [diff] [blame] | 5354 | [ALC889_FIXUP_DAC_ROUTE] = { |
| 5355 | .type = ALC_FIXUP_FUNC, |
| 5356 | .v.func = alc889_fixup_dac_route, |
| 5357 | }, |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5358 | [ALC889_FIXUP_MBP_VREF] = { |
| 5359 | .type = ALC_FIXUP_FUNC, |
| 5360 | .v.func = alc889_fixup_mbp_vref, |
| 5361 | .chained = true, |
| 5362 | .chain_id = ALC882_FIXUP_GPIO1, |
| 5363 | }, |
| 5364 | [ALC889_FIXUP_IMAC91_VREF] = { |
| 5365 | .type = ALC_FIXUP_FUNC, |
| 5366 | .v.func = alc889_fixup_imac91_vref, |
| 5367 | .chained = true, |
| 5368 | .chain_id = ALC882_FIXUP_GPIO1, |
| 5369 | }, |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 5370 | [ALC882_FIXUP_INV_DMIC] = { |
| 5371 | .type = ALC_FIXUP_FUNC, |
| 5372 | .v.func = alc_fixup_inv_dmic_0x12, |
| 5373 | }, |
Takashi Iwai | e427c23 | 2012-07-29 10:04:08 +0200 | [diff] [blame] | 5374 | [ALC882_FIXUP_NO_PRIMARY_HP] = { |
| 5375 | .type = ALC_FIXUP_FUNC, |
| 5376 | .v.func = alc882_fixup_no_primary_hp, |
| 5377 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5378 | }; |
| 5379 | |
| 5380 | static const struct snd_pci_quirk alc882_fixup_tbl[] = { |
Takashi Iwai | 8812c4f | 2011-11-09 17:39:15 +0100 | [diff] [blame] | 5381 | SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD), |
| 5382 | SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD), |
| 5383 | SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD), |
| 5384 | SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD), |
| 5385 | SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD), |
| 5386 | SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD), |
Takashi Iwai | c3e837b | 2011-11-10 16:01:47 +0100 | [diff] [blame] | 5387 | SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G", |
| 5388 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
| 5389 | SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G", |
| 5390 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
| 5391 | SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G", |
| 5392 | ALC882_FIXUP_ACER_ASPIRE_8930G), |
| 5393 | SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G", |
| 5394 | ALC882_FIXUP_ACER_ASPIRE_8930G), |
| 5395 | SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G", |
| 5396 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
| 5397 | SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G", |
| 5398 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
| 5399 | SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G", |
| 5400 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 5401 | SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210), |
Takashi Iwai | f5c53d8 | 2012-05-07 10:07:33 +0200 | [diff] [blame] | 5402 | SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G", |
| 5403 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
Takashi Iwai | 02a237b | 2012-02-13 15:25:07 +0100 | [diff] [blame] | 5404 | SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE), |
Takashi Iwai | fe97da1 | 2012-04-12 08:00:19 +0200 | [diff] [blame] | 5405 | SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G), |
Takashi Iwai | ac9b1cd | 2011-11-09 17:45:55 +0100 | [diff] [blame] | 5406 | SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736), |
Takashi Iwai | 177943a | 2011-11-09 12:55:18 +0100 | [diff] [blame] | 5407 | SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD), |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 5408 | SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V), |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 5409 | SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC), |
Takashi Iwai | 0e7cc2e | 2011-11-09 12:42:48 +0100 | [diff] [blame] | 5410 | SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601), |
Takashi Iwai | ac9b1cd | 2011-11-09 17:45:55 +0100 | [diff] [blame] | 5411 | SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT), |
Takashi Iwai | e427c23 | 2012-07-29 10:04:08 +0200 | [diff] [blame] | 5412 | SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP), |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 5413 | |
| 5414 | /* All Apple entries are in codec SSIDs */ |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5415 | SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF), |
| 5416 | SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF), |
| 5417 | SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF), |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 5418 | SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO), |
| 5419 | SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO), |
| 5420 | SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO), |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5421 | SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF), |
| 5422 | SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF), |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 5423 | SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD), |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5424 | SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF), |
| 5425 | SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF), |
| 5426 | SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF), |
| 5427 | SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF), |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 5428 | SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO), |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5429 | SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF), |
| 5430 | SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF), |
| 5431 | SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF), |
Josh Boyer | 29ebe40 | 2012-04-12 13:55:36 -0400 | [diff] [blame] | 5432 | SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO), |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5433 | SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF), |
| 5434 | SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF), |
| 5435 | SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF), |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 5436 | |
Takashi Iwai | 7a6069b | 2011-11-09 15:22:01 +0100 | [diff] [blame] | 5437 | SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD), |
Takashi Iwai | bca4013 | 2012-05-07 11:13:14 +0200 | [diff] [blame] | 5438 | SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD), |
Takashi Iwai | eb844d5 | 2011-11-09 18:03:07 +0100 | [diff] [blame] | 5439 | SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3), |
Marton Balint | 8f23921 | 2012-03-05 21:33:23 +0100 | [diff] [blame] | 5440 | SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD), |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 5441 | SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX), |
Takashi Iwai | 7a6069b | 2011-11-09 15:22:01 +0100 | [diff] [blame] | 5442 | SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD), |
| 5443 | SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD), |
Takashi Iwai | ac9b1cd | 2011-11-09 17:45:55 +0100 | [diff] [blame] | 5444 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530), |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 5445 | SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5446 | {} |
| 5447 | }; |
| 5448 | |
Takashi Iwai | 912093b | 2012-04-11 14:03:41 +0200 | [diff] [blame] | 5449 | static const struct alc_model_fixup alc882_fixup_models[] = { |
| 5450 | {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"}, |
| 5451 | {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"}, |
| 5452 | {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"}, |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 5453 | {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"}, |
Takashi Iwai | e427c23 | 2012-07-29 10:04:08 +0200 | [diff] [blame] | 5454 | {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"}, |
Takashi Iwai | 912093b | 2012-04-11 14:03:41 +0200 | [diff] [blame] | 5455 | {} |
| 5456 | }; |
| 5457 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5458 | /* |
| 5459 | * BIOS auto configuration |
| 5460 | */ |
| 5461 | /* almost identical with ALC880 parser... */ |
| 5462 | static int alc882_parse_auto_config(struct hda_codec *codec) |
| 5463 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5464 | static const hda_nid_t alc882_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5465 | static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5466 | return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5467 | } |
| 5468 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5469 | /* |
| 5470 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5471 | static int patch_alc882(struct hda_codec *codec) |
| 5472 | { |
| 5473 | struct alc_spec *spec; |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5474 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5475 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 5476 | err = alc_alloc_spec(codec, 0x0b); |
| 5477 | if (err < 0) |
| 5478 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5479 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 5480 | spec = codec->spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5481 | |
| 5482 | switch (codec->vendor_id) { |
| 5483 | case 0x10ec0882: |
| 5484 | case 0x10ec0885: |
| 5485 | break; |
| 5486 | default: |
| 5487 | /* ALC883 and variants */ |
| 5488 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); |
| 5489 | break; |
| 5490 | } |
| 5491 | |
Takashi Iwai | 912093b | 2012-04-11 14:03:41 +0200 | [diff] [blame] | 5492 | alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl, |
| 5493 | alc882_fixups); |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5494 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5495 | |
| 5496 | alc_auto_parse_customize_define(codec); |
| 5497 | |
Takashi Iwai | 1a97b7f | 2012-02-21 11:11:48 +0100 | [diff] [blame] | 5498 | /* automatic parse from the BIOS config */ |
| 5499 | err = alc882_parse_auto_config(codec); |
| 5500 | if (err < 0) |
| 5501 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5502 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5503 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 5504 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5505 | if (err < 0) |
| 5506 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5507 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5508 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5509 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5510 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5511 | |
Takashi Iwai | 589876e | 2012-02-20 15:47:55 +0100 | [diff] [blame] | 5512 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5513 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5514 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5515 | |
| 5516 | error: |
| 5517 | alc_free(codec); |
| 5518 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5519 | } |
| 5520 | |
| 5521 | |
| 5522 | /* |
| 5523 | * ALC262 support |
| 5524 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5525 | static int alc262_parse_auto_config(struct hda_codec *codec) |
| 5526 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5527 | static const hda_nid_t alc262_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5528 | static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5529 | return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5530 | } |
| 5531 | |
| 5532 | /* |
| 5533 | * Pin config fixes |
| 5534 | */ |
| 5535 | enum { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 5536 | ALC262_FIXUP_FSC_H270, |
| 5537 | ALC262_FIXUP_HP_Z200, |
| 5538 | ALC262_FIXUP_TYAN, |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 5539 | ALC262_FIXUP_LENOVO_3000, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 5540 | ALC262_FIXUP_BENQ, |
| 5541 | ALC262_FIXUP_BENQ_T31, |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 5542 | ALC262_FIXUP_INV_DMIC, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5543 | }; |
| 5544 | |
| 5545 | static const struct alc_fixup alc262_fixups[] = { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 5546 | [ALC262_FIXUP_FSC_H270] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5547 | .type = ALC_FIXUP_PINS, |
| 5548 | .v.pins = (const struct alc_pincfg[]) { |
| 5549 | { 0x14, 0x99130110 }, /* speaker */ |
| 5550 | { 0x15, 0x0221142f }, /* front HP */ |
| 5551 | { 0x1b, 0x0121141f }, /* rear HP */ |
| 5552 | { } |
| 5553 | } |
| 5554 | }, |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 5555 | [ALC262_FIXUP_HP_Z200] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5556 | .type = ALC_FIXUP_PINS, |
| 5557 | .v.pins = (const struct alc_pincfg[]) { |
| 5558 | { 0x16, 0x99130120 }, /* internal speaker */ |
| 5559 | { } |
| 5560 | } |
| 5561 | }, |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 5562 | [ALC262_FIXUP_TYAN] = { |
| 5563 | .type = ALC_FIXUP_PINS, |
| 5564 | .v.pins = (const struct alc_pincfg[]) { |
| 5565 | { 0x14, 0x1993e1f0 }, /* int AUX */ |
| 5566 | { } |
| 5567 | } |
| 5568 | }, |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 5569 | [ALC262_FIXUP_LENOVO_3000] = { |
| 5570 | .type = ALC_FIXUP_VERBS, |
| 5571 | .v.verbs = (const struct hda_verb[]) { |
| 5572 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 5573 | {} |
| 5574 | }, |
| 5575 | .chained = true, |
| 5576 | .chain_id = ALC262_FIXUP_BENQ, |
| 5577 | }, |
| 5578 | [ALC262_FIXUP_BENQ] = { |
| 5579 | .type = ALC_FIXUP_VERBS, |
| 5580 | .v.verbs = (const struct hda_verb[]) { |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 5581 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 5582 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, |
| 5583 | {} |
| 5584 | } |
| 5585 | }, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 5586 | [ALC262_FIXUP_BENQ_T31] = { |
| 5587 | .type = ALC_FIXUP_VERBS, |
| 5588 | .v.verbs = (const struct hda_verb[]) { |
| 5589 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 5590 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, |
| 5591 | {} |
| 5592 | } |
| 5593 | }, |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 5594 | [ALC262_FIXUP_INV_DMIC] = { |
| 5595 | .type = ALC_FIXUP_FUNC, |
| 5596 | .v.func = alc_fixup_inv_dmic_0x12, |
| 5597 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5598 | }; |
| 5599 | |
| 5600 | static const struct snd_pci_quirk alc262_fixup_tbl[] = { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 5601 | SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200), |
Takashi Iwai | 3dcd3be | 2011-11-07 14:59:40 +0100 | [diff] [blame] | 5602 | SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ), |
| 5603 | SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ), |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 5604 | SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN), |
| 5605 | SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270), |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 5606 | SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000), |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 5607 | SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ), |
| 5608 | SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5609 | {} |
| 5610 | }; |
| 5611 | |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 5612 | static const struct alc_model_fixup alc262_fixup_models[] = { |
| 5613 | {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"}, |
| 5614 | {} |
| 5615 | }; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5616 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5617 | /* |
| 5618 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5619 | static int patch_alc262(struct hda_codec *codec) |
| 5620 | { |
| 5621 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5622 | int err; |
| 5623 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 5624 | err = alc_alloc_spec(codec, 0x0b); |
| 5625 | if (err < 0) |
| 5626 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5627 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 5628 | spec = codec->spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5629 | |
| 5630 | #if 0 |
| 5631 | /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is |
| 5632 | * under-run |
| 5633 | */ |
| 5634 | { |
| 5635 | int tmp; |
| 5636 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 5637 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 5638 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 5639 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80); |
| 5640 | } |
| 5641 | #endif |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5642 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); |
| 5643 | |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 5644 | alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl, |
| 5645 | alc262_fixups); |
Takashi Iwai | 42399f7 | 2011-11-07 17:18:44 +0100 | [diff] [blame] | 5646 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5647 | |
Takashi Iwai | af741c1 | 2012-05-07 18:09:48 +0200 | [diff] [blame] | 5648 | alc_auto_parse_customize_define(codec); |
| 5649 | |
Takashi Iwai | 42399f7 | 2011-11-07 17:18:44 +0100 | [diff] [blame] | 5650 | /* automatic parse from the BIOS config */ |
| 5651 | err = alc262_parse_auto_config(codec); |
| 5652 | if (err < 0) |
| 5653 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5654 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5655 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 5656 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5657 | if (err < 0) |
| 5658 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5659 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5660 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5661 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5662 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5663 | spec->shutup = alc_eapd_shutup; |
| 5664 | |
Takashi Iwai | 589876e | 2012-02-20 15:47:55 +0100 | [diff] [blame] | 5665 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5666 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5667 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5668 | |
| 5669 | error: |
| 5670 | alc_free(codec); |
| 5671 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5672 | } |
| 5673 | |
| 5674 | /* |
| 5675 | * ALC268 |
| 5676 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5677 | /* bind Beep switches of both NID 0x0f and 0x10 */ |
| 5678 | static const struct hda_bind_ctls alc268_bind_beep_sw = { |
| 5679 | .ops = &snd_hda_bind_sw, |
| 5680 | .values = { |
| 5681 | HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT), |
| 5682 | HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT), |
| 5683 | 0 |
| 5684 | }, |
| 5685 | }; |
| 5686 | |
| 5687 | static const struct snd_kcontrol_new alc268_beep_mixer[] = { |
| 5688 | HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT), |
| 5689 | HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw), |
| 5690 | { } |
| 5691 | }; |
| 5692 | |
| 5693 | /* set PCBEEP vol = 0, mute connections */ |
| 5694 | static const struct hda_verb alc268_beep_init_verbs[] = { |
| 5695 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5696 | {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 5697 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 5698 | { } |
| 5699 | }; |
| 5700 | |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 5701 | enum { |
| 5702 | ALC268_FIXUP_INV_DMIC, |
| 5703 | }; |
| 5704 | |
| 5705 | static const struct alc_fixup alc268_fixups[] = { |
| 5706 | [ALC268_FIXUP_INV_DMIC] = { |
| 5707 | .type = ALC_FIXUP_FUNC, |
| 5708 | .v.func = alc_fixup_inv_dmic_0x12, |
| 5709 | }, |
| 5710 | }; |
| 5711 | |
| 5712 | static const struct alc_model_fixup alc268_fixup_models[] = { |
| 5713 | {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"}, |
| 5714 | {} |
| 5715 | }; |
| 5716 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5717 | /* |
| 5718 | * BIOS auto configuration |
| 5719 | */ |
| 5720 | static int alc268_parse_auto_config(struct hda_codec *codec) |
| 5721 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5722 | static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5723 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5724 | int err = alc_parse_auto_config(codec, NULL, alc268_ssids); |
| 5725 | if (err > 0) { |
| 5726 | if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { |
| 5727 | add_mixer(spec, alc268_beep_mixer); |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 5728 | snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5729 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5730 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5731 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5732 | } |
| 5733 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5734 | /* |
| 5735 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5736 | static int patch_alc268(struct hda_codec *codec) |
| 5737 | { |
| 5738 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5739 | int i, has_beep, err; |
| 5740 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5741 | /* ALC268 has no aa-loopback mixer */ |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 5742 | err = alc_alloc_spec(codec, 0); |
| 5743 | if (err < 0) |
| 5744 | return err; |
| 5745 | |
| 5746 | spec = codec->spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5747 | |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 5748 | alc_pick_fixup(codec, alc268_fixup_models, NULL, alc268_fixups); |
| 5749 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 5750 | |
Takashi Iwai | 6ebb805 | 2011-08-16 15:15:40 +0200 | [diff] [blame] | 5751 | /* automatic parse from the BIOS config */ |
| 5752 | err = alc268_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5753 | if (err < 0) |
| 5754 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5755 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5756 | has_beep = 0; |
| 5757 | for (i = 0; i < spec->num_mixers; i++) { |
| 5758 | if (spec->mixers[i] == alc268_beep_mixer) { |
| 5759 | has_beep = 1; |
| 5760 | break; |
| 5761 | } |
| 5762 | } |
| 5763 | |
| 5764 | if (has_beep) { |
| 5765 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5766 | if (err < 0) |
| 5767 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5768 | if (!query_amp_caps(codec, 0x1d, HDA_INPUT)) |
| 5769 | /* override the amp caps for beep generator */ |
| 5770 | snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT, |
| 5771 | (0x0c << AC_AMPCAP_OFFSET_SHIFT) | |
| 5772 | (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 5773 | (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 5774 | (0 << AC_AMPCAP_MUTE_SHIFT)); |
| 5775 | } |
| 5776 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5777 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5778 | spec->shutup = alc_eapd_shutup; |
| 5779 | |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 5780 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5781 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5782 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5783 | |
| 5784 | error: |
| 5785 | alc_free(codec); |
| 5786 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5787 | } |
| 5788 | |
| 5789 | /* |
| 5790 | * ALC269 |
| 5791 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5792 | static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { |
| 5793 | .substreams = 1, |
| 5794 | .channels_min = 2, |
| 5795 | .channels_max = 8, |
| 5796 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
| 5797 | /* NID is set in alc_build_pcms */ |
| 5798 | .ops = { |
| 5799 | .open = alc_playback_pcm_open, |
| 5800 | .prepare = alc_playback_pcm_prepare, |
| 5801 | .cleanup = alc_playback_pcm_cleanup |
| 5802 | }, |
| 5803 | }; |
| 5804 | |
| 5805 | static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { |
| 5806 | .substreams = 1, |
| 5807 | .channels_min = 2, |
| 5808 | .channels_max = 2, |
| 5809 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
| 5810 | /* NID is set in alc_build_pcms */ |
| 5811 | }; |
| 5812 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5813 | /* different alc269-variants */ |
| 5814 | enum { |
| 5815 | ALC269_TYPE_ALC269VA, |
| 5816 | ALC269_TYPE_ALC269VB, |
| 5817 | ALC269_TYPE_ALC269VC, |
Kailang Yang | adcc70b | 2012-05-25 08:08:38 +0200 | [diff] [blame] | 5818 | ALC269_TYPE_ALC269VD, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5819 | }; |
| 5820 | |
| 5821 | /* |
| 5822 | * BIOS auto configuration |
| 5823 | */ |
| 5824 | static int alc269_parse_auto_config(struct hda_codec *codec) |
| 5825 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5826 | static const hda_nid_t alc269_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5827 | static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 }; |
| 5828 | static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5829 | struct alc_spec *spec = codec->spec; |
Kailang Yang | adcc70b | 2012-05-25 08:08:38 +0200 | [diff] [blame] | 5830 | const hda_nid_t *ssids; |
| 5831 | |
| 5832 | switch (spec->codec_variant) { |
| 5833 | case ALC269_TYPE_ALC269VA: |
| 5834 | case ALC269_TYPE_ALC269VC: |
| 5835 | ssids = alc269va_ssids; |
| 5836 | break; |
| 5837 | case ALC269_TYPE_ALC269VB: |
| 5838 | case ALC269_TYPE_ALC269VD: |
| 5839 | ssids = alc269_ssids; |
| 5840 | break; |
| 5841 | default: |
| 5842 | ssids = alc269_ssids; |
| 5843 | break; |
| 5844 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5845 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5846 | return alc_parse_auto_config(codec, alc269_ignore, ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5847 | } |
| 5848 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5849 | static void alc269_toggle_power_output(struct hda_codec *codec, int power_up) |
| 5850 | { |
| 5851 | int val = alc_read_coef_idx(codec, 0x04); |
| 5852 | if (power_up) |
| 5853 | val |= 1 << 11; |
| 5854 | else |
| 5855 | val &= ~(1 << 11); |
| 5856 | alc_write_coef_idx(codec, 0x04, val); |
| 5857 | } |
| 5858 | |
| 5859 | static void alc269_shutup(struct hda_codec *codec) |
| 5860 | { |
Kailang Yang | adcc70b | 2012-05-25 08:08:38 +0200 | [diff] [blame] | 5861 | struct alc_spec *spec = codec->spec; |
| 5862 | |
| 5863 | if (spec->codec_variant != ALC269_TYPE_ALC269VB) |
| 5864 | return; |
| 5865 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5866 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5867 | alc269_toggle_power_output(codec, 0); |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5868 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5869 | alc269_toggle_power_output(codec, 0); |
| 5870 | msleep(150); |
| 5871 | } |
| 5872 | } |
| 5873 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 5874 | #ifdef CONFIG_PM |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5875 | static int alc269_resume(struct hda_codec *codec) |
| 5876 | { |
Kailang Yang | adcc70b | 2012-05-25 08:08:38 +0200 | [diff] [blame] | 5877 | struct alc_spec *spec = codec->spec; |
| 5878 | |
| 5879 | if (spec->codec_variant == ALC269_TYPE_ALC269VB || |
| 5880 | (alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5881 | alc269_toggle_power_output(codec, 0); |
| 5882 | msleep(150); |
| 5883 | } |
| 5884 | |
| 5885 | codec->patch_ops.init(codec); |
| 5886 | |
Kailang Yang | adcc70b | 2012-05-25 08:08:38 +0200 | [diff] [blame] | 5887 | if (spec->codec_variant == ALC269_TYPE_ALC269VB || |
| 5888 | (alc_get_coef0(codec) & 0x00ff) == 0x017) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5889 | alc269_toggle_power_output(codec, 1); |
| 5890 | msleep(200); |
| 5891 | } |
| 5892 | |
Kailang Yang | adcc70b | 2012-05-25 08:08:38 +0200 | [diff] [blame] | 5893 | if (spec->codec_variant == ALC269_TYPE_ALC269VB || |
| 5894 | (alc_get_coef0(codec) & 0x00ff) == 0x018) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5895 | alc269_toggle_power_output(codec, 1); |
| 5896 | |
| 5897 | snd_hda_codec_resume_amp(codec); |
| 5898 | snd_hda_codec_resume_cache(codec); |
| 5899 | hda_call_check_power_status(codec, 0x01); |
| 5900 | return 0; |
| 5901 | } |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 5902 | #endif /* CONFIG_PM */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5903 | |
David Henningsson | 108cc10 | 2012-07-20 10:37:25 +0200 | [diff] [blame] | 5904 | static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec, |
| 5905 | const struct alc_fixup *fix, int action) |
| 5906 | { |
| 5907 | struct alc_spec *spec = codec->spec; |
| 5908 | |
| 5909 | if (action == ALC_FIXUP_ACT_PRE_PROBE) |
| 5910 | spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; |
| 5911 | } |
| 5912 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5913 | static void alc269_fixup_hweq(struct hda_codec *codec, |
| 5914 | const struct alc_fixup *fix, int action) |
| 5915 | { |
| 5916 | int coef; |
| 5917 | |
| 5918 | if (action != ALC_FIXUP_ACT_INIT) |
| 5919 | return; |
| 5920 | coef = alc_read_coef_idx(codec, 0x1e); |
| 5921 | alc_write_coef_idx(codec, 0x1e, coef | 0x80); |
| 5922 | } |
| 5923 | |
| 5924 | static void alc271_fixup_dmic(struct hda_codec *codec, |
| 5925 | const struct alc_fixup *fix, int action) |
| 5926 | { |
| 5927 | static const struct hda_verb verbs[] = { |
| 5928 | {0x20, AC_VERB_SET_COEF_INDEX, 0x0d}, |
| 5929 | {0x20, AC_VERB_SET_PROC_COEF, 0x4000}, |
| 5930 | {} |
| 5931 | }; |
| 5932 | unsigned int cfg; |
| 5933 | |
| 5934 | if (strcmp(codec->chip_name, "ALC271X")) |
| 5935 | return; |
| 5936 | cfg = snd_hda_codec_get_pincfg(codec, 0x12); |
| 5937 | if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED) |
| 5938 | snd_hda_sequence_write(codec, verbs); |
| 5939 | } |
| 5940 | |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 5941 | static void alc269_fixup_pcm_44k(struct hda_codec *codec, |
| 5942 | const struct alc_fixup *fix, int action) |
| 5943 | { |
| 5944 | struct alc_spec *spec = codec->spec; |
| 5945 | |
| 5946 | if (action != ALC_FIXUP_ACT_PROBE) |
| 5947 | return; |
| 5948 | |
| 5949 | /* Due to a hardware problem on Lenovo Ideadpad, we need to |
| 5950 | * fix the sample rate of analog I/O to 44.1kHz |
| 5951 | */ |
| 5952 | spec->stream_analog_playback = &alc269_44k_pcm_analog_playback; |
| 5953 | spec->stream_analog_capture = &alc269_44k_pcm_analog_capture; |
| 5954 | } |
| 5955 | |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 5956 | static void alc269_fixup_stereo_dmic(struct hda_codec *codec, |
| 5957 | const struct alc_fixup *fix, int action) |
| 5958 | { |
| 5959 | int coef; |
| 5960 | |
| 5961 | if (action != ALC_FIXUP_ACT_INIT) |
| 5962 | return; |
| 5963 | /* The digital-mic unit sends PDM (differential signal) instead of |
| 5964 | * the standard PCM, thus you can't record a valid mono stream as is. |
| 5965 | * Below is a workaround specific to ALC269 to control the dmic |
| 5966 | * signal source as mono. |
| 5967 | */ |
| 5968 | coef = alc_read_coef_idx(codec, 0x07); |
| 5969 | alc_write_coef_idx(codec, 0x07, coef | 0x80); |
| 5970 | } |
| 5971 | |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5972 | static void alc269_quanta_automute(struct hda_codec *codec) |
| 5973 | { |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 5974 | update_outputs(codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5975 | |
| 5976 | snd_hda_codec_write(codec, 0x20, 0, |
| 5977 | AC_VERB_SET_COEF_INDEX, 0x0c); |
| 5978 | snd_hda_codec_write(codec, 0x20, 0, |
| 5979 | AC_VERB_SET_PROC_COEF, 0x680); |
| 5980 | |
| 5981 | snd_hda_codec_write(codec, 0x20, 0, |
| 5982 | AC_VERB_SET_COEF_INDEX, 0x0c); |
| 5983 | snd_hda_codec_write(codec, 0x20, 0, |
| 5984 | AC_VERB_SET_PROC_COEF, 0x480); |
| 5985 | } |
| 5986 | |
| 5987 | static void alc269_fixup_quanta_mute(struct hda_codec *codec, |
| 5988 | const struct alc_fixup *fix, int action) |
| 5989 | { |
| 5990 | struct alc_spec *spec = codec->spec; |
| 5991 | if (action != ALC_FIXUP_ACT_PROBE) |
| 5992 | return; |
| 5993 | spec->automute_hook = alc269_quanta_automute; |
| 5994 | } |
| 5995 | |
Takashi Iwai | 420b0fe | 2012-03-12 12:35:27 +0100 | [diff] [blame] | 5996 | /* update mute-LED according to the speaker mute state via mic2 VREF pin */ |
| 5997 | static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled) |
| 5998 | { |
| 5999 | struct hda_codec *codec = private_data; |
| 6000 | unsigned int pinval = enabled ? 0x20 : 0x24; |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 6001 | snd_hda_set_pin_ctl_cache(codec, 0x19, pinval); |
Takashi Iwai | 420b0fe | 2012-03-12 12:35:27 +0100 | [diff] [blame] | 6002 | } |
| 6003 | |
| 6004 | static void alc269_fixup_mic2_mute(struct hda_codec *codec, |
| 6005 | const struct alc_fixup *fix, int action) |
| 6006 | { |
| 6007 | struct alc_spec *spec = codec->spec; |
| 6008 | switch (action) { |
| 6009 | case ALC_FIXUP_ACT_BUILD: |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 6010 | spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook; |
Takashi Iwai | f29735c | 2012-03-13 07:55:10 +0100 | [diff] [blame] | 6011 | snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true); |
Takashi Iwai | 420b0fe | 2012-03-12 12:35:27 +0100 | [diff] [blame] | 6012 | /* fallthru */ |
| 6013 | case ALC_FIXUP_ACT_INIT: |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 6014 | snd_hda_sync_vmaster_hook(&spec->vmaster_mute); |
Takashi Iwai | 420b0fe | 2012-03-12 12:35:27 +0100 | [diff] [blame] | 6015 | break; |
| 6016 | } |
| 6017 | } |
| 6018 | |
David Henningsson | 693b613 | 2012-06-22 19:12:10 +0200 | [diff] [blame] | 6019 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6020 | enum { |
| 6021 | ALC269_FIXUP_SONY_VAIO, |
| 6022 | ALC275_FIXUP_SONY_VAIO_GPIO2, |
| 6023 | ALC269_FIXUP_DELL_M101Z, |
| 6024 | ALC269_FIXUP_SKU_IGNORE, |
| 6025 | ALC269_FIXUP_ASUS_G73JW, |
| 6026 | ALC269_FIXUP_LENOVO_EAPD, |
| 6027 | ALC275_FIXUP_SONY_HWEQ, |
| 6028 | ALC271_FIXUP_DMIC, |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 6029 | ALC269_FIXUP_PCM_44K, |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 6030 | ALC269_FIXUP_STEREO_DMIC, |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 6031 | ALC269_FIXUP_QUANTA_MUTE, |
| 6032 | ALC269_FIXUP_LIFEBOOK, |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 6033 | ALC269_FIXUP_AMIC, |
| 6034 | ALC269_FIXUP_DMIC, |
| 6035 | ALC269VB_FIXUP_AMIC, |
| 6036 | ALC269VB_FIXUP_DMIC, |
Takashi Iwai | 420b0fe | 2012-03-12 12:35:27 +0100 | [diff] [blame] | 6037 | ALC269_FIXUP_MIC2_MUTE_LED, |
David Henningsson | 693b613 | 2012-06-22 19:12:10 +0200 | [diff] [blame] | 6038 | ALC269_FIXUP_INV_DMIC, |
David Henningsson | 108cc10 | 2012-07-20 10:37:25 +0200 | [diff] [blame] | 6039 | ALC269_FIXUP_LENOVO_DOCK, |
| 6040 | ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6041 | }; |
| 6042 | |
| 6043 | static const struct alc_fixup alc269_fixups[] = { |
| 6044 | [ALC269_FIXUP_SONY_VAIO] = { |
| 6045 | .type = ALC_FIXUP_VERBS, |
| 6046 | .v.verbs = (const struct hda_verb[]) { |
| 6047 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD}, |
| 6048 | {} |
| 6049 | } |
| 6050 | }, |
| 6051 | [ALC275_FIXUP_SONY_VAIO_GPIO2] = { |
| 6052 | .type = ALC_FIXUP_VERBS, |
| 6053 | .v.verbs = (const struct hda_verb[]) { |
| 6054 | {0x01, AC_VERB_SET_GPIO_MASK, 0x04}, |
| 6055 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04}, |
| 6056 | {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, |
| 6057 | { } |
| 6058 | }, |
| 6059 | .chained = true, |
| 6060 | .chain_id = ALC269_FIXUP_SONY_VAIO |
| 6061 | }, |
| 6062 | [ALC269_FIXUP_DELL_M101Z] = { |
| 6063 | .type = ALC_FIXUP_VERBS, |
| 6064 | .v.verbs = (const struct hda_verb[]) { |
| 6065 | /* Enables internal speaker */ |
| 6066 | {0x20, AC_VERB_SET_COEF_INDEX, 13}, |
| 6067 | {0x20, AC_VERB_SET_PROC_COEF, 0x4040}, |
| 6068 | {} |
| 6069 | } |
| 6070 | }, |
| 6071 | [ALC269_FIXUP_SKU_IGNORE] = { |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 6072 | .type = ALC_FIXUP_FUNC, |
| 6073 | .v.func = alc_fixup_sku_ignore, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6074 | }, |
| 6075 | [ALC269_FIXUP_ASUS_G73JW] = { |
| 6076 | .type = ALC_FIXUP_PINS, |
| 6077 | .v.pins = (const struct alc_pincfg[]) { |
| 6078 | { 0x17, 0x99130111 }, /* subwoofer */ |
| 6079 | { } |
| 6080 | } |
| 6081 | }, |
| 6082 | [ALC269_FIXUP_LENOVO_EAPD] = { |
| 6083 | .type = ALC_FIXUP_VERBS, |
| 6084 | .v.verbs = (const struct hda_verb[]) { |
| 6085 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, |
| 6086 | {} |
| 6087 | } |
| 6088 | }, |
| 6089 | [ALC275_FIXUP_SONY_HWEQ] = { |
| 6090 | .type = ALC_FIXUP_FUNC, |
| 6091 | .v.func = alc269_fixup_hweq, |
| 6092 | .chained = true, |
| 6093 | .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2 |
| 6094 | }, |
| 6095 | [ALC271_FIXUP_DMIC] = { |
| 6096 | .type = ALC_FIXUP_FUNC, |
| 6097 | .v.func = alc271_fixup_dmic, |
| 6098 | }, |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 6099 | [ALC269_FIXUP_PCM_44K] = { |
| 6100 | .type = ALC_FIXUP_FUNC, |
| 6101 | .v.func = alc269_fixup_pcm_44k, |
| 6102 | }, |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 6103 | [ALC269_FIXUP_STEREO_DMIC] = { |
| 6104 | .type = ALC_FIXUP_FUNC, |
| 6105 | .v.func = alc269_fixup_stereo_dmic, |
| 6106 | }, |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 6107 | [ALC269_FIXUP_QUANTA_MUTE] = { |
| 6108 | .type = ALC_FIXUP_FUNC, |
| 6109 | .v.func = alc269_fixup_quanta_mute, |
| 6110 | }, |
| 6111 | [ALC269_FIXUP_LIFEBOOK] = { |
| 6112 | .type = ALC_FIXUP_PINS, |
| 6113 | .v.pins = (const struct alc_pincfg[]) { |
| 6114 | { 0x1a, 0x2101103f }, /* dock line-out */ |
| 6115 | { 0x1b, 0x23a11040 }, /* dock mic-in */ |
| 6116 | { } |
| 6117 | }, |
| 6118 | .chained = true, |
| 6119 | .chain_id = ALC269_FIXUP_QUANTA_MUTE |
| 6120 | }, |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 6121 | [ALC269_FIXUP_AMIC] = { |
| 6122 | .type = ALC_FIXUP_PINS, |
| 6123 | .v.pins = (const struct alc_pincfg[]) { |
| 6124 | { 0x14, 0x99130110 }, /* speaker */ |
| 6125 | { 0x15, 0x0121401f }, /* HP out */ |
| 6126 | { 0x18, 0x01a19c20 }, /* mic */ |
| 6127 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 6128 | { } |
| 6129 | }, |
| 6130 | }, |
| 6131 | [ALC269_FIXUP_DMIC] = { |
| 6132 | .type = ALC_FIXUP_PINS, |
| 6133 | .v.pins = (const struct alc_pincfg[]) { |
| 6134 | { 0x12, 0x99a3092f }, /* int-mic */ |
| 6135 | { 0x14, 0x99130110 }, /* speaker */ |
| 6136 | { 0x15, 0x0121401f }, /* HP out */ |
| 6137 | { 0x18, 0x01a19c20 }, /* mic */ |
| 6138 | { } |
| 6139 | }, |
| 6140 | }, |
| 6141 | [ALC269VB_FIXUP_AMIC] = { |
| 6142 | .type = ALC_FIXUP_PINS, |
| 6143 | .v.pins = (const struct alc_pincfg[]) { |
| 6144 | { 0x14, 0x99130110 }, /* speaker */ |
| 6145 | { 0x18, 0x01a19c20 }, /* mic */ |
| 6146 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 6147 | { 0x21, 0x0121401f }, /* HP out */ |
| 6148 | { } |
| 6149 | }, |
| 6150 | }, |
David Henningsson | 2267ea9 | 2012-01-03 08:45:56 +0100 | [diff] [blame] | 6151 | [ALC269VB_FIXUP_DMIC] = { |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 6152 | .type = ALC_FIXUP_PINS, |
| 6153 | .v.pins = (const struct alc_pincfg[]) { |
| 6154 | { 0x12, 0x99a3092f }, /* int-mic */ |
| 6155 | { 0x14, 0x99130110 }, /* speaker */ |
| 6156 | { 0x18, 0x01a19c20 }, /* mic */ |
| 6157 | { 0x21, 0x0121401f }, /* HP out */ |
| 6158 | { } |
| 6159 | }, |
| 6160 | }, |
Takashi Iwai | 420b0fe | 2012-03-12 12:35:27 +0100 | [diff] [blame] | 6161 | [ALC269_FIXUP_MIC2_MUTE_LED] = { |
| 6162 | .type = ALC_FIXUP_FUNC, |
| 6163 | .v.func = alc269_fixup_mic2_mute, |
| 6164 | }, |
David Henningsson | 693b613 | 2012-06-22 19:12:10 +0200 | [diff] [blame] | 6165 | [ALC269_FIXUP_INV_DMIC] = { |
| 6166 | .type = ALC_FIXUP_FUNC, |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 6167 | .v.func = alc_fixup_inv_dmic_0x12, |
David Henningsson | 693b613 | 2012-06-22 19:12:10 +0200 | [diff] [blame] | 6168 | }, |
David Henningsson | 108cc10 | 2012-07-20 10:37:25 +0200 | [diff] [blame] | 6169 | [ALC269_FIXUP_LENOVO_DOCK] = { |
| 6170 | .type = ALC_FIXUP_PINS, |
| 6171 | .v.pins = (const struct alc_pincfg[]) { |
| 6172 | { 0x19, 0x23a11040 }, /* dock mic */ |
| 6173 | { 0x1b, 0x2121103f }, /* dock headphone */ |
| 6174 | { } |
| 6175 | }, |
| 6176 | .chained = true, |
| 6177 | .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT |
| 6178 | }, |
| 6179 | [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = { |
| 6180 | .type = ALC_FIXUP_FUNC, |
| 6181 | .v.func = alc269_fixup_pincfg_no_hp_to_lineout, |
| 6182 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6183 | }; |
| 6184 | |
| 6185 | static const struct snd_pci_quirk alc269_fixup_tbl[] = { |
David Henningsson | 693b613 | 2012-06-22 19:12:10 +0200 | [diff] [blame] | 6186 | SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC), |
| 6187 | SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC), |
Takashi Iwai | 420b0fe | 2012-03-12 12:35:27 +0100 | [diff] [blame] | 6188 | SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED), |
David Henningsson | 5ac5755 | 2012-04-20 10:01:46 +0200 | [diff] [blame] | 6189 | SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC), |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 6190 | SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW), |
David Henningsson | 693b613 | 2012-06-22 19:12:10 +0200 | [diff] [blame] | 6191 | SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC), |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 6192 | SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC), |
| 6193 | SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC), |
| 6194 | SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC), |
| 6195 | SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), |
| 6196 | SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6197 | SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2), |
| 6198 | SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), |
| 6199 | SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), |
| 6200 | SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO), |
| 6201 | SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z), |
| 6202 | SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC), |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 6203 | SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6204 | SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE), |
| 6205 | SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE), |
| 6206 | SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE), |
| 6207 | SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE), |
| 6208 | SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE), |
Takashi Iwai | 707fba3 | 2012-08-02 09:04:39 +0200 | [diff] [blame] | 6209 | SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK), |
Philipp A. Mohrenweiser | 4407be6 | 2012-08-06 13:14:18 +0200 | [diff] [blame^] | 6210 | SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK), |
David Henningsson | 108cc10 | 2012-07-20 10:37:25 +0200 | [diff] [blame] | 6211 | SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK), |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 6212 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE), |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 6213 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6214 | SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD), |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 6215 | |
Takashi Iwai | a7f3eed | 2012-02-16 13:03:18 +0100 | [diff] [blame] | 6216 | #if 0 |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 6217 | /* Below is a quirk table taken from the old code. |
| 6218 | * Basically the device should work as is without the fixup table. |
| 6219 | * If BIOS doesn't give a proper info, enable the corresponding |
| 6220 | * fixup entry. |
Jesper Juhl | 7d7eb9e | 2012-04-12 22:11:25 +0200 | [diff] [blame] | 6221 | */ |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 6222 | SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A", |
| 6223 | ALC269_FIXUP_AMIC), |
| 6224 | SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC), |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 6225 | SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC), |
| 6226 | SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC), |
| 6227 | SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC), |
| 6228 | SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC), |
| 6229 | SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC), |
| 6230 | SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC), |
| 6231 | SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC), |
| 6232 | SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC), |
| 6233 | SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC), |
| 6234 | SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC), |
| 6235 | SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC), |
| 6236 | SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC), |
| 6237 | SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC), |
| 6238 | SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC), |
| 6239 | SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC), |
| 6240 | SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC), |
| 6241 | SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC), |
| 6242 | SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC), |
| 6243 | SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC), |
| 6244 | SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC), |
| 6245 | SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC), |
| 6246 | SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC), |
| 6247 | SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC), |
| 6248 | SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC), |
| 6249 | SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC), |
| 6250 | SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC), |
| 6251 | SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC), |
| 6252 | SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC), |
| 6253 | SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC), |
| 6254 | SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC), |
| 6255 | SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC), |
| 6256 | SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC), |
| 6257 | SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC), |
| 6258 | SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC), |
| 6259 | SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC), |
| 6260 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC), |
| 6261 | SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC), |
| 6262 | SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC), |
| 6263 | #endif |
| 6264 | {} |
| 6265 | }; |
| 6266 | |
| 6267 | static const struct alc_model_fixup alc269_fixup_models[] = { |
| 6268 | {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"}, |
| 6269 | {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"}, |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 6270 | {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"}, |
| 6271 | {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"}, |
| 6272 | {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"}, |
David Henningsson | 108cc10 | 2012-07-20 10:37:25 +0200 | [diff] [blame] | 6273 | {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"}, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6274 | {} |
| 6275 | }; |
| 6276 | |
| 6277 | |
Takashi Iwai | 546bb67 | 2012-03-07 08:37:19 +0100 | [diff] [blame] | 6278 | static void alc269_fill_coef(struct hda_codec *codec) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6279 | { |
Kailang Yang | 526af6e | 2012-03-07 08:25:20 +0100 | [diff] [blame] | 6280 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6281 | int val; |
| 6282 | |
Kailang Yang | 526af6e | 2012-03-07 08:25:20 +0100 | [diff] [blame] | 6283 | if (spec->codec_variant != ALC269_TYPE_ALC269VB) |
Takashi Iwai | 546bb67 | 2012-03-07 08:37:19 +0100 | [diff] [blame] | 6284 | return; |
Kailang Yang | 526af6e | 2012-03-07 08:25:20 +0100 | [diff] [blame] | 6285 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 6286 | if ((alc_get_coef0(codec) & 0x00ff) < 0x015) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6287 | alc_write_coef_idx(codec, 0xf, 0x960b); |
| 6288 | alc_write_coef_idx(codec, 0xe, 0x8817); |
| 6289 | } |
| 6290 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 6291 | if ((alc_get_coef0(codec) & 0x00ff) == 0x016) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6292 | alc_write_coef_idx(codec, 0xf, 0x960b); |
| 6293 | alc_write_coef_idx(codec, 0xe, 0x8814); |
| 6294 | } |
| 6295 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 6296 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6297 | val = alc_read_coef_idx(codec, 0x04); |
| 6298 | /* Power up output pin */ |
| 6299 | alc_write_coef_idx(codec, 0x04, val | (1<<11)); |
| 6300 | } |
| 6301 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 6302 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6303 | val = alc_read_coef_idx(codec, 0xd); |
| 6304 | if ((val & 0x0c00) >> 10 != 0x1) { |
| 6305 | /* Capless ramp up clock control */ |
| 6306 | alc_write_coef_idx(codec, 0xd, val | (1<<10)); |
| 6307 | } |
| 6308 | val = alc_read_coef_idx(codec, 0x17); |
| 6309 | if ((val & 0x01c0) >> 6 != 0x4) { |
| 6310 | /* Class D power on reset */ |
| 6311 | alc_write_coef_idx(codec, 0x17, val | (1<<7)); |
| 6312 | } |
| 6313 | } |
| 6314 | |
| 6315 | val = alc_read_coef_idx(codec, 0xd); /* Class D */ |
| 6316 | alc_write_coef_idx(codec, 0xd, val | (1<<14)); |
| 6317 | |
| 6318 | val = alc_read_coef_idx(codec, 0x4); /* HP */ |
| 6319 | alc_write_coef_idx(codec, 0x4, val | (1<<11)); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6320 | } |
| 6321 | |
| 6322 | /* |
| 6323 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6324 | static int patch_alc269(struct hda_codec *codec) |
| 6325 | { |
| 6326 | struct alc_spec *spec; |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 6327 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6328 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 6329 | err = alc_alloc_spec(codec, 0x0b); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6330 | if (err < 0) |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 6331 | return err; |
| 6332 | |
| 6333 | spec = codec->spec; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6334 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6335 | if (codec->vendor_id == 0x10ec0269) { |
| 6336 | spec->codec_variant = ALC269_TYPE_ALC269VA; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 6337 | switch (alc_get_coef0(codec) & 0x00f0) { |
| 6338 | case 0x0010: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6339 | if (codec->bus->pci->subsystem_vendor == 0x1025 && |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6340 | spec->cdefine.platform_type == 1) |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 6341 | err = alc_codec_rename(codec, "ALC271X"); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6342 | spec->codec_variant = ALC269_TYPE_ALC269VB; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 6343 | break; |
| 6344 | case 0x0020: |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6345 | if (codec->bus->pci->subsystem_vendor == 0x17aa && |
| 6346 | codec->bus->pci->subsystem_device == 0x21f3) |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 6347 | err = alc_codec_rename(codec, "ALC3202"); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6348 | spec->codec_variant = ALC269_TYPE_ALC269VC; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 6349 | break; |
Kailang Yang | adcc70b | 2012-05-25 08:08:38 +0200 | [diff] [blame] | 6350 | case 0x0030: |
| 6351 | spec->codec_variant = ALC269_TYPE_ALC269VD; |
| 6352 | break; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 6353 | default: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6354 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 6355 | } |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6356 | if (err < 0) |
| 6357 | goto error; |
Takashi Iwai | 546bb67 | 2012-03-07 08:37:19 +0100 | [diff] [blame] | 6358 | spec->init_hook = alc269_fill_coef; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6359 | alc269_fill_coef(codec); |
| 6360 | } |
| 6361 | |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 6362 | alc_pick_fixup(codec, alc269_fixup_models, |
| 6363 | alc269_fixup_tbl, alc269_fixups); |
| 6364 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6365 | |
Takashi Iwai | af741c1 | 2012-05-07 18:09:48 +0200 | [diff] [blame] | 6366 | alc_auto_parse_customize_define(codec); |
| 6367 | |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 6368 | /* automatic parse from the BIOS config */ |
| 6369 | err = alc269_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6370 | if (err < 0) |
| 6371 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6372 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6373 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 6374 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6375 | if (err < 0) |
| 6376 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6377 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6378 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6379 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6380 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 6381 | #ifdef CONFIG_PM |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6382 | codec->patch_ops.resume = alc269_resume; |
| 6383 | #endif |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6384 | spec->shutup = alc269_shutup; |
| 6385 | |
Takashi Iwai | 589876e | 2012-02-20 15:47:55 +0100 | [diff] [blame] | 6386 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 6387 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6388 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6389 | |
| 6390 | error: |
| 6391 | alc_free(codec); |
| 6392 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6393 | } |
| 6394 | |
| 6395 | /* |
| 6396 | * ALC861 |
| 6397 | */ |
| 6398 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6399 | static int alc861_parse_auto_config(struct hda_codec *codec) |
| 6400 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6401 | static const hda_nid_t alc861_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6402 | static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 }; |
| 6403 | return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6404 | } |
| 6405 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6406 | /* Pin config fixes */ |
| 6407 | enum { |
Takashi Iwai | e652f4c | 2012-02-13 11:56:25 +0100 | [diff] [blame] | 6408 | ALC861_FIXUP_FSC_AMILO_PI1505, |
| 6409 | ALC861_FIXUP_AMP_VREF_0F, |
| 6410 | ALC861_FIXUP_NO_JACK_DETECT, |
| 6411 | ALC861_FIXUP_ASUS_A6RP, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6412 | }; |
| 6413 | |
Takashi Iwai | 31150f2 | 2012-01-30 10:54:08 +0100 | [diff] [blame] | 6414 | /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */ |
| 6415 | static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec, |
| 6416 | const struct alc_fixup *fix, int action) |
| 6417 | { |
| 6418 | struct alc_spec *spec = codec->spec; |
| 6419 | unsigned int val; |
| 6420 | |
| 6421 | if (action != ALC_FIXUP_ACT_INIT) |
| 6422 | return; |
| 6423 | val = snd_hda_codec_read(codec, 0x0f, 0, |
| 6424 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 6425 | if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))) |
| 6426 | val |= AC_PINCTL_IN_EN; |
| 6427 | val |= AC_PINCTL_VREF_50; |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 6428 | snd_hda_set_pin_ctl(codec, 0x0f, val); |
Takashi Iwai | 31150f2 | 2012-01-30 10:54:08 +0100 | [diff] [blame] | 6429 | spec->keep_vref_in_automute = 1; |
| 6430 | } |
| 6431 | |
Takashi Iwai | e652f4c | 2012-02-13 11:56:25 +0100 | [diff] [blame] | 6432 | /* suppress the jack-detection */ |
| 6433 | static void alc_fixup_no_jack_detect(struct hda_codec *codec, |
| 6434 | const struct alc_fixup *fix, int action) |
| 6435 | { |
| 6436 | if (action == ALC_FIXUP_ACT_PRE_PROBE) |
| 6437 | codec->no_jack_detect = 1; |
Jesper Juhl | 7d7eb9e | 2012-04-12 22:11:25 +0200 | [diff] [blame] | 6438 | } |
Takashi Iwai | e652f4c | 2012-02-13 11:56:25 +0100 | [diff] [blame] | 6439 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6440 | static const struct alc_fixup alc861_fixups[] = { |
Takashi Iwai | e652f4c | 2012-02-13 11:56:25 +0100 | [diff] [blame] | 6441 | [ALC861_FIXUP_FSC_AMILO_PI1505] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6442 | .type = ALC_FIXUP_PINS, |
| 6443 | .v.pins = (const struct alc_pincfg[]) { |
| 6444 | { 0x0b, 0x0221101f }, /* HP */ |
| 6445 | { 0x0f, 0x90170310 }, /* speaker */ |
| 6446 | { } |
| 6447 | } |
| 6448 | }, |
Takashi Iwai | e652f4c | 2012-02-13 11:56:25 +0100 | [diff] [blame] | 6449 | [ALC861_FIXUP_AMP_VREF_0F] = { |
Takashi Iwai | 31150f2 | 2012-01-30 10:54:08 +0100 | [diff] [blame] | 6450 | .type = ALC_FIXUP_FUNC, |
| 6451 | .v.func = alc861_fixup_asus_amp_vref_0f, |
Takashi Iwai | 3b25eb6 | 2012-01-25 09:55:46 +0100 | [diff] [blame] | 6452 | }, |
Takashi Iwai | e652f4c | 2012-02-13 11:56:25 +0100 | [diff] [blame] | 6453 | [ALC861_FIXUP_NO_JACK_DETECT] = { |
| 6454 | .type = ALC_FIXUP_FUNC, |
| 6455 | .v.func = alc_fixup_no_jack_detect, |
| 6456 | }, |
| 6457 | [ALC861_FIXUP_ASUS_A6RP] = { |
| 6458 | .type = ALC_FIXUP_FUNC, |
| 6459 | .v.func = alc861_fixup_asus_amp_vref_0f, |
| 6460 | .chained = true, |
| 6461 | .chain_id = ALC861_FIXUP_NO_JACK_DETECT, |
| 6462 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6463 | }; |
| 6464 | |
| 6465 | static const struct snd_pci_quirk alc861_fixup_tbl[] = { |
Takashi Iwai | e652f4c | 2012-02-13 11:56:25 +0100 | [diff] [blame] | 6466 | SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP), |
| 6467 | SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F), |
| 6468 | SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT), |
| 6469 | SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F), |
| 6470 | SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F), |
| 6471 | SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6472 | {} |
| 6473 | }; |
| 6474 | |
| 6475 | /* |
| 6476 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6477 | static int patch_alc861(struct hda_codec *codec) |
| 6478 | { |
| 6479 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6480 | int err; |
| 6481 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 6482 | err = alc_alloc_spec(codec, 0x15); |
| 6483 | if (err < 0) |
| 6484 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6485 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 6486 | spec = codec->spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6487 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 6488 | alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); |
| 6489 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6490 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 6491 | /* automatic parse from the BIOS config */ |
| 6492 | err = alc861_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6493 | if (err < 0) |
| 6494 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6495 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6496 | if (!spec->no_analog) { |
| 6497 | err = snd_hda_attach_beep_device(codec, 0x23); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6498 | if (err < 0) |
| 6499 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6500 | set_beep_amp(spec, 0x23, 0, HDA_OUTPUT); |
| 6501 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6502 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6503 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6504 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 6505 | spec->power_hook = alc_power_eapd; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6506 | #endif |
| 6507 | |
Takashi Iwai | 589876e | 2012-02-20 15:47:55 +0100 | [diff] [blame] | 6508 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 6509 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6510 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6511 | |
| 6512 | error: |
| 6513 | alc_free(codec); |
| 6514 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6515 | } |
| 6516 | |
| 6517 | /* |
| 6518 | * ALC861-VD support |
| 6519 | * |
| 6520 | * Based on ALC882 |
| 6521 | * |
| 6522 | * In addition, an independent DAC |
| 6523 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6524 | static int alc861vd_parse_auto_config(struct hda_codec *codec) |
| 6525 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6526 | static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6527 | static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 6528 | return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6529 | } |
| 6530 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6531 | enum { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 6532 | ALC660VD_FIX_ASUS_GPIO1, |
| 6533 | ALC861VD_FIX_DALLAS, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6534 | }; |
| 6535 | |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 6536 | /* exclude VREF80 */ |
| 6537 | static void alc861vd_fixup_dallas(struct hda_codec *codec, |
| 6538 | const struct alc_fixup *fix, int action) |
| 6539 | { |
| 6540 | if (action == ALC_FIXUP_ACT_PRE_PROBE) { |
| 6541 | snd_hda_override_pin_caps(codec, 0x18, 0x00001714); |
| 6542 | snd_hda_override_pin_caps(codec, 0x19, 0x0000171c); |
| 6543 | } |
| 6544 | } |
| 6545 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6546 | static const struct alc_fixup alc861vd_fixups[] = { |
| 6547 | [ALC660VD_FIX_ASUS_GPIO1] = { |
| 6548 | .type = ALC_FIXUP_VERBS, |
| 6549 | .v.verbs = (const struct hda_verb[]) { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 6550 | /* reset GPIO1 */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6551 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, |
| 6552 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, |
| 6553 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, |
| 6554 | { } |
| 6555 | } |
| 6556 | }, |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 6557 | [ALC861VD_FIX_DALLAS] = { |
| 6558 | .type = ALC_FIXUP_FUNC, |
| 6559 | .v.func = alc861vd_fixup_dallas, |
| 6560 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6561 | }; |
| 6562 | |
| 6563 | static const struct snd_pci_quirk alc861vd_fixup_tbl[] = { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 6564 | SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6565 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1), |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 6566 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6567 | {} |
| 6568 | }; |
| 6569 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6570 | /* |
| 6571 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6572 | static int patch_alc861vd(struct hda_codec *codec) |
| 6573 | { |
| 6574 | struct alc_spec *spec; |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 6575 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6576 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 6577 | err = alc_alloc_spec(codec, 0x0b); |
| 6578 | if (err < 0) |
| 6579 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6580 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 6581 | spec = codec->spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6582 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 6583 | alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); |
| 6584 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6585 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 6586 | /* automatic parse from the BIOS config */ |
| 6587 | err = alc861vd_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6588 | if (err < 0) |
| 6589 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6590 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6591 | if (!spec->no_analog) { |
| 6592 | err = snd_hda_attach_beep_device(codec, 0x23); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6593 | if (err < 0) |
| 6594 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6595 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 6596 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6597 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6598 | codec->patch_ops = alc_patch_ops; |
| 6599 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6600 | spec->shutup = alc_eapd_shutup; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6601 | |
Takashi Iwai | 589876e | 2012-02-20 15:47:55 +0100 | [diff] [blame] | 6602 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 6603 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6604 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6605 | |
| 6606 | error: |
| 6607 | alc_free(codec); |
| 6608 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6609 | } |
| 6610 | |
| 6611 | /* |
| 6612 | * ALC662 support |
| 6613 | * |
| 6614 | * ALC662 is almost identical with ALC880 but has cleaner and more flexible |
| 6615 | * configuration. Each pin widget can choose any input DACs and a mixer. |
| 6616 | * Each ADC is connected from a mixer of all inputs. This makes possible |
| 6617 | * 6-channel independent captures. |
| 6618 | * |
| 6619 | * In addition, an independent DAC for the multi-playback (not used in this |
| 6620 | * driver yet). |
| 6621 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6622 | |
| 6623 | /* |
| 6624 | * BIOS auto configuration |
| 6625 | */ |
| 6626 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6627 | static int alc662_parse_auto_config(struct hda_codec *codec) |
| 6628 | { |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 6629 | static const hda_nid_t alc662_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6630 | static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 }; |
| 6631 | static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 6632 | const hda_nid_t *ssids; |
Takashi Iwai | ee979a14 | 2008-09-02 15:42:20 +0200 | [diff] [blame] | 6633 | |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 6634 | if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 || |
| 6635 | codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670) |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6636 | ssids = alc663_ssids; |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 6637 | else |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6638 | ssids = alc662_ssids; |
| 6639 | return alc_parse_auto_config(codec, alc662_ignore, ssids); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6640 | } |
| 6641 | |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 6642 | static void alc272_fixup_mario(struct hda_codec *codec, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 6643 | const struct alc_fixup *fix, int action) |
Takashi Iwai | 6fc398c | 2011-01-13 14:36:37 +0100 | [diff] [blame] | 6644 | { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 6645 | if (action != ALC_FIXUP_ACT_PROBE) |
Takashi Iwai | 6fc398c | 2011-01-13 14:36:37 +0100 | [diff] [blame] | 6646 | return; |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 6647 | if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT, |
| 6648 | (0x3b << AC_AMPCAP_OFFSET_SHIFT) | |
| 6649 | (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 6650 | (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 6651 | (0 << AC_AMPCAP_MUTE_SHIFT))) |
| 6652 | printk(KERN_WARNING |
| 6653 | "hda_codec: failed to override amp caps for NID 0x2\n"); |
| 6654 | } |
| 6655 | |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6656 | enum { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 6657 | ALC662_FIXUP_ASPIRE, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6658 | ALC662_FIXUP_IDEAPAD, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 6659 | ALC272_FIXUP_MARIO, |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 6660 | ALC662_FIXUP_CZC_P10T, |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 6661 | ALC662_FIXUP_SKU_IGNORE, |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 6662 | ALC662_FIXUP_HP_RP5800, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6663 | ALC662_FIXUP_ASUS_MODE1, |
| 6664 | ALC662_FIXUP_ASUS_MODE2, |
| 6665 | ALC662_FIXUP_ASUS_MODE3, |
| 6666 | ALC662_FIXUP_ASUS_MODE4, |
| 6667 | ALC662_FIXUP_ASUS_MODE5, |
| 6668 | ALC662_FIXUP_ASUS_MODE6, |
| 6669 | ALC662_FIXUP_ASUS_MODE7, |
| 6670 | ALC662_FIXUP_ASUS_MODE8, |
Takashi Iwai | 1565cc3 | 2012-02-13 12:03:25 +0100 | [diff] [blame] | 6671 | ALC662_FIXUP_NO_JACK_DETECT, |
David Henningsson | edfe3bf | 2012-06-12 13:15:12 +0200 | [diff] [blame] | 6672 | ALC662_FIXUP_ZOTAC_Z68, |
Takashi Iwai | 125821a | 2012-06-22 14:30:29 +0200 | [diff] [blame] | 6673 | ALC662_FIXUP_INV_DMIC, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6674 | }; |
| 6675 | |
| 6676 | static const struct alc_fixup alc662_fixups[] = { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 6677 | [ALC662_FIXUP_ASPIRE] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 6678 | .type = ALC_FIXUP_PINS, |
| 6679 | .v.pins = (const struct alc_pincfg[]) { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 6680 | { 0x15, 0x99130112 }, /* subwoofer */ |
| 6681 | { } |
| 6682 | } |
| 6683 | }, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6684 | [ALC662_FIXUP_IDEAPAD] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 6685 | .type = ALC_FIXUP_PINS, |
| 6686 | .v.pins = (const struct alc_pincfg[]) { |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6687 | { 0x17, 0x99130112 }, /* subwoofer */ |
| 6688 | { } |
| 6689 | } |
| 6690 | }, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 6691 | [ALC272_FIXUP_MARIO] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 6692 | .type = ALC_FIXUP_FUNC, |
| 6693 | .v.func = alc272_fixup_mario, |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 6694 | }, |
| 6695 | [ALC662_FIXUP_CZC_P10T] = { |
| 6696 | .type = ALC_FIXUP_VERBS, |
| 6697 | .v.verbs = (const struct hda_verb[]) { |
| 6698 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, |
| 6699 | {} |
| 6700 | } |
| 6701 | }, |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 6702 | [ALC662_FIXUP_SKU_IGNORE] = { |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 6703 | .type = ALC_FIXUP_FUNC, |
| 6704 | .v.func = alc_fixup_sku_ignore, |
Takashi Iwai | c6b3587 | 2011-03-28 12:05:31 +0200 | [diff] [blame] | 6705 | }, |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 6706 | [ALC662_FIXUP_HP_RP5800] = { |
| 6707 | .type = ALC_FIXUP_PINS, |
| 6708 | .v.pins = (const struct alc_pincfg[]) { |
| 6709 | { 0x14, 0x0221201f }, /* HP out */ |
| 6710 | { } |
| 6711 | }, |
| 6712 | .chained = true, |
| 6713 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6714 | }, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6715 | [ALC662_FIXUP_ASUS_MODE1] = { |
| 6716 | .type = ALC_FIXUP_PINS, |
| 6717 | .v.pins = (const struct alc_pincfg[]) { |
| 6718 | { 0x14, 0x99130110 }, /* speaker */ |
| 6719 | { 0x18, 0x01a19c20 }, /* mic */ |
| 6720 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 6721 | { 0x21, 0x0121401f }, /* HP out */ |
| 6722 | { } |
| 6723 | }, |
| 6724 | .chained = true, |
| 6725 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6726 | }, |
| 6727 | [ALC662_FIXUP_ASUS_MODE2] = { |
Takashi Iwai | 2996bdb | 2011-08-18 16:02:24 +0200 | [diff] [blame] | 6728 | .type = ALC_FIXUP_PINS, |
| 6729 | .v.pins = (const struct alc_pincfg[]) { |
| 6730 | { 0x14, 0x99130110 }, /* speaker */ |
| 6731 | { 0x18, 0x01a19820 }, /* mic */ |
| 6732 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 6733 | { 0x1b, 0x0121401f }, /* HP out */ |
| 6734 | { } |
| 6735 | }, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6736 | .chained = true, |
| 6737 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6738 | }, |
| 6739 | [ALC662_FIXUP_ASUS_MODE3] = { |
| 6740 | .type = ALC_FIXUP_PINS, |
| 6741 | .v.pins = (const struct alc_pincfg[]) { |
| 6742 | { 0x14, 0x99130110 }, /* speaker */ |
| 6743 | { 0x15, 0x0121441f }, /* HP */ |
| 6744 | { 0x18, 0x01a19840 }, /* mic */ |
| 6745 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 6746 | { 0x21, 0x01211420 }, /* HP2 */ |
| 6747 | { } |
| 6748 | }, |
| 6749 | .chained = true, |
| 6750 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6751 | }, |
| 6752 | [ALC662_FIXUP_ASUS_MODE4] = { |
| 6753 | .type = ALC_FIXUP_PINS, |
| 6754 | .v.pins = (const struct alc_pincfg[]) { |
| 6755 | { 0x14, 0x99130110 }, /* speaker */ |
| 6756 | { 0x16, 0x99130111 }, /* speaker */ |
| 6757 | { 0x18, 0x01a19840 }, /* mic */ |
| 6758 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 6759 | { 0x21, 0x0121441f }, /* HP */ |
| 6760 | { } |
| 6761 | }, |
| 6762 | .chained = true, |
| 6763 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6764 | }, |
| 6765 | [ALC662_FIXUP_ASUS_MODE5] = { |
| 6766 | .type = ALC_FIXUP_PINS, |
| 6767 | .v.pins = (const struct alc_pincfg[]) { |
| 6768 | { 0x14, 0x99130110 }, /* speaker */ |
| 6769 | { 0x15, 0x0121441f }, /* HP */ |
| 6770 | { 0x16, 0x99130111 }, /* speaker */ |
| 6771 | { 0x18, 0x01a19840 }, /* mic */ |
| 6772 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 6773 | { } |
| 6774 | }, |
| 6775 | .chained = true, |
| 6776 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6777 | }, |
| 6778 | [ALC662_FIXUP_ASUS_MODE6] = { |
| 6779 | .type = ALC_FIXUP_PINS, |
| 6780 | .v.pins = (const struct alc_pincfg[]) { |
| 6781 | { 0x14, 0x99130110 }, /* speaker */ |
| 6782 | { 0x15, 0x01211420 }, /* HP2 */ |
| 6783 | { 0x18, 0x01a19840 }, /* mic */ |
| 6784 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 6785 | { 0x1b, 0x0121441f }, /* HP */ |
| 6786 | { } |
| 6787 | }, |
| 6788 | .chained = true, |
| 6789 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6790 | }, |
| 6791 | [ALC662_FIXUP_ASUS_MODE7] = { |
| 6792 | .type = ALC_FIXUP_PINS, |
| 6793 | .v.pins = (const struct alc_pincfg[]) { |
| 6794 | { 0x14, 0x99130110 }, /* speaker */ |
| 6795 | { 0x17, 0x99130111 }, /* speaker */ |
| 6796 | { 0x18, 0x01a19840 }, /* mic */ |
| 6797 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 6798 | { 0x1b, 0x01214020 }, /* HP */ |
| 6799 | { 0x21, 0x0121401f }, /* HP */ |
| 6800 | { } |
| 6801 | }, |
| 6802 | .chained = true, |
| 6803 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6804 | }, |
| 6805 | [ALC662_FIXUP_ASUS_MODE8] = { |
| 6806 | .type = ALC_FIXUP_PINS, |
| 6807 | .v.pins = (const struct alc_pincfg[]) { |
| 6808 | { 0x14, 0x99130110 }, /* speaker */ |
| 6809 | { 0x12, 0x99a30970 }, /* int-mic */ |
| 6810 | { 0x15, 0x01214020 }, /* HP */ |
| 6811 | { 0x17, 0x99130111 }, /* speaker */ |
| 6812 | { 0x18, 0x01a19840 }, /* mic */ |
| 6813 | { 0x21, 0x0121401f }, /* HP */ |
| 6814 | { } |
| 6815 | }, |
| 6816 | .chained = true, |
| 6817 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
Takashi Iwai | 2996bdb | 2011-08-18 16:02:24 +0200 | [diff] [blame] | 6818 | }, |
Takashi Iwai | 1565cc3 | 2012-02-13 12:03:25 +0100 | [diff] [blame] | 6819 | [ALC662_FIXUP_NO_JACK_DETECT] = { |
| 6820 | .type = ALC_FIXUP_FUNC, |
| 6821 | .v.func = alc_fixup_no_jack_detect, |
| 6822 | }, |
David Henningsson | edfe3bf | 2012-06-12 13:15:12 +0200 | [diff] [blame] | 6823 | [ALC662_FIXUP_ZOTAC_Z68] = { |
| 6824 | .type = ALC_FIXUP_PINS, |
| 6825 | .v.pins = (const struct alc_pincfg[]) { |
| 6826 | { 0x1b, 0x02214020 }, /* Front HP */ |
| 6827 | { } |
| 6828 | } |
| 6829 | }, |
Takashi Iwai | 125821a | 2012-06-22 14:30:29 +0200 | [diff] [blame] | 6830 | [ALC662_FIXUP_INV_DMIC] = { |
| 6831 | .type = ALC_FIXUP_FUNC, |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 6832 | .v.func = alc_fixup_inv_dmic_0x12, |
Takashi Iwai | 125821a | 2012-06-22 14:30:29 +0200 | [diff] [blame] | 6833 | }, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6834 | }; |
| 6835 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 6836 | static const struct snd_pci_quirk alc662_fixup_tbl[] = { |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6837 | SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2), |
David Henningsson | a6c47a8 | 2011-02-10 15:39:19 +0100 | [diff] [blame] | 6838 | SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE), |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 6839 | SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE), |
Takashi Iwai | 125821a | 2012-06-22 14:30:29 +0200 | [diff] [blame] | 6840 | SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC), |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 6841 | SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE), |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 6842 | SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), |
Takashi Iwai | 1565cc3 | 2012-02-13 12:03:25 +0100 | [diff] [blame] | 6843 | SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT), |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6844 | SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2), |
Daniel T Chen | a0e90ac | 2010-11-20 10:20:35 -0500 | [diff] [blame] | 6845 | SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD), |
Valentine Sinitsyn | d411858 | 2010-10-01 22:24:08 +0600 | [diff] [blame] | 6846 | SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD), |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6847 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD), |
David Henningsson | edfe3bf | 2012-06-12 13:15:12 +0200 | [diff] [blame] | 6848 | SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68), |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 6849 | SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T), |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6850 | |
| 6851 | #if 0 |
| 6852 | /* Below is a quirk table taken from the old code. |
| 6853 | * Basically the device should work as is without the fixup table. |
| 6854 | * If BIOS doesn't give a proper info, enable the corresponding |
| 6855 | * fixup entry. |
Jesper Juhl | 7d7eb9e | 2012-04-12 22:11:25 +0200 | [diff] [blame] | 6856 | */ |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6857 | SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1), |
| 6858 | SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3), |
| 6859 | SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1), |
| 6860 | SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3), |
| 6861 | SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 6862 | SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6863 | SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 6864 | SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1), |
| 6865 | SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1), |
| 6866 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6867 | SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7), |
| 6868 | SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7), |
| 6869 | SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8), |
| 6870 | SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3), |
| 6871 | SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1), |
| 6872 | SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6873 | SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2), |
| 6874 | SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1), |
| 6875 | SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6876 | SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 6877 | SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 6878 | SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6879 | SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1), |
| 6880 | SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3), |
| 6881 | SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2), |
| 6882 | SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6883 | SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5), |
| 6884 | SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 6885 | SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6886 | SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1), |
| 6887 | SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6888 | SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6889 | SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3), |
| 6890 | SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3), |
| 6891 | SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1), |
| 6892 | SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1), |
| 6893 | SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1), |
| 6894 | SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1), |
| 6895 | SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1), |
| 6896 | SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6897 | SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2), |
| 6898 | SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1), |
| 6899 | SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 6900 | SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3), |
| 6901 | SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1), |
| 6902 | SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1), |
| 6903 | SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1), |
| 6904 | SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2), |
| 6905 | SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 6906 | SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4), |
| 6907 | #endif |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6908 | {} |
| 6909 | }; |
| 6910 | |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 6911 | static const struct alc_model_fixup alc662_fixup_models[] = { |
| 6912 | {.id = ALC272_FIXUP_MARIO, .name = "mario"}, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6913 | {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"}, |
| 6914 | {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"}, |
| 6915 | {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"}, |
| 6916 | {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"}, |
| 6917 | {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"}, |
| 6918 | {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"}, |
| 6919 | {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"}, |
| 6920 | {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"}, |
Takashi Iwai | 6e72aa5 | 2012-06-25 10:52:25 +0200 | [diff] [blame] | 6921 | {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"}, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 6922 | {} |
| 6923 | }; |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6924 | |
Kailang Yang | 8663ff7 | 2012-06-29 09:35:52 +0200 | [diff] [blame] | 6925 | static void alc662_fill_coef(struct hda_codec *codec) |
| 6926 | { |
| 6927 | int val, coef; |
| 6928 | |
| 6929 | coef = alc_get_coef0(codec); |
| 6930 | |
| 6931 | switch (codec->vendor_id) { |
| 6932 | case 0x10ec0662: |
| 6933 | if ((coef & 0x00f0) == 0x0030) { |
| 6934 | val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */ |
| 6935 | alc_write_coef_idx(codec, 0x4, val & ~(1<<10)); |
| 6936 | } |
| 6937 | break; |
| 6938 | case 0x10ec0272: |
| 6939 | case 0x10ec0273: |
| 6940 | case 0x10ec0663: |
| 6941 | case 0x10ec0665: |
| 6942 | case 0x10ec0670: |
| 6943 | case 0x10ec0671: |
| 6944 | case 0x10ec0672: |
| 6945 | val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */ |
| 6946 | alc_write_coef_idx(codec, 0xd, val | (1<<14)); |
| 6947 | break; |
| 6948 | } |
| 6949 | } |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6950 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6951 | /* |
| 6952 | */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6953 | static int patch_alc662(struct hda_codec *codec) |
| 6954 | { |
| 6955 | struct alc_spec *spec; |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 6956 | int err; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6957 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 6958 | err = alc_alloc_spec(codec, 0x0b); |
| 6959 | if (err < 0) |
| 6960 | return err; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6961 | |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 6962 | spec = codec->spec; |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 6963 | |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6964 | /* handle multiple HPs as is */ |
| 6965 | spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; |
| 6966 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 6967 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
| 6968 | |
Kailang Yang | 8663ff7 | 2012-06-29 09:35:52 +0200 | [diff] [blame] | 6969 | spec->init_hook = alc662_fill_coef; |
| 6970 | alc662_fill_coef(codec); |
| 6971 | |
Takashi Iwai | 8e5a050 | 2012-06-21 15:49:33 +0200 | [diff] [blame] | 6972 | alc_pick_fixup(codec, alc662_fixup_models, |
| 6973 | alc662_fixup_tbl, alc662_fixups); |
| 6974 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 6975 | |
| 6976 | alc_auto_parse_customize_define(codec); |
| 6977 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 6978 | if ((alc_get_coef0(codec) & (1 << 14)) && |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6979 | codec->bus->pci->subsystem_vendor == 0x1025 && |
| 6980 | spec->cdefine.platform_type == 1) { |
| 6981 | if (alc_codec_rename(codec, "ALC272X") < 0) |
| 6982 | goto error; |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 6983 | } |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 6984 | |
Takashi Iwai | b9c5106 | 2011-08-24 18:08:07 +0200 | [diff] [blame] | 6985 | /* automatic parse from the BIOS config */ |
| 6986 | err = alc662_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6987 | if (err < 0) |
| 6988 | goto error; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6989 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6990 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 6991 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6992 | if (err < 0) |
| 6993 | goto error; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 6994 | switch (codec->vendor_id) { |
| 6995 | case 0x10ec0662: |
| 6996 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 6997 | break; |
| 6998 | case 0x10ec0272: |
| 6999 | case 0x10ec0663: |
| 7000 | case 0x10ec0665: |
| 7001 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
| 7002 | break; |
| 7003 | case 0x10ec0273: |
| 7004 | set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT); |
| 7005 | break; |
| 7006 | } |
Kailang Yang | cec27c8 | 2010-02-04 14:18:18 +0100 | [diff] [blame] | 7007 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 7008 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 7009 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 7010 | spec->shutup = alc_eapd_shutup; |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 7011 | |
Takashi Iwai | 589876e | 2012-02-20 15:47:55 +0100 | [diff] [blame] | 7012 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 7013 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 7014 | return 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 7015 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 7016 | error: |
| 7017 | alc_free(codec); |
| 7018 | return err; |
Kailang Yang | b478b99 | 2011-05-18 11:51:15 +0200 | [diff] [blame] | 7019 | } |
| 7020 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 7021 | /* |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 7022 | * ALC680 support |
| 7023 | */ |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 7024 | |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 7025 | static int alc680_parse_auto_config(struct hda_codec *codec) |
| 7026 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 7027 | return alc_parse_auto_config(codec, NULL, NULL); |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 7028 | } |
| 7029 | |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 7030 | /* |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 7031 | */ |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 7032 | static int patch_alc680(struct hda_codec *codec) |
| 7033 | { |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 7034 | int err; |
| 7035 | |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 7036 | /* ALC680 has no aa-loopback mixer */ |
Takashi Iwai | 3de9517 | 2012-05-07 18:03:15 +0200 | [diff] [blame] | 7037 | err = alc_alloc_spec(codec, 0); |
| 7038 | if (err < 0) |
| 7039 | return err; |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 7040 | |
Takashi Iwai | 1ebec5f | 2011-08-15 13:21:48 +0200 | [diff] [blame] | 7041 | /* automatic parse from the BIOS config */ |
| 7042 | err = alc680_parse_auto_config(codec); |
| 7043 | if (err < 0) { |
| 7044 | alc_free(codec); |
| 7045 | return err; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 7046 | } |
| 7047 | |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 7048 | codec->patch_ops = alc_patch_ops; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 7049 | |
| 7050 | return 0; |
| 7051 | } |
| 7052 | |
| 7053 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7054 | * patch entries |
| 7055 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 7056 | static const struct hda_codec_preset snd_hda_preset_realtek[] = { |
Kailang Yang | 296f033 | 2011-05-18 11:52:36 +0200 | [diff] [blame] | 7057 | { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7058 | { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 }, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 7059 | { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 }, |
Kailang Yang | f6a9224 | 2007-12-13 16:52:54 +0100 | [diff] [blame] | 7060 | { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 }, |
Kailang Yang | a361d84 | 2007-06-05 12:30:55 +0200 | [diff] [blame] | 7061 | { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 }, |
Kailang Yang | f6a9224 | 2007-12-13 16:52:54 +0100 | [diff] [blame] | 7062 | { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 }, |
Kailang Yang | ebb83ee | 2009-12-17 12:23:00 +0100 | [diff] [blame] | 7063 | { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 }, |
Kailang Yang | 01afd41 | 2008-10-15 11:22:09 +0200 | [diff] [blame] | 7064 | { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 }, |
Kailang Yang | ebb83ee | 2009-12-17 12:23:00 +0100 | [diff] [blame] | 7065 | { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 }, |
Kailang Yang | 296f033 | 2011-05-18 11:52:36 +0200 | [diff] [blame] | 7066 | { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 }, |
David Henningsson | befae82 | 2012-06-25 19:49:28 +0200 | [diff] [blame] | 7067 | { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 }, |
David Henningsson | 4e01ec6 | 2012-07-18 07:38:46 +0200 | [diff] [blame] | 7068 | { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 7069 | { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660", |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 7070 | .patch = patch_alc861 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 7071 | { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd }, |
| 7072 | { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 }, |
| 7073 | { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd }, |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 7074 | { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 7075 | .patch = patch_alc882 }, |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 7076 | { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1", |
| 7077 | .patch = patch_alc662 }, |
David Henningsson | cc667a7 | 2011-10-18 14:07:51 +0200 | [diff] [blame] | 7078 | { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3", |
| 7079 | .patch = patch_alc662 }, |
Kailang Yang | 6dda9f4 | 2008-05-27 12:05:31 +0200 | [diff] [blame] | 7080 | { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 }, |
Kailang Yang | cec27c8 | 2010-02-04 14:18:18 +0100 | [diff] [blame] | 7081 | { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 }, |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 7082 | { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 }, |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 7083 | { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 7084 | { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7085 | { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 7086 | { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 }, |
Clive Messer | 669faba | 2008-09-30 15:49:13 +0200 | [diff] [blame] | 7087 | { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 7088 | .patch = patch_alc882 }, |
Takashi Iwai | cb308f9 | 2008-04-16 14:13:29 +0200 | [diff] [blame] | 7089 | { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 7090 | .patch = patch_alc882 }, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 7091 | { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 7092 | { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 }, |
Kailang Yang | 4442608 | 2008-10-15 11:18:05 +0200 | [diff] [blame] | 7093 | { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 7094 | .patch = patch_alc882 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 7095 | { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 }, |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 7096 | { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 }, |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 7097 | { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 7098 | { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7099 | {} /* terminator */ |
| 7100 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 7101 | |
| 7102 | MODULE_ALIAS("snd-hda-codec-id:10ec*"); |
| 7103 | |
| 7104 | MODULE_LICENSE("GPL"); |
| 7105 | MODULE_DESCRIPTION("Realtek HD-audio codec"); |
| 7106 | |
| 7107 | static struct hda_codec_preset_list realtek_list = { |
| 7108 | .preset = snd_hda_preset_realtek, |
| 7109 | .owner = THIS_MODULE, |
| 7110 | }; |
| 7111 | |
| 7112 | static int __init patch_realtek_init(void) |
| 7113 | { |
| 7114 | return snd_hda_add_codec_preset(&realtek_list); |
| 7115 | } |
| 7116 | |
| 7117 | static void __exit patch_realtek_exit(void) |
| 7118 | { |
| 7119 | snd_hda_delete_codec_preset(&realtek_list); |
| 7120 | } |
| 7121 | |
| 7122 | module_init(patch_realtek_init) |
| 7123 | module_exit(patch_realtek_exit) |