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 | 7cf51e48 | 2006-02-09 12:01:26 +0100 | [diff] [blame] | 9 | * Jonathan Woithe <jwoithe@physics.adelaide.edu.au> |
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> |
| 30 | #include <sound/core.h> |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 31 | #include <sound/jack.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include "hda_codec.h" |
| 33 | #include "hda_local.h" |
Kusanagi Kouichi | 680cd53 | 2009-02-05 00:00:58 +0900 | [diff] [blame] | 34 | #include "hda_beep.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 36 | /* unsol event tags */ |
| 37 | #define ALC_FRONT_EVENT 0x01 |
| 38 | #define ALC_DCVOL_EVENT 0x02 |
| 39 | #define ALC_HP_EVENT 0x04 |
| 40 | #define ALC_MIC_EVENT 0x08 |
Takashi Iwai | d4a86d8 | 2010-06-23 17:51:26 +0200 | [diff] [blame] | 41 | |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 42 | /* for GPIO Poll */ |
| 43 | #define GPIO_MASK 0x03 |
| 44 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 45 | /* extra amp-initialization sequence types */ |
| 46 | enum { |
| 47 | ALC_INIT_NONE, |
| 48 | ALC_INIT_DEFAULT, |
| 49 | ALC_INIT_GPIO1, |
| 50 | ALC_INIT_GPIO2, |
| 51 | ALC_INIT_GPIO3, |
| 52 | }; |
| 53 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 54 | struct alc_customize_define { |
| 55 | unsigned int sku_cfg; |
| 56 | unsigned char port_connectivity; |
| 57 | unsigned char check_sum; |
| 58 | unsigned char customization; |
| 59 | unsigned char external_amp; |
| 60 | unsigned int enable_pcbeep:1; |
| 61 | unsigned int platform_type:1; |
| 62 | unsigned int swap:1; |
| 63 | unsigned int override:1; |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 64 | 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] | 65 | }; |
| 66 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 67 | struct alc_fixup; |
| 68 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 69 | struct alc_multi_io { |
| 70 | hda_nid_t pin; /* multi-io widget pin NID */ |
| 71 | hda_nid_t dac; /* DAC to be connected */ |
| 72 | unsigned int ctl_in; /* cached input-pin control value */ |
| 73 | }; |
| 74 | |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 75 | enum { |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 76 | ALC_AUTOMUTE_PIN, /* change the pin control */ |
| 77 | ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */ |
| 78 | ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */ |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 79 | }; |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | struct alc_spec { |
| 82 | /* codec parameterization */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 83 | const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | unsigned int num_mixers; |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 85 | const struct snd_kcontrol_new *cap_mixer; /* capture mixer */ |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 86 | unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Takashi Iwai | 2d9c648 | 2009-10-13 08:06:55 +0200 | [diff] [blame] | 88 | const struct hda_verb *init_verbs[10]; /* initialization verbs |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 89 | * don't forget NULL |
| 90 | * termination! |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 91 | */ |
| 92 | unsigned int num_init_verbs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Takashi Iwai | aa563af | 2009-07-31 10:05:11 +0200 | [diff] [blame] | 94 | char stream_name_analog[32]; /* analog PCM stream */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 95 | const struct hda_pcm_stream *stream_analog_playback; |
| 96 | const struct hda_pcm_stream *stream_analog_capture; |
| 97 | const struct hda_pcm_stream *stream_analog_alt_playback; |
| 98 | const struct hda_pcm_stream *stream_analog_alt_capture; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Takashi Iwai | aa563af | 2009-07-31 10:05:11 +0200 | [diff] [blame] | 100 | char stream_name_digital[32]; /* digital PCM stream */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 101 | const struct hda_pcm_stream *stream_digital_playback; |
| 102 | const struct hda_pcm_stream *stream_digital_capture; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | /* playback */ |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 105 | struct hda_multi_out multiout; /* playback set-up |
| 106 | * max_channels, dacs must be set |
| 107 | * dig_out_nid and hp_nid are optional |
| 108 | */ |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 109 | hda_nid_t alt_dac_nid; |
Takashi Iwai | 6a05ac4 | 2009-02-13 11:19:09 +0100 | [diff] [blame] | 110 | hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */ |
Takashi Iwai | 8c44198 | 2009-01-20 18:30:20 +0100 | [diff] [blame] | 111 | int dig_out_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | /* capture */ |
| 114 | unsigned int num_adc_nids; |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 115 | const hda_nid_t *adc_nids; |
| 116 | const hda_nid_t *capsrc_nids; |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 117 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 118 | hda_nid_t mixer_nid; /* analog-mixer NID */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 120 | /* capture setup for dynamic dual-adc switch */ |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 121 | hda_nid_t cur_adc; |
| 122 | unsigned int cur_adc_stream_tag; |
| 123 | unsigned int cur_adc_format; |
| 124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | /* capture source */ |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 126 | unsigned int num_mux_defs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | const struct hda_input_mux *input_mux; |
| 128 | unsigned int cur_mux[3]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 129 | hda_nid_t ext_mic_pin; |
| 130 | hda_nid_t dock_mic_pin; |
| 131 | hda_nid_t int_mic_pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | /* channel model */ |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 134 | const struct hda_channel_mode *channel_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | int num_channel_mode; |
Takashi Iwai | 4e195a7 | 2006-07-28 14:47:34 +0200 | [diff] [blame] | 136 | int need_dac_fix; |
Hector Martin | 3b315d7 | 2009-06-02 10:54:19 +0200 | [diff] [blame] | 137 | int const_channel_count; |
| 138 | int ext_channel_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | /* PCM information */ |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 141 | struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */ |
Takashi Iwai | 41e41f1 | 2005-06-08 14:48:49 +0200 | [diff] [blame] | 142 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 143 | /* dynamic controls, init_verbs and input_mux */ |
| 144 | struct auto_pin_cfg autocfg; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 145 | struct alc_customize_define cdefine; |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 146 | struct snd_array kctls; |
Herton Ronaldo Krzesinski | 61b9b9b | 2009-01-28 09:16:33 -0200 | [diff] [blame] | 147 | struct hda_input_mux private_imux[3]; |
Takashi Iwai | 41923e4 | 2007-10-22 17:20:10 +0200 | [diff] [blame] | 148 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 149 | hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS]; |
| 150 | hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 151 | hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS]; |
| 152 | unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS]; |
| 153 | int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */ |
Takashi Iwai | 834be88 | 2006-03-01 14:16:17 +0100 | [diff] [blame] | 154 | |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 155 | /* hooks */ |
| 156 | void (*init_hook)(struct hda_codec *codec); |
| 157 | void (*unsol_event)(struct hda_codec *codec, unsigned int res); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 158 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 159 | void (*power_hook)(struct hda_codec *codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 160 | #endif |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 161 | void (*shutup)(struct hda_codec *codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 162 | void (*automute_hook)(struct hda_codec *codec); |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 163 | |
Takashi Iwai | 834be88 | 2006-03-01 14:16:17 +0100 | [diff] [blame] | 164 | /* for pin sensing */ |
Takashi Iwai | 834be88 | 2006-03-01 14:16:17 +0100 | [diff] [blame] | 165 | unsigned int jack_present: 1; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 166 | unsigned int line_jack_present:1; |
Takashi Iwai | e942796 | 2011-04-28 15:46:07 +0200 | [diff] [blame] | 167 | unsigned int master_mute:1; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 168 | unsigned int auto_mic:1; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 169 | unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */ |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 170 | unsigned int automute:1; /* HP automute enabled */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 171 | unsigned int detect_line:1; /* Line-out detection enabled */ |
| 172 | unsigned int automute_lines:1; /* automute line-out as well */ |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 173 | unsigned int automute_hp_lo:1; /* both HP and LO available */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 174 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 175 | /* other flags */ |
| 176 | unsigned int no_analog :1; /* digital I/O only */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 177 | unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */ |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 178 | unsigned int single_input_src:1; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 179 | 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] | 180 | unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */ |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 181 | |
| 182 | /* auto-mute control */ |
| 183 | int automute_mode; |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 184 | hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 185 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 186 | int init_amp; |
Takashi Iwai | d433a67 | 2010-09-20 15:11:54 +0200 | [diff] [blame] | 187 | int codec_variant; /* flag for other variants */ |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 188 | |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 189 | /* for virtual master */ |
| 190 | hda_nid_t vmaster_nid; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 191 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 192 | struct hda_loopback_check loopback; |
| 193 | #endif |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 194 | |
| 195 | /* for PLL fix */ |
| 196 | hda_nid_t pll_nid; |
| 197 | unsigned int pll_coef_idx, pll_coef_bit; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 198 | |
| 199 | /* fix-up list */ |
| 200 | int fixup_id; |
| 201 | const struct alc_fixup *fixup_list; |
| 202 | const char *fixup_name; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 203 | |
| 204 | /* multi-io */ |
| 205 | int multi_ios; |
| 206 | struct alc_multi_io multi_io[4]; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 207 | |
| 208 | /* bind volumes */ |
| 209 | struct snd_array bind_ctls; |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 210 | }; |
| 211 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 212 | #define ALC_MODEL_AUTO 0 /* common for all chips */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 214 | static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, |
| 215 | int dir, unsigned int bits) |
| 216 | { |
| 217 | if (!nid) |
| 218 | return false; |
| 219 | if (get_wcaps(codec, nid) & (1 << (dir + 1))) |
| 220 | if (query_amp_caps(codec, nid, dir) & bits) |
| 221 | return true; |
| 222 | return false; |
| 223 | } |
| 224 | |
| 225 | #define nid_has_mute(codec, nid, dir) \ |
| 226 | check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE) |
| 227 | #define nid_has_volume(codec, nid, dir) \ |
| 228 | check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS) |
| 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | /* |
| 231 | * input MUX handling |
| 232 | */ |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 233 | static int alc_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 234 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
| 236 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 237 | struct alc_spec *spec = codec->spec; |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 238 | unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id); |
| 239 | if (mux_idx >= spec->num_mux_defs) |
| 240 | mux_idx = 0; |
Takashi Iwai | 5311114 | 2010-03-08 12:13:07 +0100 | [diff] [blame] | 241 | if (!spec->input_mux[mux_idx].num_items && mux_idx > 0) |
| 242 | mux_idx = 0; |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 243 | return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 246 | static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 247 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
| 249 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 250 | struct alc_spec *spec = codec->spec; |
| 251 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 252 | |
| 253 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
| 254 | return 0; |
| 255 | } |
| 256 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 257 | 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] | 258 | { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 259 | struct alc_spec *spec = codec->spec; |
| 260 | hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]]; |
| 261 | |
| 262 | if (spec->cur_adc && spec->cur_adc != new_adc) { |
| 263 | /* stream is running, let's swap the current ADC */ |
| 264 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); |
| 265 | spec->cur_adc = new_adc; |
| 266 | snd_hda_codec_setup_stream(codec, new_adc, |
| 267 | spec->cur_adc_stream_tag, 0, |
| 268 | spec->cur_adc_format); |
| 269 | return true; |
| 270 | } |
| 271 | return false; |
| 272 | } |
| 273 | |
| 274 | /* select the given imux item; either unmute exclusively or select the route */ |
| 275 | static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx, |
| 276 | unsigned int idx, bool force) |
| 277 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 279 | const struct hda_input_mux *imux; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 280 | unsigned int mux_idx; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 281 | int i, type; |
| 282 | hda_nid_t nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 284 | mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; |
| 285 | imux = &spec->input_mux[mux_idx]; |
Takashi Iwai | 5311114 | 2010-03-08 12:13:07 +0100 | [diff] [blame] | 286 | if (!imux->num_items && mux_idx > 0) |
| 287 | imux = &spec->input_mux[0]; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 288 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 289 | if (idx >= imux->num_items) |
| 290 | idx = imux->num_items - 1; |
| 291 | if (spec->cur_mux[adc_idx] == idx && !force) |
| 292 | return 0; |
| 293 | spec->cur_mux[adc_idx] = idx; |
| 294 | |
| 295 | if (spec->dyn_adc_switch) { |
| 296 | alc_dyn_adc_pcm_resetup(codec, idx); |
| 297 | adc_idx = spec->dyn_adc_idx[idx]; |
| 298 | } |
| 299 | |
| 300 | nid = spec->capsrc_nids ? |
| 301 | spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx]; |
| 302 | |
| 303 | /* no selection? */ |
| 304 | if (snd_hda_get_conn_list(codec, nid, NULL) <= 1) |
| 305 | return 1; |
| 306 | |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 307 | type = get_wcaps_type(get_wcaps(codec, nid)); |
Takashi Iwai | 0169b6b | 2009-06-22 10:50:19 +0200 | [diff] [blame] | 308 | if (type == AC_WID_AUD_MIX) { |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 309 | /* Matrix-mixer style (e.g. ALC882) */ |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 310 | for (i = 0; i < imux->num_items; i++) { |
| 311 | unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE; |
| 312 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, |
| 313 | imux->items[i].index, |
| 314 | HDA_AMP_MUTE, v); |
| 315 | } |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 316 | } else { |
| 317 | /* MUX style (e.g. ALC880) */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 318 | snd_hda_codec_write_cache(codec, nid, 0, |
| 319 | AC_VERB_SET_CONNECT_SEL, |
| 320 | imux->items[idx].index); |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 321 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 322 | return 1; |
| 323 | } |
| 324 | |
| 325 | static int alc_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 326 | struct snd_ctl_elem_value *ucontrol) |
| 327 | { |
| 328 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 329 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 330 | return alc_mux_select(codec, adc_idx, |
| 331 | ucontrol->value.enumerated.item[0], false); |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 332 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /* |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 335 | * set up the input pin config (depending on the given auto-pin type) |
| 336 | */ |
| 337 | static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid, |
| 338 | int auto_pin_type) |
| 339 | { |
| 340 | unsigned int val = PIN_IN; |
| 341 | |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 342 | if (auto_pin_type == AUTO_PIN_MIC) { |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 343 | unsigned int pincap; |
Takashi Iwai | 954a29c | 2010-07-30 10:55:44 +0200 | [diff] [blame] | 344 | unsigned int oldval; |
| 345 | oldval = snd_hda_codec_read(codec, nid, 0, |
| 346 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
Takashi Iwai | 1327a32 | 2009-03-23 13:07:47 +0100 | [diff] [blame] | 347 | pincap = snd_hda_query_pin_caps(codec, nid); |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 348 | pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; |
Takashi Iwai | 954a29c | 2010-07-30 10:55:44 +0200 | [diff] [blame] | 349 | /* if the default pin setup is vref50, we give it priority */ |
| 350 | if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50) |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 351 | val = PIN_VREF80; |
Takashi Iwai | 461c6c3 | 2009-05-25 08:06:02 +0200 | [diff] [blame] | 352 | else if (pincap & AC_PINCAP_VREF_50) |
| 353 | val = PIN_VREF50; |
| 354 | else if (pincap & AC_PINCAP_VREF_100) |
| 355 | val = PIN_VREF100; |
| 356 | else if (pincap & AC_PINCAP_VREF_GRD) |
| 357 | val = PIN_VREFGRD; |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 358 | } |
| 359 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val); |
| 360 | } |
| 361 | |
| 362 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 363 | * Append the given mixer and verb elements for the later use |
| 364 | * The mixer array is referred in build_controls(), and init_verbs are |
| 365 | * called in init(). |
Takashi Iwai | d88897e | 2008-10-31 15:01:37 +0100 | [diff] [blame] | 366 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 367 | 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] | 368 | { |
| 369 | if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers))) |
| 370 | return; |
| 371 | spec->mixers[spec->num_mixers++] = mix; |
| 372 | } |
| 373 | |
| 374 | static void add_verb(struct alc_spec *spec, const struct hda_verb *verb) |
| 375 | { |
| 376 | if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs))) |
| 377 | return; |
| 378 | spec->init_verbs[spec->num_init_verbs++] = verb; |
| 379 | } |
| 380 | |
| 381 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 382 | * GPIO setup tables, used in initialization |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 383 | */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 384 | /* Enable GPIO mask and set output */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 385 | static const struct hda_verb alc_gpio1_init_verbs[] = { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 386 | {0x01, AC_VERB_SET_GPIO_MASK, 0x01}, |
| 387 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, |
| 388 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, |
| 389 | { } |
| 390 | }; |
| 391 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 392 | static const struct hda_verb alc_gpio2_init_verbs[] = { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 393 | {0x01, AC_VERB_SET_GPIO_MASK, 0x02}, |
| 394 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02}, |
| 395 | {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, |
| 396 | { } |
| 397 | }; |
| 398 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 399 | static const struct hda_verb alc_gpio3_init_verbs[] = { |
Kailang Yang | bdd148a | 2007-05-08 15:19:08 +0200 | [diff] [blame] | 400 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, |
| 401 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03}, |
| 402 | {0x01, AC_VERB_SET_GPIO_DATA, 0x03}, |
| 403 | { } |
| 404 | }; |
| 405 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 406 | /* |
| 407 | * Fix hardware PLL issue |
| 408 | * On some codecs, the analog PLL gating control must be off while |
| 409 | * the default value is 1. |
| 410 | */ |
| 411 | static void alc_fix_pll(struct hda_codec *codec) |
| 412 | { |
| 413 | struct alc_spec *spec = codec->spec; |
| 414 | unsigned int val; |
| 415 | |
| 416 | if (!spec->pll_nid) |
| 417 | return; |
| 418 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, |
| 419 | spec->pll_coef_idx); |
| 420 | val = snd_hda_codec_read(codec, spec->pll_nid, 0, |
| 421 | AC_VERB_GET_PROC_COEF, 0); |
| 422 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, |
| 423 | spec->pll_coef_idx); |
| 424 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF, |
| 425 | val & ~(1 << spec->pll_coef_bit)); |
| 426 | } |
| 427 | |
| 428 | static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid, |
| 429 | unsigned int coef_idx, unsigned int coef_bit) |
| 430 | { |
| 431 | struct alc_spec *spec = codec->spec; |
| 432 | spec->pll_nid = nid; |
| 433 | spec->pll_coef_idx = coef_idx; |
| 434 | spec->pll_coef_bit = coef_bit; |
| 435 | alc_fix_pll(codec); |
| 436 | } |
| 437 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 438 | /* |
| 439 | * Jack-reporting via input-jack layer |
| 440 | */ |
| 441 | |
| 442 | /* initialization of jacks; currently checks only a few known pins */ |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 443 | static int alc_init_jacks(struct hda_codec *codec) |
| 444 | { |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 445 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 446 | struct alc_spec *spec = codec->spec; |
| 447 | int err; |
| 448 | unsigned int hp_nid = spec->autocfg.hp_pins[0]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 449 | unsigned int mic_nid = spec->ext_mic_pin; |
| 450 | unsigned int dock_nid = spec->dock_mic_pin; |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 451 | |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 452 | if (hp_nid) { |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 453 | err = snd_hda_input_jack_add(codec, hp_nid, |
| 454 | SND_JACK_HEADPHONE, NULL); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 455 | if (err < 0) |
| 456 | return err; |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 457 | snd_hda_input_jack_report(codec, hp_nid); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 458 | } |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 459 | |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 460 | if (mic_nid) { |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 461 | err = snd_hda_input_jack_add(codec, mic_nid, |
| 462 | SND_JACK_MICROPHONE, NULL); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 463 | if (err < 0) |
| 464 | return err; |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 465 | snd_hda_input_jack_report(codec, mic_nid); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 466 | } |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 467 | if (dock_nid) { |
| 468 | err = snd_hda_input_jack_add(codec, dock_nid, |
| 469 | SND_JACK_MICROPHONE, NULL); |
| 470 | if (err < 0) |
| 471 | return err; |
| 472 | snd_hda_input_jack_report(codec, dock_nid); |
| 473 | } |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 474 | #endif /* CONFIG_SND_HDA_INPUT_JACK */ |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 475 | return 0; |
| 476 | } |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 477 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 478 | /* |
| 479 | * Jack detections for HP auto-mute and mic-switch |
| 480 | */ |
| 481 | |
| 482 | /* check each pin in the given array; returns true if any of them is plugged */ |
| 483 | 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] | 484 | { |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 485 | int i, present = 0; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 486 | |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 487 | for (i = 0; i < num_pins; i++) { |
| 488 | hda_nid_t nid = pins[i]; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 489 | if (!nid) |
| 490 | break; |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 491 | snd_hda_input_jack_report(codec, nid); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 492 | present |= snd_hda_jack_detect(codec, nid); |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 493 | } |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 494 | return present; |
| 495 | } |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 496 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 497 | /* standard HP/line-out auto-mute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 498 | 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] | 499 | bool mute, bool hp_out) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 500 | { |
| 501 | struct alc_spec *spec = codec->spec; |
| 502 | unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0; |
Takashi Iwai | e942796 | 2011-04-28 15:46:07 +0200 | [diff] [blame] | 503 | unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 504 | int i; |
| 505 | |
| 506 | for (i = 0; i < num_pins; i++) { |
| 507 | hda_nid_t nid = pins[i]; |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 508 | if (!nid) |
| 509 | break; |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 510 | switch (spec->automute_mode) { |
| 511 | case ALC_AUTOMUTE_PIN: |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 512 | snd_hda_codec_write(codec, nid, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 513 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 514 | pin_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 515 | break; |
| 516 | case ALC_AUTOMUTE_AMP: |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 517 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 518 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 519 | break; |
| 520 | case ALC_AUTOMUTE_MIXER: |
| 521 | nid = spec->automute_mixer_nid[i]; |
| 522 | if (!nid) |
| 523 | break; |
| 524 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 525 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 526 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 527 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 528 | break; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 529 | } |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 530 | } |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 531 | } |
| 532 | |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 533 | /* Toggle internal speakers muting */ |
| 534 | static void update_speakers(struct hda_codec *codec) |
| 535 | { |
| 536 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 537 | int on; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 538 | |
Takashi Iwai | c0a2026 | 2011-06-10 15:28:15 +0200 | [diff] [blame] | 539 | /* Control HP pins/amps depending on master_mute state; |
| 540 | * in general, HP pins/amps control should be enabled in all cases, |
| 541 | * but currently set only for master_mute, just to be safe |
| 542 | */ |
| 543 | do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins), |
| 544 | spec->autocfg.hp_pins, spec->master_mute, true); |
| 545 | |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 546 | if (!spec->automute) |
| 547 | on = 0; |
| 548 | else |
| 549 | on = spec->jack_present | spec->line_jack_present; |
| 550 | on |= spec->master_mute; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 551 | do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins), |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 552 | spec->autocfg.speaker_pins, on, false); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 553 | |
| 554 | /* toggle line-out mutes if needed, too */ |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 555 | /* if LO is a copy of either HP or Speaker, don't need to handle it */ |
| 556 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] || |
| 557 | spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0]) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 558 | return; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 559 | if (!spec->automute_lines || !spec->automute) |
| 560 | on = 0; |
| 561 | else |
| 562 | on = spec->jack_present; |
| 563 | on |= spec->master_mute; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 564 | do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 565 | spec->autocfg.line_out_pins, on, false); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 566 | } |
| 567 | |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 568 | static void call_update_speakers(struct hda_codec *codec) |
| 569 | { |
| 570 | struct alc_spec *spec = codec->spec; |
| 571 | if (spec->automute_hook) |
| 572 | spec->automute_hook(codec); |
| 573 | else |
| 574 | update_speakers(codec); |
| 575 | } |
| 576 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 577 | /* standard HP-automute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 578 | static void alc_hp_automute(struct hda_codec *codec) |
| 579 | { |
| 580 | struct alc_spec *spec = codec->spec; |
| 581 | |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 582 | spec->jack_present = |
| 583 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins), |
| 584 | spec->autocfg.hp_pins); |
Takashi Iwai | 3c715a9 | 2011-08-23 12:41:09 +0200 | [diff] [blame] | 585 | if (!spec->automute) |
| 586 | return; |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 587 | call_update_speakers(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 588 | } |
| 589 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 590 | /* standard line-out-automute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 591 | static void alc_line_automute(struct hda_codec *codec) |
| 592 | { |
| 593 | struct alc_spec *spec = codec->spec; |
| 594 | |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 595 | spec->line_jack_present = |
| 596 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
| 597 | spec->autocfg.line_out_pins); |
Takashi Iwai | 3c715a9 | 2011-08-23 12:41:09 +0200 | [diff] [blame] | 598 | if (!spec->automute || !spec->detect_line) |
| 599 | return; |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 600 | call_update_speakers(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 601 | } |
| 602 | |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 603 | #define get_connection_index(codec, mux, nid) \ |
| 604 | snd_hda_get_conn_index(codec, mux, nid, 0) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 605 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 606 | /* standard mic auto-switch helper */ |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 607 | static void alc_mic_automute(struct hda_codec *codec) |
| 608 | { |
| 609 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 610 | hda_nid_t *pins = spec->imux_pins; |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 611 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 612 | if (!spec->auto_mic || !spec->auto_mic_valid_imux) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 613 | return; |
| 614 | if (snd_BUG_ON(!spec->adc_nids)) |
| 615 | return; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 616 | 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] | 617 | return; |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 618 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 619 | if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx])) |
| 620 | alc_mux_select(codec, 0, spec->ext_mic_idx, false); |
| 621 | else if (spec->dock_mic_idx >= 0 && |
| 622 | snd_hda_jack_detect(codec, pins[spec->dock_mic_idx])) |
| 623 | alc_mux_select(codec, 0, spec->dock_mic_idx, false); |
| 624 | else |
| 625 | alc_mux_select(codec, 0, spec->int_mic_idx, false); |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 626 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 627 | snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]); |
| 628 | if (spec->dock_mic_idx >= 0) |
| 629 | snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 630 | } |
| 631 | |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 632 | /* unsolicited event for HP jack sensing */ |
| 633 | static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res) |
| 634 | { |
| 635 | if (codec->vendor_id == 0x10ec0880) |
| 636 | res >>= 28; |
| 637 | else |
| 638 | res >>= 26; |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 639 | switch (res) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 640 | case ALC_HP_EVENT: |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 641 | alc_hp_automute(codec); |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 642 | break; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 643 | case ALC_FRONT_EVENT: |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 644 | alc_line_automute(codec); |
| 645 | break; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 646 | case ALC_MIC_EVENT: |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 647 | alc_mic_automute(codec); |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 648 | break; |
| 649 | } |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 650 | } |
| 651 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 652 | /* call init functions of standard auto-mute helpers */ |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 653 | static void alc_inithook(struct hda_codec *codec) |
| 654 | { |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 655 | alc_hp_automute(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 656 | alc_line_automute(codec); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 657 | alc_mic_automute(codec); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 658 | } |
| 659 | |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 660 | /* additional initialization for ALC888 variants */ |
| 661 | static void alc888_coef_init(struct hda_codec *codec) |
| 662 | { |
| 663 | unsigned int tmp; |
| 664 | |
| 665 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0); |
| 666 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 667 | 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] | 668 | if ((tmp & 0xf0) == 0x20) |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 669 | /* alc888S-VC */ |
| 670 | snd_hda_codec_read(codec, 0x20, 0, |
| 671 | AC_VERB_SET_PROC_COEF, 0x830); |
| 672 | else |
| 673 | /* alc888-VB */ |
| 674 | snd_hda_codec_read(codec, 0x20, 0, |
| 675 | AC_VERB_SET_PROC_COEF, 0x3030); |
| 676 | } |
| 677 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 678 | /* additional initialization for ALC889 variants */ |
Jaroslav Kysela | 87a8c37 | 2009-07-23 10:58:29 +0200 | [diff] [blame] | 679 | static void alc889_coef_init(struct hda_codec *codec) |
| 680 | { |
| 681 | unsigned int tmp; |
| 682 | |
| 683 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 684 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 685 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 686 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010); |
| 687 | } |
| 688 | |
Takashi Iwai | 3fb4a50 | 2010-01-19 15:46:37 +0100 | [diff] [blame] | 689 | /* turn on/off EAPD control (only if available) */ |
| 690 | static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on) |
| 691 | { |
| 692 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) |
| 693 | return; |
| 694 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) |
| 695 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE, |
| 696 | on ? 2 : 0); |
| 697 | } |
| 698 | |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 699 | /* turn on/off EAPD controls of the codec */ |
| 700 | static void alc_auto_setup_eapd(struct hda_codec *codec, bool on) |
| 701 | { |
| 702 | /* We currently only handle front, HP */ |
Takashi Iwai | 39fa84e | 2011-06-27 15:28:57 +0200 | [diff] [blame] | 703 | static hda_nid_t pins[] = { |
| 704 | 0x0f, 0x10, 0x14, 0x15, 0 |
| 705 | }; |
| 706 | hda_nid_t *p; |
| 707 | for (p = pins; *p; p++) |
| 708 | set_eapd(codec, *p, on); |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 709 | } |
| 710 | |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 711 | /* generic shutup callback; |
| 712 | * just turning off EPAD and a little pause for avoiding pop-noise |
| 713 | */ |
| 714 | static void alc_eapd_shutup(struct hda_codec *codec) |
| 715 | { |
| 716 | alc_auto_setup_eapd(codec, false); |
| 717 | msleep(200); |
| 718 | } |
| 719 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 720 | /* generic EAPD initialization */ |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 721 | static void alc_auto_init_amp(struct hda_codec *codec, int type) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 722 | { |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 723 | unsigned int tmp; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 724 | |
Takashi Iwai | 39fa84e | 2011-06-27 15:28:57 +0200 | [diff] [blame] | 725 | alc_auto_setup_eapd(codec, true); |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 726 | switch (type) { |
| 727 | case ALC_INIT_GPIO1: |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 728 | snd_hda_sequence_write(codec, alc_gpio1_init_verbs); |
| 729 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 730 | case ALC_INIT_GPIO2: |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 731 | snd_hda_sequence_write(codec, alc_gpio2_init_verbs); |
| 732 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 733 | case ALC_INIT_GPIO3: |
Kailang Yang | bdd148a | 2007-05-08 15:19:08 +0200 | [diff] [blame] | 734 | snd_hda_sequence_write(codec, alc_gpio3_init_verbs); |
| 735 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 736 | case ALC_INIT_DEFAULT: |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 737 | switch (codec->vendor_id) { |
| 738 | case 0x10ec0260: |
| 739 | snd_hda_codec_write(codec, 0x1a, 0, |
| 740 | AC_VERB_SET_COEF_INDEX, 7); |
| 741 | tmp = snd_hda_codec_read(codec, 0x1a, 0, |
| 742 | AC_VERB_GET_PROC_COEF, 0); |
| 743 | snd_hda_codec_write(codec, 0x1a, 0, |
| 744 | AC_VERB_SET_COEF_INDEX, 7); |
| 745 | snd_hda_codec_write(codec, 0x1a, 0, |
| 746 | AC_VERB_SET_PROC_COEF, |
| 747 | tmp | 0x2010); |
| 748 | break; |
| 749 | case 0x10ec0262: |
| 750 | case 0x10ec0880: |
| 751 | case 0x10ec0882: |
| 752 | case 0x10ec0883: |
| 753 | case 0x10ec0885: |
Takashi Iwai | 4a5a4c5 | 2009-02-06 12:46:59 +0100 | [diff] [blame] | 754 | case 0x10ec0887: |
Takashi Iwai | 20b67dd | 2011-03-23 22:54:32 +0100 | [diff] [blame] | 755 | /*case 0x10ec0889:*/ /* this causes an SPDIF problem */ |
Jaroslav Kysela | 87a8c37 | 2009-07-23 10:58:29 +0200 | [diff] [blame] | 756 | alc889_coef_init(codec); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 757 | break; |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 758 | case 0x10ec0888: |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 759 | alc888_coef_init(codec); |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 760 | break; |
Takashi Iwai | 0aea778 | 2010-01-25 15:44:11 +0100 | [diff] [blame] | 761 | #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] | 762 | case 0x10ec0267: |
| 763 | case 0x10ec0268: |
| 764 | snd_hda_codec_write(codec, 0x20, 0, |
| 765 | AC_VERB_SET_COEF_INDEX, 7); |
| 766 | tmp = snd_hda_codec_read(codec, 0x20, 0, |
| 767 | AC_VERB_GET_PROC_COEF, 0); |
| 768 | snd_hda_codec_write(codec, 0x20, 0, |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 769 | AC_VERB_SET_COEF_INDEX, 7); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 770 | snd_hda_codec_write(codec, 0x20, 0, |
| 771 | AC_VERB_SET_PROC_COEF, |
| 772 | tmp | 0x3000); |
| 773 | break; |
Takashi Iwai | 0aea778 | 2010-01-25 15:44:11 +0100 | [diff] [blame] | 774 | #endif /* XXX */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 775 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 776 | break; |
| 777 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 778 | } |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 779 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 780 | /* |
| 781 | * Auto-Mute mode mixer enum support |
| 782 | */ |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 783 | static int alc_automute_mode_info(struct snd_kcontrol *kcontrol, |
| 784 | struct snd_ctl_elem_info *uinfo) |
| 785 | { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 786 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 787 | struct alc_spec *spec = codec->spec; |
| 788 | static const char * const texts2[] = { |
| 789 | "Disabled", "Enabled" |
| 790 | }; |
| 791 | static const char * const texts3[] = { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 792 | "Disabled", "Speaker Only", "Line-Out+Speaker" |
| 793 | }; |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 794 | const char * const *texts; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 795 | |
| 796 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 797 | uinfo->count = 1; |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 798 | if (spec->automute_hp_lo) { |
| 799 | uinfo->value.enumerated.items = 3; |
| 800 | texts = texts3; |
| 801 | } else { |
| 802 | uinfo->value.enumerated.items = 2; |
| 803 | texts = texts2; |
| 804 | } |
| 805 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 806 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 807 | strcpy(uinfo->value.enumerated.name, |
| 808 | texts[uinfo->value.enumerated.item]); |
| 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | static int alc_automute_mode_get(struct snd_kcontrol *kcontrol, |
| 813 | struct snd_ctl_elem_value *ucontrol) |
| 814 | { |
| 815 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 816 | struct alc_spec *spec = codec->spec; |
| 817 | unsigned int val; |
| 818 | if (!spec->automute) |
| 819 | val = 0; |
| 820 | else if (!spec->automute_lines) |
| 821 | val = 1; |
| 822 | else |
| 823 | val = 2; |
| 824 | ucontrol->value.enumerated.item[0] = val; |
| 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | static int alc_automute_mode_put(struct snd_kcontrol *kcontrol, |
| 829 | struct snd_ctl_elem_value *ucontrol) |
| 830 | { |
| 831 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 832 | struct alc_spec *spec = codec->spec; |
| 833 | |
| 834 | switch (ucontrol->value.enumerated.item[0]) { |
| 835 | case 0: |
| 836 | if (!spec->automute) |
| 837 | return 0; |
| 838 | spec->automute = 0; |
| 839 | break; |
| 840 | case 1: |
| 841 | if (spec->automute && !spec->automute_lines) |
| 842 | return 0; |
| 843 | spec->automute = 1; |
| 844 | spec->automute_lines = 0; |
| 845 | break; |
| 846 | case 2: |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 847 | if (!spec->automute_hp_lo) |
| 848 | return -EINVAL; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 849 | if (spec->automute && spec->automute_lines) |
| 850 | return 0; |
| 851 | spec->automute = 1; |
| 852 | spec->automute_lines = 1; |
| 853 | break; |
| 854 | default: |
| 855 | return -EINVAL; |
| 856 | } |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 857 | call_update_speakers(codec); |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 858 | return 1; |
| 859 | } |
| 860 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 861 | static const struct snd_kcontrol_new alc_automute_mode_enum = { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 862 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 863 | .name = "Auto-Mute Mode", |
| 864 | .info = alc_automute_mode_info, |
| 865 | .get = alc_automute_mode_get, |
| 866 | .put = alc_automute_mode_put, |
| 867 | }; |
| 868 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 869 | static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec) |
| 870 | { |
| 871 | snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32); |
| 872 | return snd_array_new(&spec->kctls); |
| 873 | } |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 874 | |
| 875 | static int alc_add_automute_mode_enum(struct hda_codec *codec) |
| 876 | { |
| 877 | struct alc_spec *spec = codec->spec; |
| 878 | struct snd_kcontrol_new *knew; |
| 879 | |
| 880 | knew = alc_kcontrol_new(spec); |
| 881 | if (!knew) |
| 882 | return -ENOMEM; |
| 883 | *knew = alc_automute_mode_enum; |
| 884 | knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL); |
| 885 | if (!knew->name) |
| 886 | return -ENOMEM; |
| 887 | return 0; |
| 888 | } |
| 889 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 890 | /* |
| 891 | * Check the availability of HP/line-out auto-mute; |
| 892 | * Set up appropriately if really supported |
| 893 | */ |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 894 | static void alc_init_auto_hp(struct hda_codec *codec) |
| 895 | { |
| 896 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 897 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 1daf5f4 | 2011-04-28 17:57:46 +0200 | [diff] [blame] | 898 | int present = 0; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 899 | int i; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 900 | |
Takashi Iwai | 1daf5f4 | 2011-04-28 17:57:46 +0200 | [diff] [blame] | 901 | if (cfg->hp_pins[0]) |
| 902 | present++; |
| 903 | if (cfg->line_out_pins[0]) |
| 904 | present++; |
| 905 | if (cfg->speaker_pins[0]) |
| 906 | present++; |
| 907 | if (present < 2) /* need two different output types */ |
| 908 | return; |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 909 | if (present == 3) |
| 910 | spec->automute_hp_lo = 1; /* both HP and LO automute */ |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 911 | |
Takashi Iwai | c48a8fb | 2011-07-27 16:41:57 +0200 | [diff] [blame] | 912 | if (!cfg->speaker_pins[0] && |
| 913 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 914 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 915 | sizeof(cfg->speaker_pins)); |
| 916 | cfg->speaker_outs = cfg->line_outs; |
| 917 | } |
| 918 | |
Takashi Iwai | c48a8fb | 2011-07-27 16:41:57 +0200 | [diff] [blame] | 919 | if (!cfg->hp_pins[0] && |
| 920 | cfg->line_out_type == AUTO_PIN_HP_OUT) { |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 921 | memcpy(cfg->hp_pins, cfg->line_out_pins, |
| 922 | sizeof(cfg->hp_pins)); |
| 923 | cfg->hp_outs = cfg->line_outs; |
| 924 | } |
| 925 | |
| 926 | for (i = 0; i < cfg->hp_outs; i++) { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 927 | hda_nid_t nid = cfg->hp_pins[i]; |
Takashi Iwai | 06dec22 | 2011-05-17 10:00:16 +0200 | [diff] [blame] | 928 | if (!is_jack_detectable(codec, nid)) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 929 | continue; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 930 | snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n", |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 931 | nid); |
| 932 | snd_hda_codec_write_cache(codec, nid, 0, |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 933 | AC_VERB_SET_UNSOLICITED_ENABLE, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 934 | AC_USRSP_EN | ALC_HP_EVENT); |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 935 | spec->automute = 1; |
| 936 | spec->automute_mode = ALC_AUTOMUTE_PIN; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 937 | } |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 938 | if (spec->automute && cfg->line_out_pins[0] && |
Takashi Iwai | c48a8fb | 2011-07-27 16:41:57 +0200 | [diff] [blame] | 939 | cfg->speaker_pins[0] && |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 940 | cfg->line_out_pins[0] != cfg->hp_pins[0] && |
| 941 | cfg->line_out_pins[0] != cfg->speaker_pins[0]) { |
| 942 | for (i = 0; i < cfg->line_outs; i++) { |
| 943 | hda_nid_t nid = cfg->line_out_pins[i]; |
Takashi Iwai | 06dec22 | 2011-05-17 10:00:16 +0200 | [diff] [blame] | 944 | if (!is_jack_detectable(codec, nid)) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 945 | continue; |
| 946 | snd_printdd("realtek: Enable Line-Out auto-muting " |
| 947 | "on NID 0x%x\n", nid); |
| 948 | snd_hda_codec_write_cache(codec, nid, 0, |
| 949 | AC_VERB_SET_UNSOLICITED_ENABLE, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 950 | AC_USRSP_EN | ALC_FRONT_EVENT); |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 951 | spec->detect_line = 1; |
| 952 | } |
Takashi Iwai | 52d3cb8 | 2011-05-17 10:04:08 +0200 | [diff] [blame] | 953 | spec->automute_lines = spec->detect_line; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 954 | } |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 955 | |
| 956 | if (spec->automute) { |
| 957 | /* create a control for automute mode */ |
| 958 | alc_add_automute_mode_enum(codec); |
| 959 | spec->unsol_event = alc_sku_unsol_event; |
| 960 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 961 | } |
| 962 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 963 | /* 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] | 964 | static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 965 | { |
| 966 | int i; |
| 967 | for (i = 0; i < nums; i++) |
| 968 | if (list[i] == nid) |
| 969 | return i; |
| 970 | return -1; |
| 971 | } |
| 972 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 973 | /* check whether dynamic ADC-switching is available */ |
| 974 | static bool alc_check_dyn_adc_switch(struct hda_codec *codec) |
| 975 | { |
| 976 | struct alc_spec *spec = codec->spec; |
| 977 | struct hda_input_mux *imux = &spec->private_imux[0]; |
| 978 | int i, n, idx; |
| 979 | hda_nid_t cap, pin; |
| 980 | |
| 981 | if (imux != spec->input_mux) /* no dynamic imux? */ |
| 982 | return false; |
| 983 | |
| 984 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 985 | cap = spec->private_capsrc_nids[n]; |
| 986 | for (i = 0; i < imux->num_items; i++) { |
| 987 | pin = spec->imux_pins[i]; |
| 988 | if (!pin) |
| 989 | return false; |
| 990 | if (get_connection_index(codec, cap, pin) < 0) |
| 991 | break; |
| 992 | } |
| 993 | if (i >= imux->num_items) |
Takashi Iwai | 268ff6f | 2011-07-08 14:37:35 +0200 | [diff] [blame] | 994 | return true; /* no ADC-switch is needed */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | for (i = 0; i < imux->num_items; i++) { |
| 998 | pin = spec->imux_pins[i]; |
| 999 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 1000 | cap = spec->private_capsrc_nids[n]; |
| 1001 | idx = get_connection_index(codec, cap, pin); |
| 1002 | if (idx >= 0) { |
| 1003 | imux->items[i].index = idx; |
| 1004 | spec->dyn_adc_idx[i] = n; |
| 1005 | break; |
| 1006 | } |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | snd_printdd("realtek: enabling ADC switching\n"); |
| 1011 | spec->dyn_adc_switch = 1; |
| 1012 | return true; |
| 1013 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1014 | |
| 1015 | /* rebuild imux for matching with the given auto-mic pins (if not yet) */ |
| 1016 | static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec) |
| 1017 | { |
| 1018 | struct alc_spec *spec = codec->spec; |
| 1019 | struct hda_input_mux *imux; |
| 1020 | static char * const texts[3] = { |
| 1021 | "Mic", "Internal Mic", "Dock Mic" |
| 1022 | }; |
| 1023 | int i; |
| 1024 | |
| 1025 | if (!spec->auto_mic) |
| 1026 | return false; |
| 1027 | imux = &spec->private_imux[0]; |
| 1028 | if (spec->input_mux == imux) |
| 1029 | return true; |
| 1030 | spec->imux_pins[0] = spec->ext_mic_pin; |
| 1031 | spec->imux_pins[1] = spec->int_mic_pin; |
| 1032 | spec->imux_pins[2] = spec->dock_mic_pin; |
| 1033 | for (i = 0; i < 3; i++) { |
| 1034 | strcpy(imux->items[i].label, texts[i]); |
| 1035 | if (spec->imux_pins[i]) |
| 1036 | imux->num_items = i + 1; |
| 1037 | } |
| 1038 | spec->num_mux_defs = 1; |
| 1039 | spec->input_mux = imux; |
| 1040 | return true; |
| 1041 | } |
| 1042 | |
| 1043 | /* check whether all auto-mic pins are valid; setup indices if OK */ |
| 1044 | static bool alc_auto_mic_check_imux(struct hda_codec *codec) |
| 1045 | { |
| 1046 | struct alc_spec *spec = codec->spec; |
| 1047 | const struct hda_input_mux *imux; |
| 1048 | |
| 1049 | if (!spec->auto_mic) |
| 1050 | return false; |
| 1051 | if (spec->auto_mic_valid_imux) |
| 1052 | return true; /* already checked */ |
| 1053 | |
| 1054 | /* fill up imux indices */ |
| 1055 | if (!alc_check_dyn_adc_switch(codec)) { |
| 1056 | spec->auto_mic = 0; |
| 1057 | return false; |
| 1058 | } |
| 1059 | |
| 1060 | imux = spec->input_mux; |
| 1061 | spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin, |
| 1062 | spec->imux_pins, imux->num_items); |
| 1063 | spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin, |
| 1064 | spec->imux_pins, imux->num_items); |
| 1065 | spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin, |
| 1066 | spec->imux_pins, imux->num_items); |
| 1067 | if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) { |
| 1068 | spec->auto_mic = 0; |
| 1069 | return false; /* no corresponding imux */ |
| 1070 | } |
| 1071 | |
| 1072 | snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0, |
| 1073 | AC_VERB_SET_UNSOLICITED_ENABLE, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1074 | AC_USRSP_EN | ALC_MIC_EVENT); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1075 | if (spec->dock_mic_pin) |
| 1076 | snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0, |
| 1077 | AC_VERB_SET_UNSOLICITED_ENABLE, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1078 | AC_USRSP_EN | ALC_MIC_EVENT); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1079 | |
| 1080 | spec->auto_mic_valid_imux = 1; |
| 1081 | spec->auto_mic = 1; |
| 1082 | return true; |
| 1083 | } |
| 1084 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1085 | /* |
| 1086 | * Check the availability of auto-mic switch; |
| 1087 | * Set up if really supported |
| 1088 | */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1089 | static void alc_init_auto_mic(struct hda_codec *codec) |
| 1090 | { |
| 1091 | struct alc_spec *spec = codec->spec; |
| 1092 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1093 | hda_nid_t fixed, ext, dock; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1094 | int i; |
| 1095 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1096 | spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1; |
| 1097 | |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1098 | fixed = ext = dock = 0; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 1099 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1100 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1101 | unsigned int defcfg; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1102 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1103 | switch (snd_hda_get_input_pin_attr(defcfg)) { |
| 1104 | case INPUT_PIN_ATTR_INT: |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1105 | if (fixed) |
| 1106 | return; /* already occupied */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1107 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 1108 | return; /* invalid type */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1109 | fixed = nid; |
| 1110 | break; |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1111 | case INPUT_PIN_ATTR_UNUSED: |
| 1112 | return; /* invalid entry */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1113 | case INPUT_PIN_ATTR_DOCK: |
| 1114 | if (dock) |
| 1115 | return; /* already occupied */ |
| 1116 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) |
| 1117 | return; /* invalid type */ |
| 1118 | dock = nid; |
| 1119 | break; |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1120 | default: |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1121 | if (ext) |
| 1122 | return; /* already occupied */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1123 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 1124 | return; /* invalid type */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1125 | ext = nid; |
| 1126 | break; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1127 | } |
| 1128 | } |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1129 | if (!ext && dock) { |
| 1130 | ext = dock; |
| 1131 | dock = 0; |
| 1132 | } |
Takashi Iwai | eaa9b3a | 2010-01-17 13:09:33 +0100 | [diff] [blame] | 1133 | if (!ext || !fixed) |
| 1134 | return; |
Takashi Iwai | e35d9d6 | 2011-05-17 11:28:16 +0200 | [diff] [blame] | 1135 | if (!is_jack_detectable(codec, ext)) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1136 | return; /* no unsol support */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1137 | if (dock && !is_jack_detectable(codec, dock)) |
| 1138 | return; /* no unsol support */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1139 | |
| 1140 | /* check imux indices */ |
| 1141 | spec->ext_mic_pin = ext; |
| 1142 | spec->int_mic_pin = fixed; |
| 1143 | spec->dock_mic_pin = dock; |
| 1144 | |
| 1145 | spec->auto_mic = 1; |
| 1146 | if (!alc_auto_mic_check_imux(codec)) |
| 1147 | return; |
| 1148 | |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1149 | snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n", |
| 1150 | ext, fixed, dock); |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1151 | spec->unsol_event = alc_sku_unsol_event; |
| 1152 | } |
| 1153 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1154 | /* check the availabilities of auto-mute and auto-mic switches */ |
| 1155 | static void alc_auto_check_switches(struct hda_codec *codec) |
| 1156 | { |
| 1157 | alc_init_auto_hp(codec); |
| 1158 | alc_init_auto_mic(codec); |
| 1159 | } |
| 1160 | |
| 1161 | /* |
| 1162 | * Realtek SSID verification |
| 1163 | */ |
| 1164 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1165 | /* Could be any non-zero and even value. When used as fixup, tells |
| 1166 | * the driver to ignore any present sku defines. |
| 1167 | */ |
| 1168 | #define ALC_FIXUP_SKU_IGNORE (2) |
| 1169 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1170 | static int alc_auto_parse_customize_define(struct hda_codec *codec) |
| 1171 | { |
| 1172 | unsigned int ass, tmp, i; |
Takashi Iwai | 7fb5622 | 2010-03-22 17:09:47 +0100 | [diff] [blame] | 1173 | unsigned nid = 0; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1174 | struct alc_spec *spec = codec->spec; |
| 1175 | |
Takashi Iwai | b6cbe51 | 2010-07-28 17:43:36 +0200 | [diff] [blame] | 1176 | spec->cdefine.enable_pcbeep = 1; /* assume always enabled */ |
| 1177 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1178 | if (spec->cdefine.fixup) { |
| 1179 | ass = spec->cdefine.sku_cfg; |
| 1180 | if (ass == ALC_FIXUP_SKU_IGNORE) |
| 1181 | return -1; |
| 1182 | goto do_sku; |
| 1183 | } |
| 1184 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1185 | ass = codec->subsystem_id & 0xffff; |
Takashi Iwai | b6cbe51 | 2010-07-28 17:43:36 +0200 | [diff] [blame] | 1186 | if (ass != codec->bus->pci->subsystem_device && (ass & 1)) |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1187 | goto do_sku; |
| 1188 | |
| 1189 | nid = 0x1d; |
| 1190 | if (codec->vendor_id == 0x10ec0260) |
| 1191 | nid = 0x17; |
| 1192 | ass = snd_hda_codec_get_pincfg(codec, nid); |
| 1193 | |
| 1194 | if (!(ass & 1)) { |
| 1195 | printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n", |
| 1196 | codec->chip_name, ass); |
| 1197 | return -1; |
| 1198 | } |
| 1199 | |
| 1200 | /* check sum */ |
| 1201 | tmp = 0; |
| 1202 | for (i = 1; i < 16; i++) { |
| 1203 | if ((ass >> i) & 1) |
| 1204 | tmp++; |
| 1205 | } |
| 1206 | if (((ass >> 16) & 0xf) != tmp) |
| 1207 | return -1; |
| 1208 | |
| 1209 | spec->cdefine.port_connectivity = ass >> 30; |
| 1210 | spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20; |
| 1211 | spec->cdefine.check_sum = (ass >> 16) & 0xf; |
| 1212 | spec->cdefine.customization = ass >> 8; |
| 1213 | do_sku: |
| 1214 | spec->cdefine.sku_cfg = ass; |
| 1215 | spec->cdefine.external_amp = (ass & 0x38) >> 3; |
| 1216 | spec->cdefine.platform_type = (ass & 0x4) >> 2; |
| 1217 | spec->cdefine.swap = (ass & 0x2) >> 1; |
| 1218 | spec->cdefine.override = ass & 0x1; |
| 1219 | |
| 1220 | snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n", |
| 1221 | nid, spec->cdefine.sku_cfg); |
| 1222 | snd_printd("SKU: port_connectivity=0x%x\n", |
| 1223 | spec->cdefine.port_connectivity); |
| 1224 | snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep); |
| 1225 | snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum); |
| 1226 | snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization); |
| 1227 | snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp); |
| 1228 | snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type); |
| 1229 | snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap); |
| 1230 | snd_printd("SKU: override=0x%x\n", spec->cdefine.override); |
| 1231 | |
| 1232 | return 0; |
| 1233 | } |
| 1234 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1235 | /* return true if the given NID is found in the list */ |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1236 | static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 1237 | { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1238 | return find_idx_in_nid_list(nid, list, nums) >= 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1239 | } |
| 1240 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1241 | /* check subsystem ID and set up device-specific initialization; |
| 1242 | * return 1 if initialized, 0 if invalid SSID |
| 1243 | */ |
| 1244 | /* 32-bit subsystem ID for BIOS loading in HD Audio codec. |
| 1245 | * 31 ~ 16 : Manufacture ID |
| 1246 | * 15 ~ 8 : SKU ID |
| 1247 | * 7 ~ 0 : Assembly ID |
| 1248 | * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36 |
| 1249 | */ |
| 1250 | static int alc_subsystem_id(struct hda_codec *codec, |
| 1251 | hda_nid_t porta, hda_nid_t porte, |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1252 | hda_nid_t portd, hda_nid_t porti) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1253 | { |
| 1254 | unsigned int ass, tmp, i; |
| 1255 | unsigned nid; |
| 1256 | struct alc_spec *spec = codec->spec; |
| 1257 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1258 | if (spec->cdefine.fixup) { |
| 1259 | ass = spec->cdefine.sku_cfg; |
| 1260 | if (ass == ALC_FIXUP_SKU_IGNORE) |
| 1261 | return 0; |
| 1262 | goto do_sku; |
| 1263 | } |
| 1264 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1265 | ass = codec->subsystem_id & 0xffff; |
| 1266 | if ((ass != codec->bus->pci->subsystem_device) && (ass & 1)) |
| 1267 | goto do_sku; |
| 1268 | |
| 1269 | /* invalid SSID, check the special NID pin defcfg instead */ |
| 1270 | /* |
Sasha Alexandr | def319f | 2009-06-16 16:00:15 -0400 | [diff] [blame] | 1271 | * 31~30 : port connectivity |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1272 | * 29~21 : reserve |
| 1273 | * 20 : PCBEEP input |
| 1274 | * 19~16 : Check sum (15:1) |
| 1275 | * 15~1 : Custom |
| 1276 | * 0 : override |
| 1277 | */ |
| 1278 | nid = 0x1d; |
| 1279 | if (codec->vendor_id == 0x10ec0260) |
| 1280 | nid = 0x17; |
| 1281 | ass = snd_hda_codec_get_pincfg(codec, nid); |
| 1282 | snd_printd("realtek: No valid SSID, " |
| 1283 | "checking pincfg 0x%08x for NID 0x%x\n", |
Takashi Iwai | cb6605c | 2009-04-28 13:03:19 +0200 | [diff] [blame] | 1284 | ass, nid); |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1285 | if (!(ass & 1)) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1286 | return 0; |
| 1287 | if ((ass >> 30) != 1) /* no physical connection */ |
| 1288 | return 0; |
| 1289 | |
| 1290 | /* check sum */ |
| 1291 | tmp = 0; |
| 1292 | for (i = 1; i < 16; i++) { |
| 1293 | if ((ass >> i) & 1) |
| 1294 | tmp++; |
| 1295 | } |
| 1296 | if (((ass >> 16) & 0xf) != tmp) |
| 1297 | return 0; |
| 1298 | do_sku: |
| 1299 | snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n", |
| 1300 | ass & 0xffff, codec->vendor_id); |
| 1301 | /* |
| 1302 | * 0 : override |
| 1303 | * 1 : Swap Jack |
| 1304 | * 2 : 0 --> Desktop, 1 --> Laptop |
| 1305 | * 3~5 : External Amplifier control |
| 1306 | * 7~6 : Reserved |
| 1307 | */ |
| 1308 | tmp = (ass & 0x38) >> 3; /* external Amp control */ |
| 1309 | switch (tmp) { |
| 1310 | case 1: |
| 1311 | spec->init_amp = ALC_INIT_GPIO1; |
| 1312 | break; |
| 1313 | case 3: |
| 1314 | spec->init_amp = ALC_INIT_GPIO2; |
| 1315 | break; |
| 1316 | case 7: |
| 1317 | spec->init_amp = ALC_INIT_GPIO3; |
| 1318 | break; |
| 1319 | case 5: |
Takashi Iwai | 5a8cfb4 | 2010-11-26 17:11:18 +0100 | [diff] [blame] | 1320 | default: |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1321 | spec->init_amp = ALC_INIT_DEFAULT; |
| 1322 | break; |
| 1323 | } |
| 1324 | |
| 1325 | /* is laptop or Desktop and enable the function "Mute internal speaker |
| 1326 | * when the external headphone out jack is plugged" |
| 1327 | */ |
| 1328 | if (!(ass & 0x8000)) |
| 1329 | return 1; |
| 1330 | /* |
| 1331 | * 10~8 : Jack location |
| 1332 | * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered |
| 1333 | * 14~13: Resvered |
| 1334 | * 15 : 1 --> enable the function "Mute internal speaker |
| 1335 | * when the external headphone out jack is plugged" |
| 1336 | */ |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1337 | if (!spec->autocfg.hp_pins[0]) { |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1338 | hda_nid_t nid; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1339 | tmp = (ass >> 11) & 0x3; /* HP to chassis */ |
| 1340 | if (tmp == 0) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1341 | nid = porta; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1342 | else if (tmp == 1) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1343 | nid = porte; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1344 | else if (tmp == 2) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1345 | nid = portd; |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1346 | else if (tmp == 3) |
| 1347 | nid = porti; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1348 | else |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1349 | return 1; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1350 | if (found_in_nid_list(nid, spec->autocfg.line_out_pins, |
| 1351 | spec->autocfg.line_outs)) |
| 1352 | return 1; |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1353 | spec->autocfg.hp_pins[0] = nid; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1354 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1355 | return 1; |
| 1356 | } |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 1357 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 1358 | /* Check the validity of ALC subsystem-id |
| 1359 | * ports contains an array of 4 pin NIDs for port-A, E, D and I */ |
| 1360 | 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] | 1361 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 1362 | 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] | 1363 | struct alc_spec *spec = codec->spec; |
| 1364 | snd_printd("realtek: " |
| 1365 | "Enable default setup for auto mode as fallback\n"); |
| 1366 | spec->init_amp = ALC_INIT_DEFAULT; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1367 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1368 | } |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 1369 | |
Takashi Iwai | 41e41f1 | 2005-06-08 14:48:49 +0200 | [diff] [blame] | 1370 | /* |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1371 | * Fix-up pin default configurations and add default verbs |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1372 | */ |
| 1373 | |
| 1374 | struct alc_pincfg { |
| 1375 | hda_nid_t nid; |
| 1376 | u32 val; |
| 1377 | }; |
| 1378 | |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1379 | struct alc_model_fixup { |
| 1380 | const int id; |
| 1381 | const char *name; |
| 1382 | }; |
| 1383 | |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1384 | struct alc_fixup { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1385 | int type; |
Takashi Iwai | 361fe6e | 2011-01-14 09:55:32 +0100 | [diff] [blame] | 1386 | bool chained; |
| 1387 | int chain_id; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1388 | union { |
| 1389 | unsigned int sku; |
| 1390 | const struct alc_pincfg *pins; |
| 1391 | const struct hda_verb *verbs; |
| 1392 | void (*func)(struct hda_codec *codec, |
| 1393 | const struct alc_fixup *fix, |
| 1394 | int action); |
| 1395 | } v; |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1396 | }; |
| 1397 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1398 | enum { |
| 1399 | ALC_FIXUP_INVALID, |
| 1400 | ALC_FIXUP_SKU, |
| 1401 | ALC_FIXUP_PINS, |
| 1402 | ALC_FIXUP_VERBS, |
| 1403 | ALC_FIXUP_FUNC, |
| 1404 | }; |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1405 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1406 | enum { |
| 1407 | ALC_FIXUP_ACT_PRE_PROBE, |
| 1408 | ALC_FIXUP_ACT_PROBE, |
Takashi Iwai | 5870112 | 2011-01-13 15:41:45 +0100 | [diff] [blame] | 1409 | ALC_FIXUP_ACT_INIT, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1410 | }; |
| 1411 | |
| 1412 | static void alc_apply_fixup(struct hda_codec *codec, int action) |
| 1413 | { |
| 1414 | struct alc_spec *spec = codec->spec; |
| 1415 | int id = spec->fixup_id; |
Takashi Iwai | aa1d0c5 | 2011-01-19 17:27:58 +0100 | [diff] [blame] | 1416 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1417 | const char *modelname = spec->fixup_name; |
Takashi Iwai | aa1d0c5 | 2011-01-19 17:27:58 +0100 | [diff] [blame] | 1418 | #endif |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1419 | int depth = 0; |
| 1420 | |
| 1421 | if (!spec->fixup_list) |
| 1422 | return; |
| 1423 | |
| 1424 | while (id >= 0) { |
| 1425 | const struct alc_fixup *fix = spec->fixup_list + id; |
| 1426 | const struct alc_pincfg *cfg; |
| 1427 | |
| 1428 | switch (fix->type) { |
| 1429 | case ALC_FIXUP_SKU: |
| 1430 | if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku) |
| 1431 | break;; |
| 1432 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1433 | "Apply sku override for %s\n", |
| 1434 | codec->chip_name, modelname); |
| 1435 | spec->cdefine.sku_cfg = fix->v.sku; |
| 1436 | spec->cdefine.fixup = 1; |
| 1437 | break; |
| 1438 | case ALC_FIXUP_PINS: |
| 1439 | cfg = fix->v.pins; |
| 1440 | if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg) |
| 1441 | break; |
| 1442 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1443 | "Apply pincfg for %s\n", |
| 1444 | codec->chip_name, modelname); |
| 1445 | for (; cfg->nid; cfg++) |
| 1446 | snd_hda_codec_set_pincfg(codec, cfg->nid, |
| 1447 | cfg->val); |
| 1448 | break; |
| 1449 | case ALC_FIXUP_VERBS: |
| 1450 | if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs) |
| 1451 | break; |
| 1452 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1453 | "Apply fix-verbs for %s\n", |
| 1454 | codec->chip_name, modelname); |
| 1455 | add_verb(codec->spec, fix->v.verbs); |
| 1456 | break; |
| 1457 | case ALC_FIXUP_FUNC: |
| 1458 | if (!fix->v.func) |
| 1459 | break; |
| 1460 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1461 | "Apply fix-func for %s\n", |
| 1462 | codec->chip_name, modelname); |
| 1463 | fix->v.func(codec, fix, action); |
| 1464 | break; |
| 1465 | default: |
| 1466 | snd_printk(KERN_ERR "hda_codec: %s: " |
| 1467 | "Invalid fixup type %d\n", |
| 1468 | codec->chip_name, fix->type); |
| 1469 | break; |
| 1470 | } |
Takashi Iwai | 24af2b1 | 2011-05-02 13:55:36 +0200 | [diff] [blame] | 1471 | if (!fix->chained) |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1472 | break; |
| 1473 | if (++depth > 10) |
| 1474 | break; |
Takashi Iwai | 24af2b1 | 2011-05-02 13:55:36 +0200 | [diff] [blame] | 1475 | id = fix->chain_id; |
Takashi Iwai | 9d57883 | 2010-11-22 13:29:19 +0100 | [diff] [blame] | 1476 | } |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1477 | } |
| 1478 | |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1479 | static void alc_pick_fixup(struct hda_codec *codec, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1480 | const struct alc_model_fixup *models, |
| 1481 | const struct snd_pci_quirk *quirk, |
| 1482 | const struct alc_fixup *fixlist) |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1483 | { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1484 | struct alc_spec *spec = codec->spec; |
| 1485 | int id = -1; |
| 1486 | const char *name = NULL; |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1487 | |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1488 | if (codec->modelname && models) { |
| 1489 | while (models->name) { |
| 1490 | if (!strcmp(codec->modelname, models->name)) { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1491 | id = models->id; |
| 1492 | name = models->name; |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1493 | break; |
| 1494 | } |
| 1495 | models++; |
| 1496 | } |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1497 | } |
| 1498 | if (id < 0) { |
| 1499 | quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk); |
| 1500 | if (quirk) { |
| 1501 | id = quirk->value; |
| 1502 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
| 1503 | name = quirk->name; |
| 1504 | #endif |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | spec->fixup_id = id; |
| 1509 | if (id >= 0) { |
| 1510 | spec->fixup_list = fixlist; |
| 1511 | spec->fixup_name = name; |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1512 | } |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1513 | } |
| 1514 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1515 | /* |
| 1516 | * COEF access helper functions |
| 1517 | */ |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 1518 | static int alc_read_coef_idx(struct hda_codec *codec, |
| 1519 | unsigned int coef_idx) |
| 1520 | { |
| 1521 | unsigned int val; |
| 1522 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, |
| 1523 | coef_idx); |
| 1524 | val = snd_hda_codec_read(codec, 0x20, 0, |
| 1525 | AC_VERB_GET_PROC_COEF, 0); |
| 1526 | return val; |
| 1527 | } |
| 1528 | |
Kailang Yang | 977ddd6 | 2010-09-15 10:02:29 +0200 | [diff] [blame] | 1529 | static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx, |
| 1530 | unsigned int coef_val) |
| 1531 | { |
| 1532 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, |
| 1533 | coef_idx); |
| 1534 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, |
| 1535 | coef_val); |
| 1536 | } |
| 1537 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1538 | /* |
| 1539 | * Digital I/O handling |
| 1540 | */ |
| 1541 | |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1542 | /* set right pin controls for digital I/O */ |
| 1543 | static void alc_auto_init_digital(struct hda_codec *codec) |
| 1544 | { |
| 1545 | struct alc_spec *spec = codec->spec; |
| 1546 | int i; |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 1547 | hda_nid_t pin, dac; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1548 | |
| 1549 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
| 1550 | pin = spec->autocfg.dig_out_pins[i]; |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 1551 | if (!pin) |
| 1552 | continue; |
| 1553 | snd_hda_codec_write(codec, pin, 0, |
| 1554 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); |
| 1555 | if (!i) |
| 1556 | dac = spec->multiout.dig_out_nid; |
| 1557 | else |
| 1558 | dac = spec->slave_dig_outs[i - 1]; |
| 1559 | if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP)) |
| 1560 | continue; |
| 1561 | snd_hda_codec_write(codec, dac, 0, |
| 1562 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 1563 | AMP_OUT_UNMUTE); |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1564 | } |
| 1565 | pin = spec->autocfg.dig_in_pin; |
| 1566 | if (pin) |
| 1567 | snd_hda_codec_write(codec, pin, 0, |
| 1568 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1569 | PIN_IN); |
| 1570 | } |
| 1571 | |
| 1572 | /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */ |
| 1573 | static void alc_auto_parse_digital(struct hda_codec *codec) |
| 1574 | { |
| 1575 | struct alc_spec *spec = codec->spec; |
| 1576 | int i, err; |
| 1577 | hda_nid_t dig_nid; |
| 1578 | |
| 1579 | /* support multiple SPDIFs; the secondary is set up as a slave */ |
| 1580 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1581 | hda_nid_t conn[4]; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1582 | err = snd_hda_get_connections(codec, |
| 1583 | spec->autocfg.dig_out_pins[i], |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1584 | conn, ARRAY_SIZE(conn)); |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1585 | if (err < 0) |
| 1586 | continue; |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1587 | dig_nid = conn[0]; /* assume the first element is audio-out */ |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1588 | if (!i) { |
| 1589 | spec->multiout.dig_out_nid = dig_nid; |
| 1590 | spec->dig_out_type = spec->autocfg.dig_out_type[0]; |
| 1591 | } else { |
| 1592 | spec->multiout.slave_dig_outs = spec->slave_dig_outs; |
| 1593 | if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1) |
| 1594 | break; |
| 1595 | spec->slave_dig_outs[i - 1] = dig_nid; |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | if (spec->autocfg.dig_in_pin) { |
Takashi Iwai | 01fdf18 | 2010-09-24 09:09:42 +0200 | [diff] [blame] | 1600 | dig_nid = codec->start_nid; |
| 1601 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { |
| 1602 | unsigned int wcaps = get_wcaps(codec, dig_nid); |
| 1603 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
| 1604 | continue; |
| 1605 | if (!(wcaps & AC_WCAP_DIGITAL)) |
| 1606 | continue; |
| 1607 | if (!(wcaps & AC_WCAP_CONN_LIST)) |
| 1608 | continue; |
| 1609 | err = get_connection_index(codec, dig_nid, |
| 1610 | spec->autocfg.dig_in_pin); |
| 1611 | if (err >= 0) { |
| 1612 | spec->dig_in_nid = dig_nid; |
| 1613 | break; |
| 1614 | } |
| 1615 | } |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1616 | } |
| 1617 | } |
| 1618 | |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1619 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1620 | * capture mixer elements |
Vincent Petry | ef8ef5f | 2008-11-23 11:31:41 +0800 | [diff] [blame] | 1621 | */ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1622 | static int alc_cap_vol_info(struct snd_kcontrol *kcontrol, |
| 1623 | struct snd_ctl_elem_info *uinfo) |
| 1624 | { |
| 1625 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1626 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1627 | unsigned long val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1628 | int err; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1629 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1630 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1631 | if (spec->vol_in_capsrc) |
| 1632 | val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT); |
| 1633 | else |
| 1634 | val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT); |
| 1635 | kcontrol->private_value = val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1636 | err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo); |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1637 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1638 | return err; |
| 1639 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1641 | static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, |
| 1642 | unsigned int size, unsigned int __user *tlv) |
| 1643 | { |
| 1644 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1645 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1646 | unsigned long val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1647 | int err; |
| 1648 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1649 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1650 | if (spec->vol_in_capsrc) |
| 1651 | val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT); |
| 1652 | else |
| 1653 | val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT); |
| 1654 | kcontrol->private_value = val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1655 | err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv); |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1656 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1657 | return err; |
| 1658 | } |
| 1659 | |
| 1660 | typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol, |
| 1661 | struct snd_ctl_elem_value *ucontrol); |
| 1662 | |
| 1663 | static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol, |
| 1664 | struct snd_ctl_elem_value *ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1665 | getput_call_t func, bool check_adc_switch) |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1666 | { |
| 1667 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1668 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1669 | int i, err = 0; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1670 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1671 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1672 | if (check_adc_switch && spec->dyn_adc_switch) { |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1673 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 1674 | kcontrol->private_value = |
| 1675 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], |
| 1676 | 3, 0, HDA_INPUT); |
| 1677 | err = func(kcontrol, ucontrol); |
| 1678 | if (err < 0) |
| 1679 | goto error; |
| 1680 | } |
| 1681 | } else { |
| 1682 | i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1683 | if (spec->vol_in_capsrc) |
| 1684 | kcontrol->private_value = |
| 1685 | HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i], |
| 1686 | 3, 0, HDA_OUTPUT); |
| 1687 | else |
| 1688 | kcontrol->private_value = |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1689 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], |
| 1690 | 3, 0, HDA_INPUT); |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1691 | err = func(kcontrol, ucontrol); |
| 1692 | } |
| 1693 | error: |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1694 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1695 | return err; |
| 1696 | } |
| 1697 | |
| 1698 | static int alc_cap_vol_get(struct snd_kcontrol *kcontrol, |
| 1699 | struct snd_ctl_elem_value *ucontrol) |
| 1700 | { |
| 1701 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1702 | snd_hda_mixer_amp_volume_get, false); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | static int alc_cap_vol_put(struct snd_kcontrol *kcontrol, |
| 1706 | struct snd_ctl_elem_value *ucontrol) |
| 1707 | { |
| 1708 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1709 | snd_hda_mixer_amp_volume_put, true); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | /* capture mixer elements */ |
| 1713 | #define alc_cap_sw_info snd_ctl_boolean_stereo_info |
| 1714 | |
| 1715 | static int alc_cap_sw_get(struct snd_kcontrol *kcontrol, |
| 1716 | struct snd_ctl_elem_value *ucontrol) |
| 1717 | { |
| 1718 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1719 | snd_hda_mixer_amp_switch_get, false); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | static int alc_cap_sw_put(struct snd_kcontrol *kcontrol, |
| 1723 | struct snd_ctl_elem_value *ucontrol) |
| 1724 | { |
| 1725 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1726 | snd_hda_mixer_amp_switch_put, true); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1727 | } |
| 1728 | |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1729 | #define _DEFINE_CAPMIX(num) \ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1730 | { \ |
| 1731 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1732 | .name = "Capture Switch", \ |
| 1733 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \ |
| 1734 | .count = num, \ |
| 1735 | .info = alc_cap_sw_info, \ |
| 1736 | .get = alc_cap_sw_get, \ |
| 1737 | .put = alc_cap_sw_put, \ |
| 1738 | }, \ |
| 1739 | { \ |
| 1740 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1741 | .name = "Capture Volume", \ |
| 1742 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \ |
| 1743 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ |
| 1744 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \ |
| 1745 | .count = num, \ |
| 1746 | .info = alc_cap_vol_info, \ |
| 1747 | .get = alc_cap_vol_get, \ |
| 1748 | .put = alc_cap_vol_put, \ |
| 1749 | .tlv = { .c = alc_cap_vol_tlv }, \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | #define _DEFINE_CAPSRC(num) \ |
Takashi Iwai | 3c3e989 | 2008-10-31 17:48:56 +0100 | [diff] [blame] | 1753 | { \ |
| 1754 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1755 | /* .name = "Capture Source", */ \ |
| 1756 | .name = "Input Source", \ |
| 1757 | .count = num, \ |
| 1758 | .info = alc_mux_enum_info, \ |
| 1759 | .get = alc_mux_enum_get, \ |
| 1760 | .put = alc_mux_enum_put, \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | #define DEFINE_CAPMIX(num) \ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1764 | static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1765 | _DEFINE_CAPMIX(num), \ |
| 1766 | _DEFINE_CAPSRC(num), \ |
| 1767 | { } /* end */ \ |
| 1768 | } |
| 1769 | |
| 1770 | #define DEFINE_CAPMIX_NOSRC(num) \ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1771 | static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1772 | _DEFINE_CAPMIX(num), \ |
| 1773 | { } /* end */ \ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | /* up to three ADCs */ |
| 1777 | DEFINE_CAPMIX(1); |
| 1778 | DEFINE_CAPMIX(2); |
| 1779 | DEFINE_CAPMIX(3); |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1780 | DEFINE_CAPMIX_NOSRC(1); |
| 1781 | DEFINE_CAPMIX_NOSRC(2); |
| 1782 | DEFINE_CAPMIX_NOSRC(3); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1783 | |
| 1784 | /* |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1785 | * virtual master controls |
| 1786 | */ |
| 1787 | |
| 1788 | /* |
| 1789 | * slave controls for virtual master |
| 1790 | */ |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1791 | static const char * const alc_slave_vols[] = { |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1792 | "Front Playback Volume", |
| 1793 | "Surround Playback Volume", |
| 1794 | "Center Playback Volume", |
| 1795 | "LFE Playback Volume", |
| 1796 | "Side Playback Volume", |
| 1797 | "Headphone Playback Volume", |
| 1798 | "Speaker Playback Volume", |
| 1799 | "Mono Playback Volume", |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1800 | "Line-Out Playback Volume", |
Takashi Iwai | 3fe45ae | 2011-08-18 15:13:17 +0200 | [diff] [blame] | 1801 | "PCM Playback Volume", |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1802 | NULL, |
| 1803 | }; |
| 1804 | |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1805 | static const char * const alc_slave_sws[] = { |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1806 | "Front Playback Switch", |
| 1807 | "Surround Playback Switch", |
| 1808 | "Center Playback Switch", |
| 1809 | "LFE Playback Switch", |
| 1810 | "Side Playback Switch", |
| 1811 | "Headphone Playback Switch", |
| 1812 | "Speaker Playback Switch", |
| 1813 | "Mono Playback Switch", |
Takashi Iwai | edb54a5 | 2008-01-29 12:47:02 +0100 | [diff] [blame] | 1814 | "IEC958 Playback Switch", |
Takashi Iwai | 23033b2 | 2009-12-08 12:36:52 +0100 | [diff] [blame] | 1815 | "Line-Out Playback Switch", |
Takashi Iwai | 3fe45ae | 2011-08-18 15:13:17 +0200 | [diff] [blame] | 1816 | "PCM Playback Switch", |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1817 | NULL, |
| 1818 | }; |
| 1819 | |
| 1820 | /* |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1821 | * build control elements |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | */ |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1823 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1824 | #define NID_MAPPING (-1) |
| 1825 | |
| 1826 | #define SUBDEV_SPEAKER_ (0 << 6) |
| 1827 | #define SUBDEV_HP_ (1 << 6) |
| 1828 | #define SUBDEV_LINE_ (2 << 6) |
| 1829 | #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f)) |
| 1830 | #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f)) |
| 1831 | #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f)) |
| 1832 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1833 | static void alc_free_kctls(struct hda_codec *codec); |
| 1834 | |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1835 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1836 | /* additional beep mixers; the actual parameters are overwritten at build */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1837 | static const struct snd_kcontrol_new alc_beep_mixer[] = { |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1838 | HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT), |
Jaroslav Kysela | 123c07a | 2009-10-21 14:48:23 +0200 | [diff] [blame] | 1839 | HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT), |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1840 | { } /* end */ |
| 1841 | }; |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1842 | #endif |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | static int alc_build_controls(struct hda_codec *codec) |
| 1845 | { |
| 1846 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2f44f84 | 2010-06-22 11:12:32 +0200 | [diff] [blame] | 1847 | struct snd_kcontrol *kctl = NULL; |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1848 | const struct snd_kcontrol_new *knew; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1849 | int i, j, err; |
| 1850 | unsigned int u; |
| 1851 | hda_nid_t nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | |
| 1853 | for (i = 0; i < spec->num_mixers; i++) { |
| 1854 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 1855 | if (err < 0) |
| 1856 | return err; |
| 1857 | } |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1858 | if (spec->cap_mixer) { |
| 1859 | err = snd_hda_add_new_ctls(codec, spec->cap_mixer); |
| 1860 | if (err < 0) |
| 1861 | return err; |
| 1862 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | if (spec->multiout.dig_out_nid) { |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 1864 | err = snd_hda_create_spdif_out_ctls(codec, |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 1865 | spec->multiout.dig_out_nid, |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 1866 | spec->multiout.dig_out_nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | if (err < 0) |
| 1868 | return err; |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1869 | if (!spec->no_analog) { |
| 1870 | err = snd_hda_create_spdif_share_sw(codec, |
| 1871 | &spec->multiout); |
| 1872 | if (err < 0) |
| 1873 | return err; |
| 1874 | spec->multiout.share_spdif = 1; |
| 1875 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | } |
| 1877 | if (spec->dig_in_nid) { |
| 1878 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); |
| 1879 | if (err < 0) |
| 1880 | return err; |
| 1881 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1882 | |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1883 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1884 | /* create beep controls if needed */ |
| 1885 | if (spec->beep_amp) { |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1886 | const struct snd_kcontrol_new *knew; |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1887 | for (knew = alc_beep_mixer; knew->name; knew++) { |
| 1888 | struct snd_kcontrol *kctl; |
| 1889 | kctl = snd_ctl_new1(knew, codec); |
| 1890 | if (!kctl) |
| 1891 | return -ENOMEM; |
| 1892 | kctl->private_value = spec->beep_amp; |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 1893 | err = snd_hda_ctl_add(codec, 0, kctl); |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1894 | if (err < 0) |
| 1895 | return err; |
| 1896 | } |
| 1897 | } |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1898 | #endif |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1899 | |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1900 | /* if we have no master control, let's create it */ |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1901 | if (!spec->no_analog && |
| 1902 | !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1903 | unsigned int vmaster_tlv[4]; |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1904 | snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1905 | HDA_OUTPUT, vmaster_tlv); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1906 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1907 | vmaster_tlv, alc_slave_vols); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1908 | if (err < 0) |
| 1909 | return err; |
| 1910 | } |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1911 | if (!spec->no_analog && |
| 1912 | !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1913 | err = snd_hda_add_vmaster(codec, "Master Playback Switch", |
| 1914 | NULL, alc_slave_sws); |
| 1915 | if (err < 0) |
| 1916 | return err; |
| 1917 | } |
| 1918 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1919 | /* assign Capture Source enums to NID */ |
Takashi Iwai | fbe618f | 2010-06-11 11:24:58 +0200 | [diff] [blame] | 1920 | if (spec->capsrc_nids || spec->adc_nids) { |
| 1921 | kctl = snd_hda_find_mixer_ctl(codec, "Capture Source"); |
| 1922 | if (!kctl) |
| 1923 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); |
| 1924 | for (i = 0; kctl && i < kctl->count; i++) { |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1925 | const hda_nid_t *nids = spec->capsrc_nids; |
Takashi Iwai | fbe618f | 2010-06-11 11:24:58 +0200 | [diff] [blame] | 1926 | if (!nids) |
| 1927 | nids = spec->adc_nids; |
| 1928 | err = snd_hda_add_nid(codec, kctl, i, nids[i]); |
| 1929 | if (err < 0) |
| 1930 | return err; |
| 1931 | } |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1932 | } |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 1933 | if (spec->cap_mixer && spec->adc_nids) { |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1934 | const char *kname = kctl ? kctl->id.name : NULL; |
| 1935 | for (knew = spec->cap_mixer; knew->name; knew++) { |
| 1936 | if (kname && strcmp(knew->name, kname) == 0) |
| 1937 | continue; |
| 1938 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 1939 | for (i = 0; kctl && i < kctl->count; i++) { |
| 1940 | err = snd_hda_add_nid(codec, kctl, i, |
| 1941 | spec->adc_nids[i]); |
| 1942 | if (err < 0) |
| 1943 | return err; |
| 1944 | } |
| 1945 | } |
| 1946 | } |
| 1947 | |
| 1948 | /* other nid->control mapping */ |
| 1949 | for (i = 0; i < spec->num_mixers; i++) { |
| 1950 | for (knew = spec->mixers[i]; knew->name; knew++) { |
| 1951 | if (knew->iface != NID_MAPPING) |
| 1952 | continue; |
| 1953 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 1954 | if (kctl == NULL) |
| 1955 | continue; |
| 1956 | u = knew->subdevice; |
| 1957 | for (j = 0; j < 4; j++, u >>= 8) { |
| 1958 | nid = u & 0x3f; |
| 1959 | if (nid == 0) |
| 1960 | continue; |
| 1961 | switch (u & 0xc0) { |
| 1962 | case SUBDEV_SPEAKER_: |
| 1963 | nid = spec->autocfg.speaker_pins[nid]; |
| 1964 | break; |
| 1965 | case SUBDEV_LINE_: |
| 1966 | nid = spec->autocfg.line_out_pins[nid]; |
| 1967 | break; |
| 1968 | case SUBDEV_HP_: |
| 1969 | nid = spec->autocfg.hp_pins[nid]; |
| 1970 | break; |
| 1971 | default: |
| 1972 | continue; |
| 1973 | } |
| 1974 | err = snd_hda_add_nid(codec, kctl, 0, nid); |
| 1975 | if (err < 0) |
| 1976 | return err; |
| 1977 | } |
| 1978 | u = knew->private_value; |
| 1979 | for (j = 0; j < 4; j++, u >>= 8) { |
| 1980 | nid = u & 0xff; |
| 1981 | if (nid == 0) |
| 1982 | continue; |
| 1983 | err = snd_hda_add_nid(codec, kctl, 0, nid); |
| 1984 | if (err < 0) |
| 1985 | return err; |
| 1986 | } |
| 1987 | } |
| 1988 | } |
Takashi Iwai | bae84e7 | 2010-03-22 08:30:20 +0100 | [diff] [blame] | 1989 | |
| 1990 | alc_free_kctls(codec); /* no longer needed */ |
| 1991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | return 0; |
| 1993 | } |
| 1994 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1995 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | /* |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 1997 | * Common callbacks |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1998 | */ |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 1999 | |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 2000 | static void alc_init_special_input_src(struct hda_codec *codec); |
| 2001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | static int alc_init(struct hda_codec *codec) |
| 2003 | { |
| 2004 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2005 | unsigned int i; |
| 2006 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 2007 | alc_fix_pll(codec); |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 2008 | alc_auto_init_amp(codec, spec->init_amp); |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 2009 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2010 | for (i = 0; i < spec->num_init_verbs; i++) |
| 2011 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 2012 | alc_init_special_input_src(codec); |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2013 | |
| 2014 | if (spec->init_hook) |
| 2015 | spec->init_hook(codec); |
| 2016 | |
Takashi Iwai | 5870112 | 2011-01-13 15:41:45 +0100 | [diff] [blame] | 2017 | alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT); |
| 2018 | |
Takashi Iwai | 9e5341b | 2010-09-21 09:57:06 +0200 | [diff] [blame] | 2019 | hda_call_check_power_status(codec, 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | return 0; |
| 2021 | } |
| 2022 | |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2023 | static void alc_unsol_event(struct hda_codec *codec, unsigned int res) |
| 2024 | { |
| 2025 | struct alc_spec *spec = codec->spec; |
| 2026 | |
| 2027 | if (spec->unsol_event) |
| 2028 | spec->unsol_event(codec, res); |
| 2029 | } |
| 2030 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2031 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2032 | static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 2033 | { |
| 2034 | struct alc_spec *spec = codec->spec; |
| 2035 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); |
| 2036 | } |
| 2037 | #endif |
| 2038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | /* |
| 2040 | * Analog playback callbacks |
| 2041 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2042 | static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2044 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | { |
| 2046 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 2047 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 2048 | hinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2051 | static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | struct hda_codec *codec, |
| 2053 | unsigned int stream_tag, |
| 2054 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2055 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | { |
| 2057 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 2058 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, |
| 2059 | stream_tag, format, substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2062 | static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2064 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | { |
| 2066 | struct alc_spec *spec = codec->spec; |
| 2067 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
| 2068 | } |
| 2069 | |
| 2070 | /* |
| 2071 | * Digital out |
| 2072 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2073 | static int alc_dig_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; |
| 2078 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 2079 | } |
| 2080 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2081 | static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 2082 | struct hda_codec *codec, |
| 2083 | unsigned int stream_tag, |
| 2084 | unsigned int format, |
| 2085 | struct snd_pcm_substream *substream) |
| 2086 | { |
| 2087 | struct alc_spec *spec = codec->spec; |
| 2088 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 2089 | stream_tag, format, substream); |
| 2090 | } |
| 2091 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2092 | static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 9b5f12e | 2009-02-13 11:47:37 +0100 | [diff] [blame] | 2093 | struct hda_codec *codec, |
| 2094 | struct snd_pcm_substream *substream) |
| 2095 | { |
| 2096 | struct alc_spec *spec = codec->spec; |
| 2097 | return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
| 2098 | } |
| 2099 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2100 | static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2102 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | { |
| 2104 | struct alc_spec *spec = codec->spec; |
| 2105 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 2106 | } |
| 2107 | |
| 2108 | /* |
| 2109 | * Analog capture |
| 2110 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2111 | static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | struct hda_codec *codec, |
| 2113 | unsigned int stream_tag, |
| 2114 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2115 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | { |
| 2117 | struct alc_spec *spec = codec->spec; |
| 2118 | |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2119 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | stream_tag, 0, format); |
| 2121 | return 0; |
| 2122 | } |
| 2123 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2124 | static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2126 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | { |
| 2128 | struct alc_spec *spec = codec->spec; |
| 2129 | |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 2130 | snd_hda_codec_cleanup_stream(codec, |
| 2131 | spec->adc_nids[substream->number + 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | return 0; |
| 2133 | } |
| 2134 | |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2135 | /* analog capture with dynamic dual-adc changes */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2136 | static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2137 | struct hda_codec *codec, |
| 2138 | unsigned int stream_tag, |
| 2139 | unsigned int format, |
| 2140 | struct snd_pcm_substream *substream) |
| 2141 | { |
| 2142 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2143 | 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] | 2144 | spec->cur_adc_stream_tag = stream_tag; |
| 2145 | spec->cur_adc_format = format; |
| 2146 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); |
| 2147 | return 0; |
| 2148 | } |
| 2149 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2150 | static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2151 | struct hda_codec *codec, |
| 2152 | struct snd_pcm_substream *substream) |
| 2153 | { |
| 2154 | struct alc_spec *spec = codec->spec; |
| 2155 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
| 2156 | spec->cur_adc = 0; |
| 2157 | return 0; |
| 2158 | } |
| 2159 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2160 | static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = { |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2161 | .substreams = 1, |
| 2162 | .channels_min = 2, |
| 2163 | .channels_max = 2, |
| 2164 | .nid = 0, /* fill later */ |
| 2165 | .ops = { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2166 | .prepare = dyn_adc_capture_pcm_prepare, |
| 2167 | .cleanup = dyn_adc_capture_pcm_cleanup |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2168 | }, |
| 2169 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | |
| 2171 | /* |
| 2172 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2173 | static const struct hda_pcm_stream alc_pcm_analog_playback = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | .substreams = 1, |
| 2175 | .channels_min = 2, |
| 2176 | .channels_max = 8, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2177 | /* NID is set in alc_build_pcms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2179 | .open = alc_playback_pcm_open, |
| 2180 | .prepare = alc_playback_pcm_prepare, |
| 2181 | .cleanup = alc_playback_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | }, |
| 2183 | }; |
| 2184 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2185 | static const struct hda_pcm_stream alc_pcm_analog_capture = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2186 | .substreams = 1, |
| 2187 | .channels_min = 2, |
| 2188 | .channels_max = 2, |
| 2189 | /* NID is set in alc_build_pcms */ |
| 2190 | }; |
| 2191 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2192 | static const struct hda_pcm_stream alc_pcm_analog_alt_playback = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2193 | .substreams = 1, |
| 2194 | .channels_min = 2, |
| 2195 | .channels_max = 2, |
| 2196 | /* NID is set in alc_build_pcms */ |
| 2197 | }; |
| 2198 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2199 | static const struct hda_pcm_stream alc_pcm_analog_alt_capture = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2200 | .substreams = 2, /* can be overridden */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | .channels_min = 2, |
| 2202 | .channels_max = 2, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2203 | /* NID is set in alc_build_pcms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2205 | .prepare = alc_alt_capture_pcm_prepare, |
| 2206 | .cleanup = alc_alt_capture_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | }, |
| 2208 | }; |
| 2209 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2210 | static const struct hda_pcm_stream alc_pcm_digital_playback = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | .substreams = 1, |
| 2212 | .channels_min = 2, |
| 2213 | .channels_max = 2, |
| 2214 | /* NID is set in alc_build_pcms */ |
| 2215 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2216 | .open = alc_dig_playback_pcm_open, |
| 2217 | .close = alc_dig_playback_pcm_close, |
| 2218 | .prepare = alc_dig_playback_pcm_prepare, |
| 2219 | .cleanup = alc_dig_playback_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | }, |
| 2221 | }; |
| 2222 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2223 | static const struct hda_pcm_stream alc_pcm_digital_capture = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | .substreams = 1, |
| 2225 | .channels_min = 2, |
| 2226 | .channels_max = 2, |
| 2227 | /* NID is set in alc_build_pcms */ |
| 2228 | }; |
| 2229 | |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 2230 | /* 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] | 2231 | static const struct hda_pcm_stream alc_pcm_null_stream = { |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 2232 | .substreams = 0, |
| 2233 | .channels_min = 0, |
| 2234 | .channels_max = 0, |
| 2235 | }; |
| 2236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | static int alc_build_pcms(struct hda_codec *codec) |
| 2238 | { |
| 2239 | struct alc_spec *spec = codec->spec; |
| 2240 | struct hda_pcm *info = spec->pcm_rec; |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2241 | const struct hda_pcm_stream *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | int i; |
| 2243 | |
| 2244 | codec->num_pcms = 1; |
| 2245 | codec->pcm_info = info; |
| 2246 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2247 | if (spec->no_analog) |
| 2248 | goto skip_analog; |
| 2249 | |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 2250 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), |
| 2251 | "%s Analog", codec->chip_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | info->name = spec->stream_name_analog; |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 2253 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2254 | if (spec->multiout.dac_nids > 0) { |
| 2255 | p = spec->stream_analog_playback; |
| 2256 | if (!p) |
| 2257 | p = &alc_pcm_analog_playback; |
| 2258 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2259 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; |
| 2260 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2261 | if (spec->adc_nids) { |
| 2262 | p = spec->stream_analog_capture; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2263 | if (!p) { |
| 2264 | if (spec->dyn_adc_switch) |
| 2265 | p = &dyn_adc_pcm_analog_capture; |
| 2266 | else |
| 2267 | p = &alc_pcm_analog_capture; |
| 2268 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2269 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2270 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 2271 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2273 | if (spec->channel_mode) { |
| 2274 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0; |
| 2275 | for (i = 0; i < spec->num_channel_mode; i++) { |
| 2276 | if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) { |
| 2277 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels; |
| 2278 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | } |
| 2280 | } |
| 2281 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2282 | skip_analog: |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2283 | /* SPDIF for stream index #1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 2285 | snprintf(spec->stream_name_digital, |
| 2286 | sizeof(spec->stream_name_digital), |
| 2287 | "%s Digital", codec->chip_name); |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2288 | codec->num_pcms = 2; |
Wu Fengguang | b25c9da | 2009-02-06 15:02:27 +0800 | [diff] [blame] | 2289 | codec->slave_dig_outs = spec->multiout.slave_dig_outs; |
Takashi Iwai | c06134d | 2006-10-11 18:49:13 +0200 | [diff] [blame] | 2290 | info = spec->pcm_rec + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | info->name = spec->stream_name_digital; |
Takashi Iwai | 8c44198 | 2009-01-20 18:30:20 +0100 | [diff] [blame] | 2292 | if (spec->dig_out_type) |
| 2293 | info->pcm_type = spec->dig_out_type; |
| 2294 | else |
| 2295 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2296 | if (spec->multiout.dig_out_nid) { |
| 2297 | p = spec->stream_digital_playback; |
| 2298 | if (!p) |
| 2299 | p = &alc_pcm_digital_playback; |
| 2300 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; |
| 2302 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2303 | if (spec->dig_in_nid) { |
| 2304 | p = spec->stream_digital_capture; |
| 2305 | if (!p) |
| 2306 | p = &alc_pcm_digital_capture; |
| 2307 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; |
| 2309 | } |
Takashi Iwai | 963f803 | 2008-08-11 10:04:40 +0200 | [diff] [blame] | 2310 | /* FIXME: do we need this for all Realtek codec models? */ |
| 2311 | codec->spdif_status_reset = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | } |
| 2313 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2314 | if (spec->no_analog) |
| 2315 | return 0; |
| 2316 | |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2317 | /* If the use of more than one ADC is requested for the current |
| 2318 | * model, configure a second analog capture-only PCM. |
| 2319 | */ |
| 2320 | /* Additional Analaog capture for index #2 */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2321 | if (spec->alt_dac_nid || spec->num_adc_nids > 1) { |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2322 | codec->num_pcms = 3; |
Takashi Iwai | c06134d | 2006-10-11 18:49:13 +0200 | [diff] [blame] | 2323 | info = spec->pcm_rec + 2; |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2324 | info->name = spec->stream_name_analog; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2325 | if (spec->alt_dac_nid) { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2326 | p = spec->stream_analog_alt_playback; |
| 2327 | if (!p) |
| 2328 | p = &alc_pcm_analog_alt_playback; |
| 2329 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2330 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 2331 | spec->alt_dac_nid; |
| 2332 | } else { |
| 2333 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 2334 | alc_pcm_null_stream; |
| 2335 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0; |
| 2336 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2337 | if (spec->num_adc_nids > 1) { |
| 2338 | p = spec->stream_analog_alt_capture; |
| 2339 | if (!p) |
| 2340 | p = &alc_pcm_analog_alt_capture; |
| 2341 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2342 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 2343 | spec->adc_nids[1]; |
| 2344 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = |
| 2345 | spec->num_adc_nids - 1; |
| 2346 | } else { |
| 2347 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 2348 | alc_pcm_null_stream; |
| 2349 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0; |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2350 | } |
| 2351 | } |
| 2352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | return 0; |
| 2354 | } |
| 2355 | |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2356 | static inline void alc_shutup(struct hda_codec *codec) |
| 2357 | { |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 2358 | struct alc_spec *spec = codec->spec; |
| 2359 | |
| 2360 | if (spec && spec->shutup) |
| 2361 | spec->shutup(codec); |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2362 | snd_hda_shutup_pins(codec); |
| 2363 | } |
| 2364 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2365 | static void alc_free_kctls(struct hda_codec *codec) |
| 2366 | { |
| 2367 | struct alc_spec *spec = codec->spec; |
| 2368 | |
| 2369 | if (spec->kctls.list) { |
| 2370 | struct snd_kcontrol_new *kctl = spec->kctls.list; |
| 2371 | int i; |
| 2372 | for (i = 0; i < spec->kctls.used; i++) |
| 2373 | kfree(kctl[i].name); |
| 2374 | } |
| 2375 | snd_array_free(&spec->kctls); |
| 2376 | } |
| 2377 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2378 | static void alc_free_bind_ctls(struct hda_codec *codec) |
| 2379 | { |
| 2380 | struct alc_spec *spec = codec->spec; |
| 2381 | if (spec->bind_ctls.list) { |
| 2382 | struct hda_bind_ctls **ctl = spec->bind_ctls.list; |
| 2383 | int i; |
| 2384 | for (i = 0; i < spec->bind_ctls.used; i++) |
| 2385 | kfree(ctl[i]); |
| 2386 | } |
| 2387 | snd_array_free(&spec->bind_ctls); |
| 2388 | } |
| 2389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | static void alc_free(struct hda_codec *codec) |
| 2391 | { |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2392 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2393 | |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2394 | if (!spec) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2395 | return; |
| 2396 | |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2397 | alc_shutup(codec); |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 2398 | snd_hda_input_jack_free(codec); |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2399 | alc_free_kctls(codec); |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2400 | alc_free_bind_ctls(codec); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2401 | kfree(spec); |
Kusanagi Kouichi | 680cd53 | 2009-02-05 00:00:58 +0900 | [diff] [blame] | 2402 | snd_hda_detach_beep_device(codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | } |
| 2404 | |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2405 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2406 | static void alc_power_eapd(struct hda_codec *codec) |
| 2407 | { |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 2408 | alc_auto_setup_eapd(codec, false); |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2409 | } |
| 2410 | |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2411 | static int alc_suspend(struct hda_codec *codec, pm_message_t state) |
| 2412 | { |
| 2413 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2414 | alc_shutup(codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2415 | if (spec && spec->power_hook) |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2416 | spec->power_hook(codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2417 | return 0; |
| 2418 | } |
| 2419 | #endif |
| 2420 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 2421 | #ifdef CONFIG_PM |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2422 | static int alc_resume(struct hda_codec *codec) |
| 2423 | { |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 2424 | msleep(150); /* to avoid pop noise */ |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2425 | codec->patch_ops.init(codec); |
| 2426 | snd_hda_codec_resume_amp(codec); |
| 2427 | snd_hda_codec_resume_cache(codec); |
Takashi Iwai | 9e5341b | 2010-09-21 09:57:06 +0200 | [diff] [blame] | 2428 | hda_call_check_power_status(codec, 0x01); |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2429 | return 0; |
| 2430 | } |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2431 | #endif |
| 2432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | /* |
| 2434 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 2435 | static const struct hda_codec_ops alc_patch_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | .build_controls = alc_build_controls, |
| 2437 | .build_pcms = alc_build_pcms, |
| 2438 | .init = alc_init, |
| 2439 | .free = alc_free, |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2440 | .unsol_event = alc_unsol_event, |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 2441 | #ifdef CONFIG_PM |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2442 | .resume = alc_resume, |
| 2443 | #endif |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2444 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2445 | .suspend = alc_suspend, |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2446 | .check_power_status = alc_check_power_status, |
| 2447 | #endif |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2448 | .reboot_notify = alc_shutup, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | }; |
| 2450 | |
Kailang Yang | c027ddc | 2010-03-19 11:33:06 +0100 | [diff] [blame] | 2451 | /* replace the codec chip_name with the given string */ |
| 2452 | static int alc_codec_rename(struct hda_codec *codec, const char *name) |
| 2453 | { |
| 2454 | kfree(codec->chip_name); |
| 2455 | codec->chip_name = kstrdup(name, GFP_KERNEL); |
| 2456 | if (!codec->chip_name) { |
| 2457 | alc_free(codec); |
| 2458 | return -ENOMEM; |
| 2459 | } |
| 2460 | return 0; |
| 2461 | } |
| 2462 | |
Takashi Iwai | 2fa522b | 2005-05-12 14:51:12 +0200 | [diff] [blame] | 2463 | /* |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2464 | * Automatic parse of I/O pins from the BIOS configuration |
| 2465 | */ |
| 2466 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2467 | enum { |
| 2468 | ALC_CTL_WIDGET_VOL, |
| 2469 | ALC_CTL_WIDGET_MUTE, |
| 2470 | ALC_CTL_BIND_MUTE, |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2471 | ALC_CTL_BIND_VOL, |
| 2472 | ALC_CTL_BIND_SW, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2473 | }; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2474 | static const struct snd_kcontrol_new alc_control_templates[] = { |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2475 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
| 2476 | HDA_CODEC_MUTE(NULL, 0, 0, 0), |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2477 | HDA_BIND_MUTE(NULL, 0, 0, 0), |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2478 | HDA_BIND_VOL(NULL, 0), |
| 2479 | HDA_BIND_SW(NULL, 0), |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2480 | }; |
| 2481 | |
| 2482 | /* add dynamic controls */ |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2483 | 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] | 2484 | int cidx, unsigned long val) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2485 | { |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2486 | struct snd_kcontrol_new *knew; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2487 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2488 | knew = alc_kcontrol_new(spec); |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2489 | if (!knew) |
| 2490 | return -ENOMEM; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2491 | *knew = alc_control_templates[type]; |
Paulo Marques | 543537b | 2005-06-23 00:09:02 -0700 | [diff] [blame] | 2492 | knew->name = kstrdup(name, GFP_KERNEL); |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2493 | if (!knew->name) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2494 | return -ENOMEM; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2495 | knew->index = cidx; |
Jaroslav Kysela | 4d02d1b | 2009-11-12 10:15:48 +0100 | [diff] [blame] | 2496 | if (get_amp_nid_(val)) |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 2497 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2498 | knew->private_value = val; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2499 | return 0; |
| 2500 | } |
| 2501 | |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2502 | static int add_control_with_pfx(struct alc_spec *spec, int type, |
| 2503 | const char *pfx, const char *dir, |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2504 | const char *sfx, int cidx, unsigned long val) |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2505 | { |
| 2506 | char name[32]; |
| 2507 | snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx); |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2508 | return add_control(spec, type, name, cidx, val); |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2509 | } |
| 2510 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2511 | #define add_pb_vol_ctrl(spec, type, pfx, val) \ |
| 2512 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val) |
| 2513 | #define add_pb_sw_ctrl(spec, type, pfx, val) \ |
| 2514 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val) |
| 2515 | #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \ |
| 2516 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val) |
| 2517 | #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \ |
| 2518 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val) |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2519 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2520 | static const char * const channel_name[4] = { |
| 2521 | "Front", "Surround", "CLFE", "Side" |
| 2522 | }; |
| 2523 | |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2524 | static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch, |
| 2525 | bool can_be_master, int *index) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2526 | { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2527 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2528 | |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2529 | *index = 0; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2530 | if (cfg->line_outs == 1 && !spec->multi_ios && |
| 2531 | !cfg->hp_outs && !cfg->speaker_outs && can_be_master) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2532 | return "Master"; |
| 2533 | |
| 2534 | switch (cfg->line_out_type) { |
| 2535 | case AUTO_PIN_SPEAKER_OUT: |
David Henningsson | ebbeb3d | 2011-03-04 14:08:30 +0100 | [diff] [blame] | 2536 | if (cfg->line_outs == 1) |
| 2537 | return "Speaker"; |
| 2538 | break; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2539 | case AUTO_PIN_HP_OUT: |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2540 | /* for multi-io case, only the primary out */ |
| 2541 | if (ch && spec->multi_ios) |
| 2542 | break; |
| 2543 | *index = ch; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2544 | return "Headphone"; |
| 2545 | default: |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2546 | if (cfg->line_outs == 1 && !spec->multi_ios) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2547 | return "PCM"; |
| 2548 | break; |
| 2549 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2550 | if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name))) |
| 2551 | return "PCM"; |
| 2552 | |
| 2553 | return channel_name[ch]; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2554 | } |
| 2555 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2556 | /* create input playback/capture controls for the given pin */ |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2557 | 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] | 2558 | const char *ctlname, int ctlidx, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 2559 | int idx, hda_nid_t mix_nid) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2560 | { |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 2561 | int err; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2562 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2563 | err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2564 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 2565 | if (err < 0) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2566 | return err; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2567 | err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2568 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 2569 | if (err < 0) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2570 | return err; |
| 2571 | return 0; |
| 2572 | } |
| 2573 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2574 | 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] | 2575 | { |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2576 | unsigned int pincap = snd_hda_query_pin_caps(codec, nid); |
| 2577 | return (pincap & AC_PINCAP_IN) != 0; |
| 2578 | } |
| 2579 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2580 | /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */ |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2581 | static int alc_auto_fill_adc_caps(struct hda_codec *codec) |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2582 | { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2583 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2584 | hda_nid_t nid; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2585 | hda_nid_t *adc_nids = spec->private_adc_nids; |
| 2586 | hda_nid_t *cap_nids = spec->private_capsrc_nids; |
| 2587 | int max_nums = ARRAY_SIZE(spec->private_adc_nids); |
| 2588 | bool indep_capsrc = false; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2589 | int i, nums = 0; |
| 2590 | |
| 2591 | nid = codec->start_nid; |
| 2592 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 2593 | hda_nid_t src; |
| 2594 | const hda_nid_t *list; |
| 2595 | unsigned int caps = get_wcaps(codec, nid); |
| 2596 | int type = get_wcaps_type(caps); |
| 2597 | |
| 2598 | if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL)) |
| 2599 | continue; |
| 2600 | adc_nids[nums] = nid; |
| 2601 | cap_nids[nums] = nid; |
| 2602 | src = nid; |
| 2603 | for (;;) { |
| 2604 | int n; |
| 2605 | type = get_wcaps_type(get_wcaps(codec, src)); |
| 2606 | if (type == AC_WID_PIN) |
| 2607 | break; |
| 2608 | if (type == AC_WID_AUD_SEL) { |
| 2609 | cap_nids[nums] = src; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2610 | indep_capsrc = true; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2611 | break; |
| 2612 | } |
| 2613 | n = snd_hda_get_conn_list(codec, src, &list); |
| 2614 | if (n > 1) { |
| 2615 | cap_nids[nums] = src; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2616 | indep_capsrc = true; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2617 | break; |
| 2618 | } else if (n != 1) |
| 2619 | break; |
| 2620 | src = *list; |
| 2621 | } |
| 2622 | if (++nums >= max_nums) |
| 2623 | break; |
| 2624 | } |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2625 | spec->adc_nids = spec->private_adc_nids; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2626 | spec->capsrc_nids = spec->private_capsrc_nids; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2627 | spec->num_adc_nids = nums; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2628 | return nums; |
| 2629 | } |
| 2630 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2631 | /* create playback/capture controls for input pins */ |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2632 | static int alc_auto_create_input_ctls(struct hda_codec *codec) |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2633 | { |
| 2634 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2635 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2636 | hda_nid_t mixer = spec->mixer_nid; |
Herton Ronaldo Krzesinski | 61b9b9b | 2009-01-28 09:16:33 -0200 | [diff] [blame] | 2637 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2638 | int num_adcs; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2639 | int i, c, err, idx, type_idx = 0; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2640 | const char *prev_label = NULL; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2641 | |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2642 | num_adcs = alc_auto_fill_adc_caps(codec); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2643 | if (num_adcs < 0) |
| 2644 | return 0; |
| 2645 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2646 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2647 | hda_nid_t pin; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2648 | const char *label; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2649 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2650 | pin = cfg->inputs[i].pin; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2651 | if (!alc_is_input_pin(codec, pin)) |
| 2652 | continue; |
| 2653 | |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2654 | label = hda_get_autocfg_input_label(codec, cfg, i); |
| 2655 | if (prev_label && !strcmp(label, prev_label)) |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2656 | type_idx++; |
| 2657 | else |
| 2658 | type_idx = 0; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2659 | prev_label = label; |
| 2660 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2661 | if (mixer) { |
| 2662 | idx = get_connection_index(codec, mixer, pin); |
| 2663 | if (idx >= 0) { |
| 2664 | err = new_analog_input(spec, pin, |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2665 | label, type_idx, |
| 2666 | idx, mixer); |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2667 | if (err < 0) |
| 2668 | return err; |
| 2669 | } |
| 2670 | } |
| 2671 | |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2672 | for (c = 0; c < num_adcs; c++) { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2673 | hda_nid_t cap = spec->capsrc_nids ? |
| 2674 | spec->capsrc_nids[c] : spec->adc_nids[c]; |
| 2675 | idx = get_connection_index(codec, cap, pin); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2676 | if (idx >= 0) { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2677 | spec->imux_pins[imux->num_items] = pin; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2678 | snd_hda_add_imux_item(imux, label, idx, NULL); |
| 2679 | break; |
| 2680 | } |
| 2681 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2682 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2683 | |
| 2684 | spec->num_mux_defs = 1; |
| 2685 | spec->input_mux = imux; |
| 2686 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2687 | return 0; |
| 2688 | } |
| 2689 | |
Takashi Iwai | f6c7e54 | 2008-02-12 18:32:23 +0100 | [diff] [blame] | 2690 | static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid, |
| 2691 | unsigned int pin_type) |
| 2692 | { |
| 2693 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 2694 | pin_type); |
| 2695 | /* unmute pin */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 2696 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
| 2697 | 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] | 2698 | AMP_OUT_UNMUTE); |
Takashi Iwai | f6c7e54 | 2008-02-12 18:32:23 +0100 | [diff] [blame] | 2699 | } |
| 2700 | |
Takashi Iwai | baba8ee | 2007-04-23 17:17:48 +0200 | [diff] [blame] | 2701 | static int get_pin_type(int line_out_type) |
| 2702 | { |
| 2703 | if (line_out_type == AUTO_PIN_HP_OUT) |
| 2704 | return PIN_HP; |
| 2705 | else |
| 2706 | return PIN_OUT; |
| 2707 | } |
| 2708 | |
Takashi Iwai | 0a7f532 | 2011-07-06 15:15:12 +0200 | [diff] [blame] | 2709 | static void alc_auto_init_analog_input(struct hda_codec *codec) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2710 | { |
| 2711 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2712 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2713 | int i; |
| 2714 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2715 | for (i = 0; i < cfg->num_inputs; i++) { |
| 2716 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2717 | if (alc_is_input_pin(codec, nid)) { |
Takashi Iwai | 30ea098 | 2010-09-16 18:47:56 +0200 | [diff] [blame] | 2718 | alc_set_input_pin(codec, nid, cfg->inputs[i].type); |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 2719 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2720 | snd_hda_codec_write(codec, nid, 0, |
| 2721 | AC_VERB_SET_AMP_GAIN_MUTE, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2722 | AMP_OUT_MUTE); |
| 2723 | } |
| 2724 | } |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 2725 | |
| 2726 | /* mute all loopback inputs */ |
| 2727 | if (spec->mixer_nid) { |
| 2728 | int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL); |
| 2729 | for (i = 0; i < nums; i++) |
| 2730 | snd_hda_codec_write(codec, spec->mixer_nid, 0, |
| 2731 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 2732 | AMP_IN_MUTE(i)); |
| 2733 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2734 | } |
| 2735 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2736 | /* convert from MIX nid to DAC */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2737 | 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] | 2738 | { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2739 | hda_nid_t list[5]; |
Takashi Iwai | 1304ac8 | 2011-04-06 15:16:21 +0200 | [diff] [blame] | 2740 | int i, num; |
| 2741 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 2742 | if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT) |
| 2743 | return nid; |
Takashi Iwai | 1304ac8 | 2011-04-06 15:16:21 +0200 | [diff] [blame] | 2744 | num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list)); |
| 2745 | for (i = 0; i < num; i++) { |
| 2746 | if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT) |
| 2747 | return list[i]; |
| 2748 | } |
| 2749 | return 0; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2750 | } |
| 2751 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2752 | /* go down to the selector widget before the mixer */ |
| 2753 | static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin) |
| 2754 | { |
| 2755 | hda_nid_t srcs[5]; |
| 2756 | int num = snd_hda_get_connections(codec, pin, srcs, |
| 2757 | ARRAY_SIZE(srcs)); |
| 2758 | if (num != 1 || |
| 2759 | get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL) |
| 2760 | return pin; |
| 2761 | return srcs[0]; |
| 2762 | } |
| 2763 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2764 | /* get MIX nid connected to the given pin targeted to DAC */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2765 | 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] | 2766 | hda_nid_t dac) |
| 2767 | { |
David Henningsson | cc1c452 | 2010-11-24 14:17:47 +0100 | [diff] [blame] | 2768 | hda_nid_t mix[5]; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2769 | int i, num; |
| 2770 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2771 | pin = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2772 | num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); |
| 2773 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2774 | if (alc_auto_mix_to_dac(codec, mix[i]) == dac) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2775 | return mix[i]; |
| 2776 | } |
| 2777 | return 0; |
| 2778 | } |
| 2779 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2780 | /* select the connection from pin to DAC if needed */ |
| 2781 | static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin, |
| 2782 | hda_nid_t dac) |
| 2783 | { |
| 2784 | hda_nid_t mix[5]; |
| 2785 | int i, num; |
| 2786 | |
| 2787 | pin = alc_go_down_to_selector(codec, pin); |
| 2788 | num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); |
| 2789 | if (num < 2) |
| 2790 | return 0; |
| 2791 | for (i = 0; i < num; i++) { |
| 2792 | if (alc_auto_mix_to_dac(codec, mix[i]) == dac) { |
| 2793 | snd_hda_codec_update_cache(codec, pin, 0, |
| 2794 | AC_VERB_SET_CONNECT_SEL, i); |
| 2795 | return 0; |
| 2796 | } |
| 2797 | } |
| 2798 | return 0; |
| 2799 | } |
| 2800 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2801 | /* look for an empty DAC slot */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2802 | 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] | 2803 | { |
| 2804 | struct alc_spec *spec = codec->spec; |
| 2805 | hda_nid_t srcs[5]; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2806 | int i, num; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2807 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2808 | pin = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2809 | num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs)); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2810 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2811 | hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2812 | if (!nid) |
| 2813 | continue; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2814 | if (found_in_nid_list(nid, spec->multiout.dac_nids, |
| 2815 | spec->multiout.num_dacs)) |
| 2816 | continue; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 2817 | if (found_in_nid_list(nid, spec->multiout.hp_out_nid, |
| 2818 | ARRAY_SIZE(spec->multiout.hp_out_nid))) |
| 2819 | continue; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2820 | if (found_in_nid_list(nid, spec->multiout.extra_out_nid, |
| 2821 | ARRAY_SIZE(spec->multiout.extra_out_nid))) |
| 2822 | continue; |
| 2823 | return nid; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2824 | } |
| 2825 | return 0; |
| 2826 | } |
| 2827 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2828 | static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin) |
| 2829 | { |
| 2830 | hda_nid_t sel = alc_go_down_to_selector(codec, pin); |
| 2831 | if (snd_hda_get_conn_list(codec, sel, NULL) == 1) |
| 2832 | return alc_auto_look_for_dac(codec, pin); |
| 2833 | return 0; |
| 2834 | } |
| 2835 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 2836 | static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs, |
| 2837 | const hda_nid_t *pins, hda_nid_t *dacs) |
| 2838 | { |
| 2839 | int i; |
| 2840 | |
| 2841 | if (num_outs && !dacs[0]) { |
| 2842 | dacs[0] = alc_auto_look_for_dac(codec, pins[0]); |
| 2843 | if (!dacs[0]) |
| 2844 | return 0; |
| 2845 | } |
| 2846 | |
| 2847 | for (i = 1; i < num_outs; i++) |
| 2848 | dacs[i] = get_dac_if_single(codec, pins[i]); |
| 2849 | for (i = 1; i < num_outs; i++) { |
| 2850 | if (!dacs[i]) |
| 2851 | dacs[i] = alc_auto_look_for_dac(codec, pins[i]); |
| 2852 | } |
| 2853 | return 0; |
| 2854 | } |
| 2855 | |
| 2856 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, |
| 2857 | unsigned int location); |
| 2858 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2859 | /* fill in the dac_nids table from the parsed pin configuration */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 2860 | static int alc_auto_fill_dac_nids(struct hda_codec *codec) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2861 | { |
| 2862 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | cb053a8 | 2011-06-27 11:32:07 +0200 | [diff] [blame] | 2863 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 350434e | 2011-06-30 21:29:12 +0200 | [diff] [blame] | 2864 | bool redone = false; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2865 | int i; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2866 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2867 | again: |
Takashi Iwai | 8f398ae | 2011-07-23 18:57:11 +0200 | [diff] [blame] | 2868 | /* set num_dacs once to full for alc_auto_look_for_dac() */ |
| 2869 | spec->multiout.num_dacs = cfg->line_outs; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 2870 | spec->multiout.hp_out_nid[0] = 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2871 | spec->multiout.extra_out_nid[0] = 0; |
| 2872 | memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids)); |
| 2873 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 2874 | |
| 2875 | /* fill hard-wired DACs first */ |
| 2876 | if (!redone) { |
| 2877 | for (i = 0; i < cfg->line_outs; i++) |
| 2878 | spec->private_dac_nids[i] = |
| 2879 | get_dac_if_single(codec, cfg->line_out_pins[i]); |
| 2880 | if (cfg->hp_outs) |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 2881 | spec->multiout.hp_out_nid[0] = |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2882 | get_dac_if_single(codec, cfg->hp_pins[0]); |
| 2883 | if (cfg->speaker_outs) |
| 2884 | spec->multiout.extra_out_nid[0] = |
| 2885 | get_dac_if_single(codec, cfg->speaker_pins[0]); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2886 | } |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2887 | |
| 2888 | for (i = 0; i < cfg->line_outs; i++) { |
| 2889 | hda_nid_t pin = cfg->line_out_pins[i]; |
| 2890 | if (spec->private_dac_nids[i]) |
| 2891 | continue; |
| 2892 | spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin); |
| 2893 | if (!spec->private_dac_nids[i] && !redone) { |
| 2894 | /* if we can't find primary DACs, re-probe without |
| 2895 | * checking the hard-wired DACs |
| 2896 | */ |
| 2897 | redone = true; |
| 2898 | goto again; |
| 2899 | } |
| 2900 | } |
| 2901 | |
Takashi Iwai | 8f398ae | 2011-07-23 18:57:11 +0200 | [diff] [blame] | 2902 | /* re-count num_dacs and squash invalid entries */ |
| 2903 | spec->multiout.num_dacs = 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2904 | for (i = 0; i < cfg->line_outs; i++) { |
| 2905 | if (spec->private_dac_nids[i]) |
| 2906 | spec->multiout.num_dacs++; |
| 2907 | else |
| 2908 | memmove(spec->private_dac_nids + i, |
| 2909 | spec->private_dac_nids + i + 1, |
| 2910 | sizeof(hda_nid_t) * (cfg->line_outs - i - 1)); |
| 2911 | } |
| 2912 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 2913 | if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
| 2914 | /* try to fill multi-io first */ |
| 2915 | unsigned int location, defcfg; |
| 2916 | int num_pins; |
Takashi Iwai | bb8bf4d | 2011-07-06 13:07:54 +0200 | [diff] [blame] | 2917 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 2918 | defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]); |
| 2919 | location = get_defcfg_location(defcfg); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2920 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 2921 | num_pins = alc_auto_fill_multi_ios(codec, location); |
| 2922 | if (num_pins > 0) { |
| 2923 | spec->multi_ios = num_pins; |
| 2924 | spec->ext_channel_count = 2; |
| 2925 | spec->multiout.num_dacs = num_pins + 1; |
| 2926 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2927 | } |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 2928 | |
| 2929 | alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins, |
| 2930 | spec->multiout.hp_out_nid); |
| 2931 | alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins, |
| 2932 | spec->multiout.extra_out_nid); |
| 2933 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2934 | return 0; |
| 2935 | } |
| 2936 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 2937 | static int alc_auto_add_vol_ctl(struct hda_codec *codec, |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 2938 | const char *pfx, int cidx, |
| 2939 | hda_nid_t nid, unsigned int chs) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 2940 | { |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 2941 | if (!nid) |
| 2942 | return 0; |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 2943 | return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, |
| 2944 | HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2945 | } |
| 2946 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 2947 | #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \ |
| 2948 | alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3) |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 2949 | |
| 2950 | /* create a mute-switch for the given mixer widget; |
| 2951 | * if it has multiple sources (e.g. DAC and loopback), create a bind-mute |
| 2952 | */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 2953 | static int alc_auto_add_sw_ctl(struct hda_codec *codec, |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 2954 | const char *pfx, int cidx, |
| 2955 | hda_nid_t nid, unsigned int chs) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2956 | { |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 2957 | int wid_type; |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 2958 | int type; |
| 2959 | unsigned long val; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 2960 | if (!nid) |
| 2961 | return 0; |
| 2962 | wid_type = get_wcaps_type(get_wcaps(codec, nid)); |
| 2963 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) { |
| 2964 | type = ALC_CTL_WIDGET_MUTE; |
| 2965 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); |
| 2966 | } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) { |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 2967 | type = ALC_CTL_WIDGET_MUTE; |
| 2968 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT); |
| 2969 | } else { |
| 2970 | type = ALC_CTL_BIND_MUTE; |
| 2971 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT); |
| 2972 | } |
| 2973 | return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2974 | } |
| 2975 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 2976 | #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \ |
| 2977 | alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2978 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 2979 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, |
| 2980 | hda_nid_t pin, hda_nid_t dac) |
| 2981 | { |
| 2982 | hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac); |
| 2983 | if (nid_has_mute(codec, pin, HDA_OUTPUT)) |
| 2984 | return pin; |
| 2985 | else if (mix && nid_has_mute(codec, mix, HDA_INPUT)) |
| 2986 | return mix; |
| 2987 | else if (nid_has_mute(codec, dac, HDA_OUTPUT)) |
| 2988 | return dac; |
| 2989 | return 0; |
| 2990 | } |
| 2991 | |
| 2992 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, |
| 2993 | hda_nid_t pin, hda_nid_t dac) |
| 2994 | { |
| 2995 | hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac); |
| 2996 | if (nid_has_volume(codec, dac, HDA_OUTPUT)) |
| 2997 | return dac; |
| 2998 | else if (nid_has_volume(codec, mix, HDA_OUTPUT)) |
| 2999 | return mix; |
| 3000 | else if (nid_has_volume(codec, pin, HDA_OUTPUT)) |
| 3001 | return pin; |
| 3002 | return 0; |
| 3003 | } |
| 3004 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3005 | /* add playback controls from the parsed DAC table */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3006 | static int alc_auto_create_multi_out_ctls(struct hda_codec *codec, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3007 | const struct auto_pin_cfg *cfg) |
| 3008 | { |
| 3009 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3010 | int i, err, noutputs; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3011 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3012 | noutputs = cfg->line_outs; |
| 3013 | if (spec->multi_ios > 0) |
| 3014 | noutputs += spec->multi_ios; |
| 3015 | |
| 3016 | for (i = 0; i < noutputs; i++) { |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 3017 | const char *name; |
| 3018 | int index; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3019 | hda_nid_t dac, pin; |
| 3020 | hda_nid_t sw, vol; |
| 3021 | |
| 3022 | dac = spec->multiout.dac_nids[i]; |
| 3023 | if (!dac) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3024 | continue; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3025 | if (i >= cfg->line_outs) |
| 3026 | pin = spec->multi_io[i - 1].pin; |
| 3027 | else |
| 3028 | pin = cfg->line_out_pins[i]; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3029 | |
| 3030 | sw = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3031 | vol = alc_look_for_out_vol_nid(codec, pin, dac); |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 3032 | name = alc_get_line_out_pfx(spec, i, true, &index); |
Takashi Iwai | 9c4e84d | 2011-08-24 17:27:52 +0200 | [diff] [blame] | 3033 | if (!name || !strcmp(name, "CLFE")) { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3034 | /* Center/LFE */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3035 | err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3036 | if (err < 0) |
| 3037 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3038 | err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3039 | if (err < 0) |
| 3040 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3041 | err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3042 | if (err < 0) |
| 3043 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3044 | err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3045 | if (err < 0) |
| 3046 | return err; |
| 3047 | } else { |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3048 | err = alc_auto_add_stereo_vol(codec, name, index, vol); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3049 | if (err < 0) |
| 3050 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3051 | err = alc_auto_add_stereo_sw(codec, name, index, sw); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3052 | if (err < 0) |
| 3053 | return err; |
| 3054 | } |
| 3055 | } |
| 3056 | return 0; |
| 3057 | } |
| 3058 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3059 | static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin, |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3060 | hda_nid_t dac, const char *pfx) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3061 | { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3062 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3063 | hda_nid_t sw, vol; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3064 | int err; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3065 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3066 | if (!dac) { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3067 | /* the corresponding DAC is already occupied */ |
| 3068 | if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)) |
| 3069 | return 0; /* no way */ |
| 3070 | /* create a switch only */ |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 3071 | return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3072 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 3073 | } |
| 3074 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3075 | sw = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3076 | vol = alc_look_for_out_vol_nid(codec, pin, dac); |
| 3077 | err = alc_auto_add_stereo_vol(codec, pfx, 0, vol); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3078 | if (err < 0) |
Takashi Iwai | 24fb917 | 2008-09-02 14:48:20 +0200 | [diff] [blame] | 3079 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3080 | err = alc_auto_add_stereo_sw(codec, pfx, 0, sw); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3081 | if (err < 0) |
| 3082 | return err; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3083 | return 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3084 | } |
| 3085 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3086 | static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec, |
| 3087 | unsigned int nums, |
| 3088 | struct hda_ctl_ops *ops) |
| 3089 | { |
| 3090 | struct alc_spec *spec = codec->spec; |
| 3091 | struct hda_bind_ctls **ctlp, *ctl; |
| 3092 | snd_array_init(&spec->bind_ctls, sizeof(ctl), 8); |
| 3093 | ctlp = snd_array_new(&spec->bind_ctls); |
| 3094 | if (!ctlp) |
| 3095 | return NULL; |
| 3096 | ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL); |
| 3097 | *ctlp = ctl; |
| 3098 | if (ctl) |
| 3099 | ctl->ops = ops; |
| 3100 | return ctl; |
| 3101 | } |
| 3102 | |
| 3103 | /* add playback controls for speaker and HP outputs */ |
| 3104 | static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins, |
| 3105 | const hda_nid_t *pins, |
| 3106 | const hda_nid_t *dacs, |
| 3107 | const char *pfx) |
| 3108 | { |
| 3109 | struct alc_spec *spec = codec->spec; |
| 3110 | struct hda_bind_ctls *ctl; |
| 3111 | char name[32]; |
| 3112 | int i, n, err; |
| 3113 | |
| 3114 | if (!num_pins || !pins[0]) |
| 3115 | return 0; |
| 3116 | |
| 3117 | if (num_pins == 1) |
| 3118 | return alc_auto_create_extra_out(codec, *pins, *dacs, pfx); |
| 3119 | |
| 3120 | if (dacs[num_pins - 1]) { |
| 3121 | /* OK, we have a multi-output system with individual volumes */ |
| 3122 | for (i = 0; i < num_pins; i++) { |
| 3123 | snprintf(name, sizeof(name), "%s %s", |
| 3124 | pfx, channel_name[i]); |
| 3125 | err = alc_auto_create_extra_out(codec, pins[i], dacs[i], |
| 3126 | name); |
| 3127 | if (err < 0) |
| 3128 | return err; |
| 3129 | } |
| 3130 | return 0; |
| 3131 | } |
| 3132 | |
| 3133 | /* Let's create a bind-controls */ |
| 3134 | ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw); |
| 3135 | if (!ctl) |
| 3136 | return -ENOMEM; |
| 3137 | n = 0; |
| 3138 | for (i = 0; i < num_pins; i++) { |
| 3139 | if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP) |
| 3140 | ctl->values[n++] = |
| 3141 | HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT); |
| 3142 | } |
| 3143 | if (n) { |
| 3144 | snprintf(name, sizeof(name), "%s Playback Switch", pfx); |
| 3145 | err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl); |
| 3146 | if (err < 0) |
| 3147 | return err; |
| 3148 | } |
| 3149 | |
| 3150 | ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol); |
| 3151 | if (!ctl) |
| 3152 | return -ENOMEM; |
| 3153 | n = 0; |
| 3154 | for (i = 0; i < num_pins; i++) { |
| 3155 | hda_nid_t vol; |
| 3156 | if (!pins[i] || !dacs[i]) |
| 3157 | continue; |
| 3158 | vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]); |
| 3159 | if (vol) |
| 3160 | ctl->values[n++] = |
| 3161 | HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT); |
| 3162 | } |
| 3163 | if (n) { |
| 3164 | snprintf(name, sizeof(name), "%s Playback Volume", pfx); |
| 3165 | err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl); |
| 3166 | if (err < 0) |
| 3167 | return err; |
| 3168 | } |
| 3169 | return 0; |
| 3170 | } |
| 3171 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3172 | static int alc_auto_create_hp_out(struct hda_codec *codec) |
| 3173 | { |
| 3174 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3175 | return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs, |
| 3176 | spec->autocfg.hp_pins, |
| 3177 | spec->multiout.hp_out_nid, |
| 3178 | "Headphone"); |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | static int alc_auto_create_speaker_out(struct hda_codec *codec) |
| 3182 | { |
| 3183 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3184 | return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs, |
| 3185 | spec->autocfg.speaker_pins, |
| 3186 | spec->multiout.extra_out_nid, |
| 3187 | "Speaker"); |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3188 | } |
| 3189 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3190 | static void alc_auto_set_output_and_unmute(struct hda_codec *codec, |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3191 | hda_nid_t pin, int pin_type, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3192 | hda_nid_t dac) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3193 | { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3194 | int i, num; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3195 | hda_nid_t nid, mix = 0; |
Takashi Iwai | ce503f3 | 2010-07-30 10:37:29 +0200 | [diff] [blame] | 3196 | hda_nid_t srcs[HDA_MAX_CONNECTIONS]; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3197 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3198 | alc_set_pin_output(codec, pin, pin_type); |
| 3199 | nid = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3200 | num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs)); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3201 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 3202 | if (alc_auto_mix_to_dac(codec, srcs[i]) != dac) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3203 | continue; |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3204 | mix = srcs[i]; |
| 3205 | break; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3206 | } |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3207 | if (!mix) |
| 3208 | return; |
| 3209 | |
| 3210 | /* need the manual connection? */ |
| 3211 | if (num > 1) |
| 3212 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i); |
| 3213 | /* unmute mixer widget inputs */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3214 | if (nid_has_mute(codec, mix, HDA_INPUT)) { |
| 3215 | 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] | 3216 | AMP_IN_UNMUTE(0)); |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3217 | 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] | 3218 | AMP_IN_UNMUTE(1)); |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3219 | } |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3220 | /* initialize volume */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3221 | nid = alc_look_for_out_vol_nid(codec, pin, dac); |
| 3222 | if (nid) |
| 3223 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 3224 | AMP_OUT_ZERO); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3225 | } |
| 3226 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3227 | static void alc_auto_init_multi_out(struct hda_codec *codec) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3228 | { |
| 3229 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3230 | int pin_type = get_pin_type(spec->autocfg.line_out_type); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3231 | int i; |
| 3232 | |
| 3233 | for (i = 0; i <= HDA_SIDE; i++) { |
| 3234 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; |
| 3235 | if (nid) |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3236 | alc_auto_set_output_and_unmute(codec, nid, pin_type, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3237 | spec->multiout.dac_nids[i]); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3238 | } |
| 3239 | } |
| 3240 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3241 | static void alc_auto_init_extra_out(struct hda_codec *codec) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3242 | { |
| 3243 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3244 | int i; |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3245 | hda_nid_t pin, dac; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3246 | |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3247 | for (i = 0; i < spec->autocfg.speaker_outs; i++) { |
| 3248 | pin = spec->autocfg.hp_pins[i]; |
| 3249 | if (!pin) |
| 3250 | break; |
| 3251 | dac = spec->multiout.hp_out_nid[i]; |
| 3252 | if (!dac) { |
| 3253 | if (i > 0 && spec->multiout.hp_out_nid[0]) |
| 3254 | dac = spec->multiout.hp_out_nid[0]; |
| 3255 | else |
| 3256 | dac = spec->multiout.dac_nids[0]; |
| 3257 | } |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3258 | alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac); |
| 3259 | } |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3260 | for (i = 0; i < spec->autocfg.speaker_outs; i++) { |
| 3261 | pin = spec->autocfg.speaker_pins[i]; |
| 3262 | if (!pin) |
| 3263 | break; |
| 3264 | dac = spec->multiout.extra_out_nid[i]; |
| 3265 | if (!dac) { |
| 3266 | if (i > 0 && spec->multiout.extra_out_nid[0]) |
| 3267 | dac = spec->multiout.extra_out_nid[0]; |
| 3268 | else |
| 3269 | dac = spec->multiout.dac_nids[0]; |
| 3270 | } |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3271 | alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac); |
| 3272 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3273 | } |
| 3274 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3275 | /* |
| 3276 | * multi-io helper |
| 3277 | */ |
| 3278 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, |
| 3279 | unsigned int location) |
| 3280 | { |
| 3281 | struct alc_spec *spec = codec->spec; |
| 3282 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3283 | hda_nid_t prime_dac = spec->private_dac_nids[0]; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3284 | int type, i, num_pins = 0; |
| 3285 | |
| 3286 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { |
| 3287 | for (i = 0; i < cfg->num_inputs; i++) { |
| 3288 | hda_nid_t nid = cfg->inputs[i].pin; |
| 3289 | hda_nid_t dac; |
| 3290 | unsigned int defcfg, caps; |
| 3291 | if (cfg->inputs[i].type != type) |
| 3292 | continue; |
| 3293 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
| 3294 | if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX) |
| 3295 | continue; |
| 3296 | if (location && get_defcfg_location(defcfg) != location) |
| 3297 | continue; |
| 3298 | caps = snd_hda_query_pin_caps(codec, nid); |
| 3299 | if (!(caps & AC_PINCAP_OUT)) |
| 3300 | continue; |
| 3301 | dac = alc_auto_look_for_dac(codec, nid); |
| 3302 | if (!dac) |
| 3303 | continue; |
| 3304 | spec->multi_io[num_pins].pin = nid; |
| 3305 | spec->multi_io[num_pins].dac = dac; |
| 3306 | num_pins++; |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3307 | spec->private_dac_nids[spec->multiout.num_dacs++] = dac; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3308 | } |
| 3309 | } |
| 3310 | spec->multiout.num_dacs = 1; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3311 | if (num_pins < 2) { |
| 3312 | /* clear up again */ |
| 3313 | memset(spec->private_dac_nids, 0, |
| 3314 | sizeof(spec->private_dac_nids)); |
| 3315 | spec->private_dac_nids[0] = prime_dac; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3316 | return 0; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3317 | } |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3318 | return num_pins; |
| 3319 | } |
| 3320 | |
| 3321 | static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol, |
| 3322 | struct snd_ctl_elem_info *uinfo) |
| 3323 | { |
| 3324 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3325 | struct alc_spec *spec = codec->spec; |
| 3326 | |
| 3327 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 3328 | uinfo->count = 1; |
| 3329 | uinfo->value.enumerated.items = spec->multi_ios + 1; |
| 3330 | if (uinfo->value.enumerated.item > spec->multi_ios) |
| 3331 | uinfo->value.enumerated.item = spec->multi_ios; |
| 3332 | sprintf(uinfo->value.enumerated.name, "%dch", |
| 3333 | (uinfo->value.enumerated.item + 1) * 2); |
| 3334 | return 0; |
| 3335 | } |
| 3336 | |
| 3337 | static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol, |
| 3338 | struct snd_ctl_elem_value *ucontrol) |
| 3339 | { |
| 3340 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3341 | struct alc_spec *spec = codec->spec; |
| 3342 | ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2; |
| 3343 | return 0; |
| 3344 | } |
| 3345 | |
| 3346 | static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output) |
| 3347 | { |
| 3348 | struct alc_spec *spec = codec->spec; |
| 3349 | hda_nid_t nid = spec->multi_io[idx].pin; |
| 3350 | |
| 3351 | if (!spec->multi_io[idx].ctl_in) |
| 3352 | spec->multi_io[idx].ctl_in = |
| 3353 | snd_hda_codec_read(codec, nid, 0, |
| 3354 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 3355 | if (output) { |
| 3356 | snd_hda_codec_update_cache(codec, nid, 0, |
| 3357 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 3358 | PIN_OUT); |
| 3359 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
| 3360 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
| 3361 | HDA_AMP_MUTE, 0); |
| 3362 | alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac); |
| 3363 | } else { |
| 3364 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
| 3365 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
| 3366 | HDA_AMP_MUTE, HDA_AMP_MUTE); |
| 3367 | snd_hda_codec_update_cache(codec, nid, 0, |
| 3368 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 3369 | spec->multi_io[idx].ctl_in); |
| 3370 | } |
| 3371 | return 0; |
| 3372 | } |
| 3373 | |
| 3374 | static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol, |
| 3375 | struct snd_ctl_elem_value *ucontrol) |
| 3376 | { |
| 3377 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3378 | struct alc_spec *spec = codec->spec; |
| 3379 | int i, ch; |
| 3380 | |
| 3381 | ch = ucontrol->value.enumerated.item[0]; |
| 3382 | if (ch < 0 || ch > spec->multi_ios) |
| 3383 | return -EINVAL; |
| 3384 | if (ch == (spec->ext_channel_count - 1) / 2) |
| 3385 | return 0; |
| 3386 | spec->ext_channel_count = (ch + 1) * 2; |
| 3387 | for (i = 0; i < spec->multi_ios; i++) |
| 3388 | alc_set_multi_io(codec, i, i < ch); |
| 3389 | spec->multiout.max_channels = spec->ext_channel_count; |
Takashi Iwai | 7b1655f | 2011-07-14 15:31:21 +0200 | [diff] [blame] | 3390 | if (spec->need_dac_fix && !spec->const_channel_count) |
| 3391 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3392 | return 1; |
| 3393 | } |
| 3394 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 3395 | static const struct snd_kcontrol_new alc_auto_channel_mode_enum = { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3396 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3397 | .name = "Channel Mode", |
| 3398 | .info = alc_auto_ch_mode_info, |
| 3399 | .get = alc_auto_ch_mode_get, |
| 3400 | .put = alc_auto_ch_mode_put, |
| 3401 | }; |
| 3402 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3403 | static int alc_auto_add_multi_channel_mode(struct hda_codec *codec) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3404 | { |
| 3405 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3406 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3407 | if (spec->multi_ios > 0) { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3408 | struct snd_kcontrol_new *knew; |
| 3409 | |
| 3410 | knew = alc_kcontrol_new(spec); |
| 3411 | if (!knew) |
| 3412 | return -ENOMEM; |
| 3413 | *knew = alc_auto_channel_mode_enum; |
| 3414 | knew->name = kstrdup("Channel Mode", GFP_KERNEL); |
| 3415 | if (!knew->name) |
| 3416 | return -ENOMEM; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3417 | } |
| 3418 | return 0; |
| 3419 | } |
| 3420 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3421 | /* filter out invalid adc_nids (and capsrc_nids) that don't give all |
| 3422 | * active input pins |
| 3423 | */ |
| 3424 | static void alc_remove_invalid_adc_nids(struct hda_codec *codec) |
| 3425 | { |
| 3426 | struct alc_spec *spec = codec->spec; |
| 3427 | const struct hda_input_mux *imux; |
| 3428 | hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)]; |
| 3429 | hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)]; |
| 3430 | int i, n, nums; |
| 3431 | |
| 3432 | imux = spec->input_mux; |
| 3433 | if (!imux) |
| 3434 | return; |
| 3435 | if (spec->dyn_adc_switch) |
| 3436 | return; |
| 3437 | |
| 3438 | nums = 0; |
| 3439 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 3440 | hda_nid_t cap = spec->private_capsrc_nids[n]; |
| 3441 | int num_conns = snd_hda_get_conn_list(codec, cap, NULL); |
| 3442 | for (i = 0; i < imux->num_items; i++) { |
| 3443 | hda_nid_t pin = spec->imux_pins[i]; |
| 3444 | if (pin) { |
| 3445 | if (get_connection_index(codec, cap, pin) < 0) |
| 3446 | break; |
| 3447 | } else if (num_conns <= imux->items[i].index) |
| 3448 | break; |
| 3449 | } |
| 3450 | if (i >= imux->num_items) { |
| 3451 | adc_nids[nums] = spec->private_adc_nids[n]; |
| 3452 | capsrc_nids[nums++] = cap; |
| 3453 | } |
| 3454 | } |
| 3455 | if (!nums) { |
| 3456 | /* check whether ADC-switch is possible */ |
| 3457 | if (!alc_check_dyn_adc_switch(codec)) { |
| 3458 | printk(KERN_WARNING "hda_codec: %s: no valid ADC found;" |
| 3459 | " using fallback 0x%x\n", |
| 3460 | codec->chip_name, spec->private_adc_nids[0]); |
| 3461 | spec->num_adc_nids = 1; |
| 3462 | spec->auto_mic = 0; |
| 3463 | return; |
| 3464 | } |
| 3465 | } else if (nums != spec->num_adc_nids) { |
| 3466 | memcpy(spec->private_adc_nids, adc_nids, |
| 3467 | nums * sizeof(hda_nid_t)); |
| 3468 | memcpy(spec->private_capsrc_nids, capsrc_nids, |
| 3469 | nums * sizeof(hda_nid_t)); |
| 3470 | spec->num_adc_nids = nums; |
| 3471 | } |
| 3472 | |
| 3473 | if (spec->auto_mic) |
| 3474 | alc_auto_mic_check_imux(codec); /* check auto-mic setups */ |
| 3475 | else if (spec->input_mux->num_items == 1) |
| 3476 | spec->num_adc_nids = 1; /* reduce to a single ADC */ |
| 3477 | } |
| 3478 | |
| 3479 | /* |
| 3480 | * initialize ADC paths |
| 3481 | */ |
| 3482 | static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx) |
| 3483 | { |
| 3484 | struct alc_spec *spec = codec->spec; |
| 3485 | hda_nid_t nid; |
| 3486 | |
| 3487 | nid = spec->adc_nids[adc_idx]; |
| 3488 | /* mute ADC */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3489 | if (nid_has_mute(codec, nid, HDA_INPUT)) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3490 | snd_hda_codec_write(codec, nid, 0, |
| 3491 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 3492 | AMP_IN_MUTE(0)); |
| 3493 | return; |
| 3494 | } |
| 3495 | if (!spec->capsrc_nids) |
| 3496 | return; |
| 3497 | nid = spec->capsrc_nids[adc_idx]; |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3498 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3499 | snd_hda_codec_write(codec, nid, 0, |
| 3500 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 3501 | AMP_OUT_MUTE); |
| 3502 | } |
| 3503 | |
| 3504 | static void alc_auto_init_input_src(struct hda_codec *codec) |
| 3505 | { |
| 3506 | struct alc_spec *spec = codec->spec; |
| 3507 | int c, nums; |
| 3508 | |
| 3509 | for (c = 0; c < spec->num_adc_nids; c++) |
| 3510 | alc_auto_init_adc(codec, c); |
| 3511 | if (spec->dyn_adc_switch) |
| 3512 | nums = 1; |
| 3513 | else |
| 3514 | nums = spec->num_adc_nids; |
| 3515 | for (c = 0; c < nums; c++) |
| 3516 | alc_mux_select(codec, 0, spec->cur_mux[c], true); |
| 3517 | } |
| 3518 | |
| 3519 | /* add mic boosts if needed */ |
| 3520 | static int alc_auto_add_mic_boost(struct hda_codec *codec) |
| 3521 | { |
| 3522 | struct alc_spec *spec = codec->spec; |
| 3523 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3524 | int i, err; |
| 3525 | int type_idx = 0; |
| 3526 | hda_nid_t nid; |
| 3527 | const char *prev_label = NULL; |
| 3528 | |
| 3529 | for (i = 0; i < cfg->num_inputs; i++) { |
| 3530 | if (cfg->inputs[i].type > AUTO_PIN_MIC) |
| 3531 | break; |
| 3532 | nid = cfg->inputs[i].pin; |
| 3533 | if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { |
| 3534 | const char *label; |
| 3535 | char boost_label[32]; |
| 3536 | |
| 3537 | label = hda_get_autocfg_input_label(codec, cfg, i); |
| 3538 | if (prev_label && !strcmp(label, prev_label)) |
| 3539 | type_idx++; |
| 3540 | else |
| 3541 | type_idx = 0; |
| 3542 | prev_label = label; |
| 3543 | |
| 3544 | snprintf(boost_label, sizeof(boost_label), |
| 3545 | "%s Boost Volume", label); |
| 3546 | err = add_control(spec, ALC_CTL_WIDGET_VOL, |
| 3547 | boost_label, type_idx, |
| 3548 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT)); |
| 3549 | if (err < 0) |
| 3550 | return err; |
| 3551 | } |
| 3552 | } |
| 3553 | return 0; |
| 3554 | } |
| 3555 | |
| 3556 | /* select or unmute the given capsrc route */ |
| 3557 | static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap, |
| 3558 | int idx) |
| 3559 | { |
| 3560 | if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) { |
| 3561 | snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx, |
| 3562 | HDA_AMP_MUTE, 0); |
| 3563 | } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) { |
| 3564 | snd_hda_codec_write_cache(codec, cap, 0, |
| 3565 | AC_VERB_SET_CONNECT_SEL, idx); |
| 3566 | } |
| 3567 | } |
| 3568 | |
| 3569 | /* set the default connection to that pin */ |
| 3570 | static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin) |
| 3571 | { |
| 3572 | struct alc_spec *spec = codec->spec; |
| 3573 | int i; |
| 3574 | |
| 3575 | if (!pin) |
| 3576 | return 0; |
| 3577 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 3578 | hda_nid_t cap = spec->capsrc_nids ? |
| 3579 | spec->capsrc_nids[i] : spec->adc_nids[i]; |
| 3580 | int idx; |
| 3581 | |
| 3582 | idx = get_connection_index(codec, cap, pin); |
| 3583 | if (idx < 0) |
| 3584 | continue; |
| 3585 | select_or_unmute_capsrc(codec, cap, idx); |
| 3586 | return i; /* return the found index */ |
| 3587 | } |
| 3588 | return -1; /* not found */ |
| 3589 | } |
| 3590 | |
| 3591 | /* initialize some special cases for input sources */ |
| 3592 | static void alc_init_special_input_src(struct hda_codec *codec) |
| 3593 | { |
| 3594 | struct alc_spec *spec = codec->spec; |
| 3595 | int i; |
| 3596 | |
| 3597 | for (i = 0; i < spec->autocfg.num_inputs; i++) |
| 3598 | init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin); |
| 3599 | } |
| 3600 | |
| 3601 | /* assign appropriate capture mixers */ |
| 3602 | static void set_capture_mixer(struct hda_codec *codec) |
| 3603 | { |
| 3604 | struct alc_spec *spec = codec->spec; |
| 3605 | static const struct snd_kcontrol_new *caps[2][3] = { |
| 3606 | { alc_capture_mixer_nosrc1, |
| 3607 | alc_capture_mixer_nosrc2, |
| 3608 | alc_capture_mixer_nosrc3 }, |
| 3609 | { alc_capture_mixer1, |
| 3610 | alc_capture_mixer2, |
| 3611 | alc_capture_mixer3 }, |
| 3612 | }; |
| 3613 | |
| 3614 | /* check whether either of ADC or MUX has a volume control */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3615 | if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3616 | if (!spec->capsrc_nids) |
| 3617 | return; /* no volume */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3618 | if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT)) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3619 | return; /* no volume in capsrc, too */ |
| 3620 | spec->vol_in_capsrc = 1; |
| 3621 | } |
| 3622 | |
| 3623 | if (spec->num_adc_nids > 0) { |
| 3624 | int mux = 0; |
| 3625 | int num_adcs = 0; |
| 3626 | |
| 3627 | if (spec->input_mux && spec->input_mux->num_items > 1) |
| 3628 | mux = 1; |
| 3629 | if (spec->auto_mic) { |
| 3630 | num_adcs = 1; |
| 3631 | mux = 0; |
| 3632 | } else if (spec->dyn_adc_switch) |
| 3633 | num_adcs = 1; |
| 3634 | if (!num_adcs) { |
| 3635 | if (spec->num_adc_nids > 3) |
| 3636 | spec->num_adc_nids = 3; |
| 3637 | else if (!spec->num_adc_nids) |
| 3638 | return; |
| 3639 | num_adcs = spec->num_adc_nids; |
| 3640 | } |
| 3641 | spec->cap_mixer = caps[mux][num_adcs - 1]; |
| 3642 | } |
| 3643 | } |
| 3644 | |
| 3645 | /* |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 3646 | * standard auto-parser initializations |
| 3647 | */ |
| 3648 | static void alc_auto_init_std(struct hda_codec *codec) |
| 3649 | { |
| 3650 | struct alc_spec *spec = codec->spec; |
| 3651 | alc_auto_init_multi_out(codec); |
| 3652 | alc_auto_init_extra_out(codec); |
| 3653 | alc_auto_init_analog_input(codec); |
| 3654 | alc_auto_init_input_src(codec); |
| 3655 | alc_auto_init_digital(codec); |
| 3656 | if (spec->unsol_event) |
| 3657 | alc_inithook(codec); |
| 3658 | } |
| 3659 | |
| 3660 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3661 | * Digital-beep handlers |
| 3662 | */ |
| 3663 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
| 3664 | #define set_beep_amp(spec, nid, idx, dir) \ |
| 3665 | ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir)) |
| 3666 | |
| 3667 | static const struct snd_pci_quirk beep_white_list[] = { |
| 3668 | SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1), |
| 3669 | SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1), |
| 3670 | SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1), |
| 3671 | SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1), |
| 3672 | SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1), |
| 3673 | {} |
| 3674 | }; |
| 3675 | |
| 3676 | static inline int has_cdefine_beep(struct hda_codec *codec) |
| 3677 | { |
| 3678 | struct alc_spec *spec = codec->spec; |
| 3679 | const struct snd_pci_quirk *q; |
| 3680 | q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list); |
| 3681 | if (q) |
| 3682 | return q->value; |
| 3683 | return spec->cdefine.enable_pcbeep; |
| 3684 | } |
| 3685 | #else |
| 3686 | #define set_beep_amp(spec, nid, idx, dir) /* NOP */ |
| 3687 | #define has_cdefine_beep(codec) 0 |
| 3688 | #endif |
| 3689 | |
| 3690 | /* parse the BIOS configuration and set up the alc_spec */ |
| 3691 | /* return 1 if successful, 0 if the proper config is not found, |
| 3692 | * or a negative error code |
| 3693 | */ |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3694 | static int alc_parse_auto_config(struct hda_codec *codec, |
| 3695 | const hda_nid_t *ignore_nids, |
| 3696 | const hda_nid_t *ssid_nids) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3697 | { |
| 3698 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3699 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3700 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3701 | |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 3702 | err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids, |
| 3703 | spec->parse_flags); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3704 | if (err < 0) |
| 3705 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3706 | if (!cfg->line_outs) { |
| 3707 | if (cfg->dig_outs || cfg->dig_in_pin) { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3708 | spec->multiout.max_channels = 2; |
| 3709 | spec->no_analog = 1; |
| 3710 | goto dig_only; |
| 3711 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3712 | return 0; /* can't find valid BIOS pin config */ |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3713 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3714 | |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3715 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->hp_outs > 0) { |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3716 | /* use HP as primary out */ |
| 3717 | cfg->speaker_outs = cfg->line_outs; |
| 3718 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 3719 | sizeof(cfg->speaker_pins)); |
| 3720 | cfg->line_outs = cfg->hp_outs; |
| 3721 | memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins)); |
| 3722 | cfg->hp_outs = 0; |
| 3723 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); |
| 3724 | cfg->line_out_type = AUTO_PIN_HP_OUT; |
| 3725 | } |
| 3726 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3727 | err = alc_auto_fill_dac_nids(codec); |
| 3728 | if (err < 0) |
| 3729 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3730 | err = alc_auto_add_multi_channel_mode(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3731 | if (err < 0) |
| 3732 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3733 | err = alc_auto_create_multi_out_ctls(codec, cfg); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3734 | if (err < 0) |
| 3735 | return err; |
| 3736 | err = alc_auto_create_hp_out(codec); |
| 3737 | if (err < 0) |
| 3738 | return err; |
| 3739 | err = alc_auto_create_speaker_out(codec); |
| 3740 | if (err < 0) |
| 3741 | return err; |
| 3742 | err = alc_auto_create_input_ctls(codec); |
| 3743 | if (err < 0) |
| 3744 | return err; |
| 3745 | |
| 3746 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3747 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3748 | dig_only: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3749 | alc_auto_parse_digital(codec); |
| 3750 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3751 | if (!spec->no_analog) |
| 3752 | alc_remove_invalid_adc_nids(codec); |
| 3753 | |
| 3754 | if (ssid_nids) |
| 3755 | alc_ssid_check(codec, ssid_nids); |
| 3756 | |
| 3757 | if (!spec->no_analog) { |
| 3758 | alc_auto_check_switches(codec); |
| 3759 | err = alc_auto_add_mic_boost(codec); |
| 3760 | if (err < 0) |
| 3761 | return err; |
| 3762 | } |
| 3763 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3764 | if (spec->kctls.list) |
| 3765 | add_mixer(spec, spec->kctls.list); |
| 3766 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3767 | return 1; |
| 3768 | } |
| 3769 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3770 | static int alc880_parse_auto_config(struct hda_codec *codec) |
| 3771 | { |
| 3772 | static const hda_nid_t alc880_ignore[] = { 0x1d, 0 }; |
| 3773 | static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 3774 | return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids); |
| 3775 | } |
| 3776 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3777 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3778 | static const struct hda_amp_list alc880_loopbacks[] = { |
| 3779 | { 0x0b, HDA_INPUT, 0 }, |
| 3780 | { 0x0b, HDA_INPUT, 1 }, |
| 3781 | { 0x0b, HDA_INPUT, 2 }, |
| 3782 | { 0x0b, HDA_INPUT, 3 }, |
| 3783 | { 0x0b, HDA_INPUT, 4 }, |
| 3784 | { } /* end */ |
| 3785 | }; |
| 3786 | #endif |
| 3787 | |
| 3788 | /* |
| 3789 | * board setups |
| 3790 | */ |
| 3791 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 3792 | #define alc_board_config \ |
| 3793 | snd_hda_check_board_config |
| 3794 | #define alc_board_codec_sid_config \ |
| 3795 | snd_hda_check_board_codec_sid_config |
| 3796 | #include "alc_quirks.c" |
| 3797 | #else |
| 3798 | #define alc_board_config(codec, nums, models, tbl) -1 |
| 3799 | #define alc_board_codec_sid_config(codec, nums, models, tbl) -1 |
| 3800 | #define setup_preset(codec, x) /* NOP */ |
| 3801 | #endif |
| 3802 | |
| 3803 | /* |
| 3804 | * OK, here we have finally the patch for ALC880 |
| 3805 | */ |
| 3806 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 3807 | #include "alc880_quirks.c" |
| 3808 | #endif |
| 3809 | |
| 3810 | static int patch_alc880(struct hda_codec *codec) |
| 3811 | { |
| 3812 | struct alc_spec *spec; |
| 3813 | int board_config; |
| 3814 | int err; |
| 3815 | |
| 3816 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 3817 | if (spec == NULL) |
| 3818 | return -ENOMEM; |
| 3819 | |
| 3820 | codec->spec = spec; |
| 3821 | |
| 3822 | spec->mixer_nid = 0x0b; |
Takashi Iwai | 7b1655f | 2011-07-14 15:31:21 +0200 | [diff] [blame] | 3823 | spec->need_dac_fix = 1; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3824 | |
| 3825 | board_config = alc_board_config(codec, ALC880_MODEL_LAST, |
| 3826 | alc880_models, alc880_cfg_tbl); |
| 3827 | if (board_config < 0) { |
| 3828 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 3829 | codec->chip_name); |
| 3830 | board_config = ALC_MODEL_AUTO; |
| 3831 | } |
| 3832 | |
| 3833 | if (board_config == ALC_MODEL_AUTO) { |
| 3834 | /* automatic parse from the BIOS config */ |
| 3835 | err = alc880_parse_auto_config(codec); |
| 3836 | if (err < 0) { |
| 3837 | alc_free(codec); |
| 3838 | return err; |
| 3839 | } |
| 3840 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 3841 | else if (!err) { |
| 3842 | printk(KERN_INFO |
| 3843 | "hda_codec: Cannot set up configuration " |
| 3844 | "from BIOS. Using 3-stack mode...\n"); |
| 3845 | board_config = ALC880_3ST; |
| 3846 | } |
| 3847 | #endif |
| 3848 | } |
| 3849 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3850 | if (board_config != ALC_MODEL_AUTO) |
| 3851 | setup_preset(codec, &alc880_presets[board_config]); |
| 3852 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 3853 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3854 | alc_auto_fill_adc_caps(codec); |
| 3855 | alc_rebuild_imux_for_auto_mic(codec); |
| 3856 | alc_remove_invalid_adc_nids(codec); |
| 3857 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3858 | |
| 3859 | if (!spec->no_analog && !spec->cap_mixer) |
| 3860 | set_capture_mixer(codec); |
| 3861 | |
| 3862 | if (!spec->no_analog) { |
| 3863 | err = snd_hda_attach_beep_device(codec, 0x1); |
| 3864 | if (err < 0) { |
| 3865 | alc_free(codec); |
| 3866 | return err; |
| 3867 | } |
| 3868 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 3869 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3870 | |
| 3871 | spec->vmaster_nid = 0x0c; |
| 3872 | |
| 3873 | codec->patch_ops = alc_patch_ops; |
| 3874 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 3875 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3876 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3877 | if (!spec->loopback.amplist) |
| 3878 | spec->loopback.amplist = alc880_loopbacks; |
| 3879 | #endif |
| 3880 | |
| 3881 | return 0; |
| 3882 | } |
| 3883 | |
| 3884 | |
| 3885 | /* |
| 3886 | * ALC260 support |
| 3887 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3888 | static int alc260_parse_auto_config(struct hda_codec *codec) |
| 3889 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3890 | static const hda_nid_t alc260_ignore[] = { 0x17, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3891 | static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 }; |
| 3892 | return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3893 | } |
| 3894 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3895 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3896 | static const struct hda_amp_list alc260_loopbacks[] = { |
| 3897 | { 0x07, HDA_INPUT, 0 }, |
| 3898 | { 0x07, HDA_INPUT, 1 }, |
| 3899 | { 0x07, HDA_INPUT, 2 }, |
| 3900 | { 0x07, HDA_INPUT, 3 }, |
| 3901 | { 0x07, HDA_INPUT, 4 }, |
| 3902 | { } /* end */ |
| 3903 | }; |
| 3904 | #endif |
| 3905 | |
| 3906 | /* |
| 3907 | * Pin config fixes |
| 3908 | */ |
| 3909 | enum { |
| 3910 | PINFIX_HP_DC5750, |
| 3911 | }; |
| 3912 | |
| 3913 | static const struct alc_fixup alc260_fixups[] = { |
| 3914 | [PINFIX_HP_DC5750] = { |
| 3915 | .type = ALC_FIXUP_PINS, |
| 3916 | .v.pins = (const struct alc_pincfg[]) { |
| 3917 | { 0x11, 0x90130110 }, /* speaker */ |
| 3918 | { } |
| 3919 | } |
| 3920 | }, |
| 3921 | }; |
| 3922 | |
| 3923 | static const struct snd_pci_quirk alc260_fixup_tbl[] = { |
| 3924 | SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750), |
| 3925 | {} |
| 3926 | }; |
| 3927 | |
| 3928 | /* |
| 3929 | */ |
| 3930 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 3931 | #include "alc260_quirks.c" |
| 3932 | #endif |
| 3933 | |
| 3934 | static int patch_alc260(struct hda_codec *codec) |
| 3935 | { |
| 3936 | struct alc_spec *spec; |
| 3937 | int err, board_config; |
| 3938 | |
| 3939 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 3940 | if (spec == NULL) |
| 3941 | return -ENOMEM; |
| 3942 | |
| 3943 | codec->spec = spec; |
| 3944 | |
| 3945 | spec->mixer_nid = 0x07; |
| 3946 | |
| 3947 | board_config = alc_board_config(codec, ALC260_MODEL_LAST, |
| 3948 | alc260_models, alc260_cfg_tbl); |
| 3949 | if (board_config < 0) { |
| 3950 | snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 3951 | codec->chip_name); |
| 3952 | board_config = ALC_MODEL_AUTO; |
| 3953 | } |
| 3954 | |
| 3955 | if (board_config == ALC_MODEL_AUTO) { |
| 3956 | alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); |
| 3957 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 3958 | } |
| 3959 | |
| 3960 | if (board_config == ALC_MODEL_AUTO) { |
| 3961 | /* automatic parse from the BIOS config */ |
| 3962 | err = alc260_parse_auto_config(codec); |
| 3963 | if (err < 0) { |
| 3964 | alc_free(codec); |
| 3965 | return err; |
| 3966 | } |
| 3967 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 3968 | else if (!err) { |
| 3969 | printk(KERN_INFO |
| 3970 | "hda_codec: Cannot set up configuration " |
| 3971 | "from BIOS. Using base mode...\n"); |
| 3972 | board_config = ALC260_BASIC; |
| 3973 | } |
| 3974 | #endif |
| 3975 | } |
| 3976 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3977 | if (board_config != ALC_MODEL_AUTO) |
| 3978 | setup_preset(codec, &alc260_presets[board_config]); |
| 3979 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 3980 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3981 | alc_auto_fill_adc_caps(codec); |
| 3982 | alc_rebuild_imux_for_auto_mic(codec); |
| 3983 | alc_remove_invalid_adc_nids(codec); |
| 3984 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3985 | |
| 3986 | if (!spec->no_analog && !spec->cap_mixer) |
| 3987 | set_capture_mixer(codec); |
| 3988 | |
| 3989 | if (!spec->no_analog) { |
| 3990 | err = snd_hda_attach_beep_device(codec, 0x1); |
| 3991 | if (err < 0) { |
| 3992 | alc_free(codec); |
| 3993 | return err; |
| 3994 | } |
| 3995 | set_beep_amp(spec, 0x07, 0x05, HDA_INPUT); |
| 3996 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3997 | |
| 3998 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 3999 | |
| 4000 | spec->vmaster_nid = 0x08; |
| 4001 | |
| 4002 | codec->patch_ops = alc_patch_ops; |
| 4003 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | 8452a98 | 2011-07-08 16:19:48 +0200 | [diff] [blame] | 4004 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4005 | spec->shutup = alc_eapd_shutup; |
| 4006 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4007 | if (!spec->loopback.amplist) |
| 4008 | spec->loopback.amplist = alc260_loopbacks; |
| 4009 | #endif |
| 4010 | |
| 4011 | return 0; |
| 4012 | } |
| 4013 | |
| 4014 | |
| 4015 | /* |
| 4016 | * ALC882/883/885/888/889 support |
| 4017 | * |
| 4018 | * ALC882 is almost identical with ALC880 but has cleaner and more flexible |
| 4019 | * configuration. Each pin widget can choose any input DACs and a mixer. |
| 4020 | * Each ADC is connected from a mixer of all inputs. This makes possible |
| 4021 | * 6-channel independent captures. |
| 4022 | * |
| 4023 | * In addition, an independent DAC for the multi-playback (not used in this |
| 4024 | * driver yet). |
| 4025 | */ |
| 4026 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4027 | #define alc882_loopbacks alc880_loopbacks |
| 4028 | #endif |
| 4029 | |
| 4030 | /* |
| 4031 | * Pin config fixes |
| 4032 | */ |
| 4033 | enum { |
| 4034 | PINFIX_ABIT_AW9D_MAX, |
| 4035 | PINFIX_LENOVO_Y530, |
| 4036 | PINFIX_PB_M5210, |
| 4037 | PINFIX_ACER_ASPIRE_7736, |
| 4038 | }; |
| 4039 | |
| 4040 | static const struct alc_fixup alc882_fixups[] = { |
| 4041 | [PINFIX_ABIT_AW9D_MAX] = { |
| 4042 | .type = ALC_FIXUP_PINS, |
| 4043 | .v.pins = (const struct alc_pincfg[]) { |
| 4044 | { 0x15, 0x01080104 }, /* side */ |
| 4045 | { 0x16, 0x01011012 }, /* rear */ |
| 4046 | { 0x17, 0x01016011 }, /* clfe */ |
| 4047 | { } |
| 4048 | } |
| 4049 | }, |
| 4050 | [PINFIX_LENOVO_Y530] = { |
| 4051 | .type = ALC_FIXUP_PINS, |
| 4052 | .v.pins = (const struct alc_pincfg[]) { |
| 4053 | { 0x15, 0x99130112 }, /* rear int speakers */ |
| 4054 | { 0x16, 0x99130111 }, /* subwoofer */ |
| 4055 | { } |
| 4056 | } |
| 4057 | }, |
| 4058 | [PINFIX_PB_M5210] = { |
| 4059 | .type = ALC_FIXUP_VERBS, |
| 4060 | .v.verbs = (const struct hda_verb[]) { |
| 4061 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, |
| 4062 | {} |
| 4063 | } |
| 4064 | }, |
| 4065 | [PINFIX_ACER_ASPIRE_7736] = { |
| 4066 | .type = ALC_FIXUP_SKU, |
| 4067 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
| 4068 | }, |
| 4069 | }; |
| 4070 | |
| 4071 | static const struct snd_pci_quirk alc882_fixup_tbl[] = { |
| 4072 | SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210), |
| 4073 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530), |
| 4074 | SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX), |
| 4075 | SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736), |
| 4076 | {} |
| 4077 | }; |
| 4078 | |
| 4079 | /* |
| 4080 | * BIOS auto configuration |
| 4081 | */ |
| 4082 | /* almost identical with ALC880 parser... */ |
| 4083 | static int alc882_parse_auto_config(struct hda_codec *codec) |
| 4084 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4085 | static const hda_nid_t alc882_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4086 | static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 4087 | return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4088 | } |
| 4089 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4090 | /* |
| 4091 | */ |
| 4092 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4093 | #include "alc882_quirks.c" |
| 4094 | #endif |
| 4095 | |
| 4096 | static int patch_alc882(struct hda_codec *codec) |
| 4097 | { |
| 4098 | struct alc_spec *spec; |
| 4099 | int err, board_config; |
| 4100 | |
| 4101 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4102 | if (spec == NULL) |
| 4103 | return -ENOMEM; |
| 4104 | |
| 4105 | codec->spec = spec; |
| 4106 | |
| 4107 | spec->mixer_nid = 0x0b; |
| 4108 | |
| 4109 | switch (codec->vendor_id) { |
| 4110 | case 0x10ec0882: |
| 4111 | case 0x10ec0885: |
| 4112 | break; |
| 4113 | default: |
| 4114 | /* ALC883 and variants */ |
| 4115 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); |
| 4116 | break; |
| 4117 | } |
| 4118 | |
| 4119 | board_config = alc_board_config(codec, ALC882_MODEL_LAST, |
| 4120 | alc882_models, alc882_cfg_tbl); |
| 4121 | |
| 4122 | if (board_config < 0) |
| 4123 | board_config = alc_board_codec_sid_config(codec, |
| 4124 | ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl); |
| 4125 | |
| 4126 | if (board_config < 0) { |
| 4127 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 4128 | codec->chip_name); |
| 4129 | board_config = ALC_MODEL_AUTO; |
| 4130 | } |
| 4131 | |
| 4132 | if (board_config == ALC_MODEL_AUTO) { |
| 4133 | alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups); |
| 4134 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 4135 | } |
| 4136 | |
| 4137 | alc_auto_parse_customize_define(codec); |
| 4138 | |
| 4139 | if (board_config == ALC_MODEL_AUTO) { |
| 4140 | /* automatic parse from the BIOS config */ |
| 4141 | err = alc882_parse_auto_config(codec); |
| 4142 | if (err < 0) { |
| 4143 | alc_free(codec); |
| 4144 | return err; |
| 4145 | } |
| 4146 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4147 | else if (!err) { |
| 4148 | printk(KERN_INFO |
| 4149 | "hda_codec: Cannot set up configuration " |
| 4150 | "from BIOS. Using base mode...\n"); |
| 4151 | board_config = ALC882_3ST_DIG; |
| 4152 | } |
| 4153 | #endif |
| 4154 | } |
| 4155 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4156 | if (board_config != ALC_MODEL_AUTO) |
| 4157 | setup_preset(codec, &alc882_presets[board_config]); |
| 4158 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4159 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4160 | alc_auto_fill_adc_caps(codec); |
| 4161 | alc_rebuild_imux_for_auto_mic(codec); |
| 4162 | alc_remove_invalid_adc_nids(codec); |
| 4163 | } |
| 4164 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4165 | if (!spec->no_analog && !spec->cap_mixer) |
| 4166 | set_capture_mixer(codec); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4167 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4168 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 4169 | err = snd_hda_attach_beep_device(codec, 0x1); |
| 4170 | if (err < 0) { |
| 4171 | alc_free(codec); |
| 4172 | return err; |
| 4173 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4174 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4175 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4176 | |
| 4177 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4178 | |
| 4179 | spec->vmaster_nid = 0x0c; |
| 4180 | |
| 4181 | codec->patch_ops = alc_patch_ops; |
| 4182 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 4183 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4184 | |
| 4185 | alc_init_jacks(codec); |
| 4186 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4187 | if (!spec->loopback.amplist) |
| 4188 | spec->loopback.amplist = alc882_loopbacks; |
| 4189 | #endif |
| 4190 | |
| 4191 | return 0; |
| 4192 | } |
| 4193 | |
| 4194 | |
| 4195 | /* |
| 4196 | * ALC262 support |
| 4197 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4198 | static int alc262_parse_auto_config(struct hda_codec *codec) |
| 4199 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4200 | static const hda_nid_t alc262_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4201 | static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 4202 | return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4203 | } |
| 4204 | |
| 4205 | /* |
| 4206 | * Pin config fixes |
| 4207 | */ |
| 4208 | enum { |
| 4209 | PINFIX_FSC_H270, |
| 4210 | PINFIX_HP_Z200, |
| 4211 | }; |
| 4212 | |
| 4213 | static const struct alc_fixup alc262_fixups[] = { |
| 4214 | [PINFIX_FSC_H270] = { |
| 4215 | .type = ALC_FIXUP_PINS, |
| 4216 | .v.pins = (const struct alc_pincfg[]) { |
| 4217 | { 0x14, 0x99130110 }, /* speaker */ |
| 4218 | { 0x15, 0x0221142f }, /* front HP */ |
| 4219 | { 0x1b, 0x0121141f }, /* rear HP */ |
| 4220 | { } |
| 4221 | } |
| 4222 | }, |
| 4223 | [PINFIX_HP_Z200] = { |
| 4224 | .type = ALC_FIXUP_PINS, |
| 4225 | .v.pins = (const struct alc_pincfg[]) { |
| 4226 | { 0x16, 0x99130120 }, /* internal speaker */ |
| 4227 | { } |
| 4228 | } |
| 4229 | }, |
| 4230 | }; |
| 4231 | |
| 4232 | static const struct snd_pci_quirk alc262_fixup_tbl[] = { |
| 4233 | SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200), |
| 4234 | SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270), |
| 4235 | {} |
| 4236 | }; |
| 4237 | |
| 4238 | |
| 4239 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4240 | #define alc262_loopbacks alc880_loopbacks |
| 4241 | #endif |
| 4242 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4243 | /* |
| 4244 | */ |
| 4245 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4246 | #include "alc262_quirks.c" |
| 4247 | #endif |
| 4248 | |
| 4249 | static int patch_alc262(struct hda_codec *codec) |
| 4250 | { |
| 4251 | struct alc_spec *spec; |
| 4252 | int board_config; |
| 4253 | int err; |
| 4254 | |
| 4255 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4256 | if (spec == NULL) |
| 4257 | return -ENOMEM; |
| 4258 | |
| 4259 | codec->spec = spec; |
| 4260 | |
| 4261 | spec->mixer_nid = 0x0b; |
| 4262 | |
| 4263 | #if 0 |
| 4264 | /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is |
| 4265 | * under-run |
| 4266 | */ |
| 4267 | { |
| 4268 | int tmp; |
| 4269 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 4270 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 4271 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 4272 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80); |
| 4273 | } |
| 4274 | #endif |
| 4275 | alc_auto_parse_customize_define(codec); |
| 4276 | |
| 4277 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); |
| 4278 | |
| 4279 | board_config = alc_board_config(codec, ALC262_MODEL_LAST, |
| 4280 | alc262_models, alc262_cfg_tbl); |
| 4281 | |
| 4282 | if (board_config < 0) { |
| 4283 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 4284 | codec->chip_name); |
| 4285 | board_config = ALC_MODEL_AUTO; |
| 4286 | } |
| 4287 | |
| 4288 | if (board_config == ALC_MODEL_AUTO) { |
| 4289 | alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups); |
| 4290 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 4291 | } |
| 4292 | |
| 4293 | if (board_config == ALC_MODEL_AUTO) { |
| 4294 | /* automatic parse from the BIOS config */ |
| 4295 | err = alc262_parse_auto_config(codec); |
| 4296 | if (err < 0) { |
| 4297 | alc_free(codec); |
| 4298 | return err; |
| 4299 | } |
| 4300 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4301 | else if (!err) { |
| 4302 | printk(KERN_INFO |
| 4303 | "hda_codec: Cannot set up configuration " |
| 4304 | "from BIOS. Using base mode...\n"); |
| 4305 | board_config = ALC262_BASIC; |
| 4306 | } |
| 4307 | #endif |
| 4308 | } |
| 4309 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4310 | if (board_config != ALC_MODEL_AUTO) |
| 4311 | setup_preset(codec, &alc262_presets[board_config]); |
| 4312 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4313 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4314 | alc_auto_fill_adc_caps(codec); |
| 4315 | alc_rebuild_imux_for_auto_mic(codec); |
| 4316 | alc_remove_invalid_adc_nids(codec); |
| 4317 | } |
| 4318 | |
| 4319 | if (!spec->no_analog && !spec->cap_mixer) |
| 4320 | set_capture_mixer(codec); |
| 4321 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4322 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 4323 | err = snd_hda_attach_beep_device(codec, 0x1); |
| 4324 | if (err < 0) { |
| 4325 | alc_free(codec); |
| 4326 | return err; |
| 4327 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4328 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4329 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4330 | |
| 4331 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4332 | |
| 4333 | spec->vmaster_nid = 0x0c; |
| 4334 | |
| 4335 | codec->patch_ops = alc_patch_ops; |
| 4336 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 4337 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4338 | spec->shutup = alc_eapd_shutup; |
| 4339 | |
| 4340 | alc_init_jacks(codec); |
| 4341 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4342 | if (!spec->loopback.amplist) |
| 4343 | spec->loopback.amplist = alc262_loopbacks; |
| 4344 | #endif |
| 4345 | |
| 4346 | return 0; |
| 4347 | } |
| 4348 | |
| 4349 | /* |
| 4350 | * ALC268 |
| 4351 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4352 | /* bind Beep switches of both NID 0x0f and 0x10 */ |
| 4353 | static const struct hda_bind_ctls alc268_bind_beep_sw = { |
| 4354 | .ops = &snd_hda_bind_sw, |
| 4355 | .values = { |
| 4356 | HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT), |
| 4357 | HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT), |
| 4358 | 0 |
| 4359 | }, |
| 4360 | }; |
| 4361 | |
| 4362 | static const struct snd_kcontrol_new alc268_beep_mixer[] = { |
| 4363 | HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT), |
| 4364 | HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw), |
| 4365 | { } |
| 4366 | }; |
| 4367 | |
| 4368 | /* set PCBEEP vol = 0, mute connections */ |
| 4369 | static const struct hda_verb alc268_beep_init_verbs[] = { |
| 4370 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4371 | {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4372 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4373 | { } |
| 4374 | }; |
| 4375 | |
| 4376 | /* |
| 4377 | * BIOS auto configuration |
| 4378 | */ |
| 4379 | static int alc268_parse_auto_config(struct hda_codec *codec) |
| 4380 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4381 | static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4382 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4383 | int err = alc_parse_auto_config(codec, NULL, alc268_ssids); |
| 4384 | if (err > 0) { |
| 4385 | if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { |
| 4386 | add_mixer(spec, alc268_beep_mixer); |
| 4387 | add_verb(spec, alc268_beep_init_verbs); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4388 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4389 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4390 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4391 | } |
| 4392 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4393 | /* |
| 4394 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4395 | static int patch_alc268(struct hda_codec *codec) |
| 4396 | { |
| 4397 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4398 | int i, has_beep, err; |
| 4399 | |
| 4400 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4401 | if (spec == NULL) |
| 4402 | return -ENOMEM; |
| 4403 | |
| 4404 | codec->spec = spec; |
| 4405 | |
| 4406 | /* ALC268 has no aa-loopback mixer */ |
| 4407 | |
Takashi Iwai | 6ebb805 | 2011-08-16 15:15:40 +0200 | [diff] [blame] | 4408 | /* automatic parse from the BIOS config */ |
| 4409 | err = alc268_parse_auto_config(codec); |
| 4410 | if (err < 0) { |
| 4411 | alc_free(codec); |
| 4412 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4413 | } |
| 4414 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4415 | has_beep = 0; |
| 4416 | for (i = 0; i < spec->num_mixers; i++) { |
| 4417 | if (spec->mixers[i] == alc268_beep_mixer) { |
| 4418 | has_beep = 1; |
| 4419 | break; |
| 4420 | } |
| 4421 | } |
| 4422 | |
| 4423 | if (has_beep) { |
| 4424 | err = snd_hda_attach_beep_device(codec, 0x1); |
| 4425 | if (err < 0) { |
| 4426 | alc_free(codec); |
| 4427 | return err; |
| 4428 | } |
| 4429 | if (!query_amp_caps(codec, 0x1d, HDA_INPUT)) |
| 4430 | /* override the amp caps for beep generator */ |
| 4431 | snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT, |
| 4432 | (0x0c << AC_AMPCAP_OFFSET_SHIFT) | |
| 4433 | (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 4434 | (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 4435 | (0 << AC_AMPCAP_MUTE_SHIFT)); |
| 4436 | } |
| 4437 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4438 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4439 | alc_auto_fill_adc_caps(codec); |
| 4440 | alc_rebuild_imux_for_auto_mic(codec); |
| 4441 | alc_remove_invalid_adc_nids(codec); |
| 4442 | } |
| 4443 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4444 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4445 | set_capture_mixer(codec); |
| 4446 | |
| 4447 | spec->vmaster_nid = 0x02; |
| 4448 | |
| 4449 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 6ebb805 | 2011-08-16 15:15:40 +0200 | [diff] [blame] | 4450 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4451 | spec->shutup = alc_eapd_shutup; |
| 4452 | |
| 4453 | alc_init_jacks(codec); |
| 4454 | |
| 4455 | return 0; |
| 4456 | } |
| 4457 | |
| 4458 | /* |
| 4459 | * ALC269 |
| 4460 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4461 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4462 | #define alc269_loopbacks alc880_loopbacks |
| 4463 | #endif |
| 4464 | |
| 4465 | static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { |
| 4466 | .substreams = 1, |
| 4467 | .channels_min = 2, |
| 4468 | .channels_max = 8, |
| 4469 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
| 4470 | /* NID is set in alc_build_pcms */ |
| 4471 | .ops = { |
| 4472 | .open = alc_playback_pcm_open, |
| 4473 | .prepare = alc_playback_pcm_prepare, |
| 4474 | .cleanup = alc_playback_pcm_cleanup |
| 4475 | }, |
| 4476 | }; |
| 4477 | |
| 4478 | static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { |
| 4479 | .substreams = 1, |
| 4480 | .channels_min = 2, |
| 4481 | .channels_max = 2, |
| 4482 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
| 4483 | /* NID is set in alc_build_pcms */ |
| 4484 | }; |
| 4485 | |
| 4486 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4487 | static int alc269_mic2_for_mute_led(struct hda_codec *codec) |
| 4488 | { |
| 4489 | switch (codec->subsystem_id) { |
| 4490 | case 0x103c1586: |
| 4491 | return 1; |
| 4492 | } |
| 4493 | return 0; |
| 4494 | } |
| 4495 | |
| 4496 | static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid) |
| 4497 | { |
| 4498 | /* update mute-LED according to the speaker mute state */ |
| 4499 | if (nid == 0x01 || nid == 0x14) { |
| 4500 | int pinval; |
| 4501 | if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) & |
| 4502 | HDA_AMP_MUTE) |
| 4503 | pinval = 0x24; |
| 4504 | else |
| 4505 | pinval = 0x20; |
| 4506 | /* mic2 vref pin is used for mute LED control */ |
| 4507 | snd_hda_codec_update_cache(codec, 0x19, 0, |
| 4508 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 4509 | pinval); |
| 4510 | } |
| 4511 | return alc_check_power_status(codec, nid); |
| 4512 | } |
| 4513 | #endif /* CONFIG_SND_HDA_POWER_SAVE */ |
| 4514 | |
| 4515 | /* different alc269-variants */ |
| 4516 | enum { |
| 4517 | ALC269_TYPE_ALC269VA, |
| 4518 | ALC269_TYPE_ALC269VB, |
| 4519 | ALC269_TYPE_ALC269VC, |
| 4520 | }; |
| 4521 | |
| 4522 | /* |
| 4523 | * BIOS auto configuration |
| 4524 | */ |
| 4525 | static int alc269_parse_auto_config(struct hda_codec *codec) |
| 4526 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4527 | static const hda_nid_t alc269_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4528 | static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 }; |
| 4529 | static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 4530 | struct alc_spec *spec = codec->spec; |
| 4531 | const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ? |
| 4532 | alc269va_ssids : alc269_ssids; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4533 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4534 | return alc_parse_auto_config(codec, alc269_ignore, ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4535 | } |
| 4536 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4537 | static void alc269_toggle_power_output(struct hda_codec *codec, int power_up) |
| 4538 | { |
| 4539 | int val = alc_read_coef_idx(codec, 0x04); |
| 4540 | if (power_up) |
| 4541 | val |= 1 << 11; |
| 4542 | else |
| 4543 | val &= ~(1 << 11); |
| 4544 | alc_write_coef_idx(codec, 0x04, val); |
| 4545 | } |
| 4546 | |
| 4547 | static void alc269_shutup(struct hda_codec *codec) |
| 4548 | { |
| 4549 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) |
| 4550 | alc269_toggle_power_output(codec, 0); |
| 4551 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) { |
| 4552 | alc269_toggle_power_output(codec, 0); |
| 4553 | msleep(150); |
| 4554 | } |
| 4555 | } |
| 4556 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 4557 | #ifdef CONFIG_PM |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4558 | static int alc269_resume(struct hda_codec *codec) |
| 4559 | { |
| 4560 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) { |
| 4561 | alc269_toggle_power_output(codec, 0); |
| 4562 | msleep(150); |
| 4563 | } |
| 4564 | |
| 4565 | codec->patch_ops.init(codec); |
| 4566 | |
| 4567 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) { |
| 4568 | alc269_toggle_power_output(codec, 1); |
| 4569 | msleep(200); |
| 4570 | } |
| 4571 | |
| 4572 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) |
| 4573 | alc269_toggle_power_output(codec, 1); |
| 4574 | |
| 4575 | snd_hda_codec_resume_amp(codec); |
| 4576 | snd_hda_codec_resume_cache(codec); |
| 4577 | hda_call_check_power_status(codec, 0x01); |
| 4578 | return 0; |
| 4579 | } |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 4580 | #endif /* CONFIG_PM */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4581 | |
| 4582 | static void alc269_fixup_hweq(struct hda_codec *codec, |
| 4583 | const struct alc_fixup *fix, int action) |
| 4584 | { |
| 4585 | int coef; |
| 4586 | |
| 4587 | if (action != ALC_FIXUP_ACT_INIT) |
| 4588 | return; |
| 4589 | coef = alc_read_coef_idx(codec, 0x1e); |
| 4590 | alc_write_coef_idx(codec, 0x1e, coef | 0x80); |
| 4591 | } |
| 4592 | |
| 4593 | static void alc271_fixup_dmic(struct hda_codec *codec, |
| 4594 | const struct alc_fixup *fix, int action) |
| 4595 | { |
| 4596 | static const struct hda_verb verbs[] = { |
| 4597 | {0x20, AC_VERB_SET_COEF_INDEX, 0x0d}, |
| 4598 | {0x20, AC_VERB_SET_PROC_COEF, 0x4000}, |
| 4599 | {} |
| 4600 | }; |
| 4601 | unsigned int cfg; |
| 4602 | |
| 4603 | if (strcmp(codec->chip_name, "ALC271X")) |
| 4604 | return; |
| 4605 | cfg = snd_hda_codec_get_pincfg(codec, 0x12); |
| 4606 | if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED) |
| 4607 | snd_hda_sequence_write(codec, verbs); |
| 4608 | } |
| 4609 | |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 4610 | static void alc269_fixup_pcm_44k(struct hda_codec *codec, |
| 4611 | const struct alc_fixup *fix, int action) |
| 4612 | { |
| 4613 | struct alc_spec *spec = codec->spec; |
| 4614 | |
| 4615 | if (action != ALC_FIXUP_ACT_PROBE) |
| 4616 | return; |
| 4617 | |
| 4618 | /* Due to a hardware problem on Lenovo Ideadpad, we need to |
| 4619 | * fix the sample rate of analog I/O to 44.1kHz |
| 4620 | */ |
| 4621 | spec->stream_analog_playback = &alc269_44k_pcm_analog_playback; |
| 4622 | spec->stream_analog_capture = &alc269_44k_pcm_analog_capture; |
| 4623 | } |
| 4624 | |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 4625 | static void alc269_fixup_stereo_dmic(struct hda_codec *codec, |
| 4626 | const struct alc_fixup *fix, int action) |
| 4627 | { |
| 4628 | int coef; |
| 4629 | |
| 4630 | if (action != ALC_FIXUP_ACT_INIT) |
| 4631 | return; |
| 4632 | /* The digital-mic unit sends PDM (differential signal) instead of |
| 4633 | * the standard PCM, thus you can't record a valid mono stream as is. |
| 4634 | * Below is a workaround specific to ALC269 to control the dmic |
| 4635 | * signal source as mono. |
| 4636 | */ |
| 4637 | coef = alc_read_coef_idx(codec, 0x07); |
| 4638 | alc_write_coef_idx(codec, 0x07, coef | 0x80); |
| 4639 | } |
| 4640 | |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 4641 | static void alc269_quanta_automute(struct hda_codec *codec) |
| 4642 | { |
| 4643 | update_speakers(codec); |
| 4644 | |
| 4645 | snd_hda_codec_write(codec, 0x20, 0, |
| 4646 | AC_VERB_SET_COEF_INDEX, 0x0c); |
| 4647 | snd_hda_codec_write(codec, 0x20, 0, |
| 4648 | AC_VERB_SET_PROC_COEF, 0x680); |
| 4649 | |
| 4650 | snd_hda_codec_write(codec, 0x20, 0, |
| 4651 | AC_VERB_SET_COEF_INDEX, 0x0c); |
| 4652 | snd_hda_codec_write(codec, 0x20, 0, |
| 4653 | AC_VERB_SET_PROC_COEF, 0x480); |
| 4654 | } |
| 4655 | |
| 4656 | static void alc269_fixup_quanta_mute(struct hda_codec *codec, |
| 4657 | const struct alc_fixup *fix, int action) |
| 4658 | { |
| 4659 | struct alc_spec *spec = codec->spec; |
| 4660 | if (action != ALC_FIXUP_ACT_PROBE) |
| 4661 | return; |
| 4662 | spec->automute_hook = alc269_quanta_automute; |
| 4663 | } |
| 4664 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4665 | enum { |
| 4666 | ALC269_FIXUP_SONY_VAIO, |
| 4667 | ALC275_FIXUP_SONY_VAIO_GPIO2, |
| 4668 | ALC269_FIXUP_DELL_M101Z, |
| 4669 | ALC269_FIXUP_SKU_IGNORE, |
| 4670 | ALC269_FIXUP_ASUS_G73JW, |
| 4671 | ALC269_FIXUP_LENOVO_EAPD, |
| 4672 | ALC275_FIXUP_SONY_HWEQ, |
| 4673 | ALC271_FIXUP_DMIC, |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 4674 | ALC269_FIXUP_PCM_44K, |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 4675 | ALC269_FIXUP_STEREO_DMIC, |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 4676 | ALC269_FIXUP_QUANTA_MUTE, |
| 4677 | ALC269_FIXUP_LIFEBOOK, |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 4678 | ALC269_FIXUP_AMIC, |
| 4679 | ALC269_FIXUP_DMIC, |
| 4680 | ALC269VB_FIXUP_AMIC, |
| 4681 | ALC269VB_FIXUP_DMIC, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4682 | }; |
| 4683 | |
| 4684 | static const struct alc_fixup alc269_fixups[] = { |
| 4685 | [ALC269_FIXUP_SONY_VAIO] = { |
| 4686 | .type = ALC_FIXUP_VERBS, |
| 4687 | .v.verbs = (const struct hda_verb[]) { |
| 4688 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD}, |
| 4689 | {} |
| 4690 | } |
| 4691 | }, |
| 4692 | [ALC275_FIXUP_SONY_VAIO_GPIO2] = { |
| 4693 | .type = ALC_FIXUP_VERBS, |
| 4694 | .v.verbs = (const struct hda_verb[]) { |
| 4695 | {0x01, AC_VERB_SET_GPIO_MASK, 0x04}, |
| 4696 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04}, |
| 4697 | {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, |
| 4698 | { } |
| 4699 | }, |
| 4700 | .chained = true, |
| 4701 | .chain_id = ALC269_FIXUP_SONY_VAIO |
| 4702 | }, |
| 4703 | [ALC269_FIXUP_DELL_M101Z] = { |
| 4704 | .type = ALC_FIXUP_VERBS, |
| 4705 | .v.verbs = (const struct hda_verb[]) { |
| 4706 | /* Enables internal speaker */ |
| 4707 | {0x20, AC_VERB_SET_COEF_INDEX, 13}, |
| 4708 | {0x20, AC_VERB_SET_PROC_COEF, 0x4040}, |
| 4709 | {} |
| 4710 | } |
| 4711 | }, |
| 4712 | [ALC269_FIXUP_SKU_IGNORE] = { |
| 4713 | .type = ALC_FIXUP_SKU, |
| 4714 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
| 4715 | }, |
| 4716 | [ALC269_FIXUP_ASUS_G73JW] = { |
| 4717 | .type = ALC_FIXUP_PINS, |
| 4718 | .v.pins = (const struct alc_pincfg[]) { |
| 4719 | { 0x17, 0x99130111 }, /* subwoofer */ |
| 4720 | { } |
| 4721 | } |
| 4722 | }, |
| 4723 | [ALC269_FIXUP_LENOVO_EAPD] = { |
| 4724 | .type = ALC_FIXUP_VERBS, |
| 4725 | .v.verbs = (const struct hda_verb[]) { |
| 4726 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, |
| 4727 | {} |
| 4728 | } |
| 4729 | }, |
| 4730 | [ALC275_FIXUP_SONY_HWEQ] = { |
| 4731 | .type = ALC_FIXUP_FUNC, |
| 4732 | .v.func = alc269_fixup_hweq, |
| 4733 | .chained = true, |
| 4734 | .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2 |
| 4735 | }, |
| 4736 | [ALC271_FIXUP_DMIC] = { |
| 4737 | .type = ALC_FIXUP_FUNC, |
| 4738 | .v.func = alc271_fixup_dmic, |
| 4739 | }, |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 4740 | [ALC269_FIXUP_PCM_44K] = { |
| 4741 | .type = ALC_FIXUP_FUNC, |
| 4742 | .v.func = alc269_fixup_pcm_44k, |
| 4743 | }, |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 4744 | [ALC269_FIXUP_STEREO_DMIC] = { |
| 4745 | .type = ALC_FIXUP_FUNC, |
| 4746 | .v.func = alc269_fixup_stereo_dmic, |
| 4747 | }, |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 4748 | [ALC269_FIXUP_QUANTA_MUTE] = { |
| 4749 | .type = ALC_FIXUP_FUNC, |
| 4750 | .v.func = alc269_fixup_quanta_mute, |
| 4751 | }, |
| 4752 | [ALC269_FIXUP_LIFEBOOK] = { |
| 4753 | .type = ALC_FIXUP_PINS, |
| 4754 | .v.pins = (const struct alc_pincfg[]) { |
| 4755 | { 0x1a, 0x2101103f }, /* dock line-out */ |
| 4756 | { 0x1b, 0x23a11040 }, /* dock mic-in */ |
| 4757 | { } |
| 4758 | }, |
| 4759 | .chained = true, |
| 4760 | .chain_id = ALC269_FIXUP_QUANTA_MUTE |
| 4761 | }, |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 4762 | [ALC269_FIXUP_AMIC] = { |
| 4763 | .type = ALC_FIXUP_PINS, |
| 4764 | .v.pins = (const struct alc_pincfg[]) { |
| 4765 | { 0x14, 0x99130110 }, /* speaker */ |
| 4766 | { 0x15, 0x0121401f }, /* HP out */ |
| 4767 | { 0x18, 0x01a19c20 }, /* mic */ |
| 4768 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 4769 | { } |
| 4770 | }, |
| 4771 | }, |
| 4772 | [ALC269_FIXUP_DMIC] = { |
| 4773 | .type = ALC_FIXUP_PINS, |
| 4774 | .v.pins = (const struct alc_pincfg[]) { |
| 4775 | { 0x12, 0x99a3092f }, /* int-mic */ |
| 4776 | { 0x14, 0x99130110 }, /* speaker */ |
| 4777 | { 0x15, 0x0121401f }, /* HP out */ |
| 4778 | { 0x18, 0x01a19c20 }, /* mic */ |
| 4779 | { } |
| 4780 | }, |
| 4781 | }, |
| 4782 | [ALC269VB_FIXUP_AMIC] = { |
| 4783 | .type = ALC_FIXUP_PINS, |
| 4784 | .v.pins = (const struct alc_pincfg[]) { |
| 4785 | { 0x14, 0x99130110 }, /* speaker */ |
| 4786 | { 0x18, 0x01a19c20 }, /* mic */ |
| 4787 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 4788 | { 0x21, 0x0121401f }, /* HP out */ |
| 4789 | { } |
| 4790 | }, |
| 4791 | }, |
| 4792 | [ALC269_FIXUP_DMIC] = { |
| 4793 | .type = ALC_FIXUP_PINS, |
| 4794 | .v.pins = (const struct alc_pincfg[]) { |
| 4795 | { 0x12, 0x99a3092f }, /* int-mic */ |
| 4796 | { 0x14, 0x99130110 }, /* speaker */ |
| 4797 | { 0x18, 0x01a19c20 }, /* mic */ |
| 4798 | { 0x21, 0x0121401f }, /* HP out */ |
| 4799 | { } |
| 4800 | }, |
| 4801 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4802 | }; |
| 4803 | |
| 4804 | static const struct snd_pci_quirk alc269_fixup_tbl[] = { |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 4805 | SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW), |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 4806 | SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC), |
| 4807 | SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC), |
| 4808 | SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC), |
| 4809 | SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), |
| 4810 | SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4811 | SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2), |
| 4812 | SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), |
| 4813 | SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), |
| 4814 | SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO), |
| 4815 | SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z), |
| 4816 | SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC), |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 4817 | SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4818 | SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE), |
| 4819 | SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE), |
| 4820 | SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE), |
| 4821 | SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE), |
| 4822 | SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE), |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 4823 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE), |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 4824 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4825 | SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD), |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 4826 | |
| 4827 | #if 1 |
| 4828 | /* Below is a quirk table taken from the old code. |
| 4829 | * Basically the device should work as is without the fixup table. |
| 4830 | * If BIOS doesn't give a proper info, enable the corresponding |
| 4831 | * fixup entry. |
| 4832 | */ |
| 4833 | SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A", |
| 4834 | ALC269_FIXUP_AMIC), |
| 4835 | SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC), |
| 4836 | SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC), |
| 4837 | SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC), |
| 4838 | SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC), |
| 4839 | SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC), |
| 4840 | SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC), |
| 4841 | SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC), |
| 4842 | SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC), |
| 4843 | SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC), |
| 4844 | SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC), |
| 4845 | SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC), |
| 4846 | SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC), |
| 4847 | SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC), |
| 4848 | SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC), |
| 4849 | SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC), |
| 4850 | SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC), |
| 4851 | SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC), |
| 4852 | SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC), |
| 4853 | SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC), |
| 4854 | SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC), |
| 4855 | SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC), |
| 4856 | SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC), |
| 4857 | SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC), |
| 4858 | SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC), |
| 4859 | SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC), |
| 4860 | SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC), |
| 4861 | SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC), |
| 4862 | SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC), |
| 4863 | SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC), |
| 4864 | SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC), |
| 4865 | SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC), |
| 4866 | SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC), |
| 4867 | SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC), |
| 4868 | SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC), |
| 4869 | SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC), |
| 4870 | SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC), |
| 4871 | SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC), |
| 4872 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC), |
| 4873 | SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC), |
| 4874 | SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC), |
| 4875 | #endif |
| 4876 | {} |
| 4877 | }; |
| 4878 | |
| 4879 | static const struct alc_model_fixup alc269_fixup_models[] = { |
| 4880 | {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"}, |
| 4881 | {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"}, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4882 | {} |
| 4883 | }; |
| 4884 | |
| 4885 | |
| 4886 | static int alc269_fill_coef(struct hda_codec *codec) |
| 4887 | { |
| 4888 | int val; |
| 4889 | |
| 4890 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) < 0x015) { |
| 4891 | alc_write_coef_idx(codec, 0xf, 0x960b); |
| 4892 | alc_write_coef_idx(codec, 0xe, 0x8817); |
| 4893 | } |
| 4894 | |
| 4895 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x016) { |
| 4896 | alc_write_coef_idx(codec, 0xf, 0x960b); |
| 4897 | alc_write_coef_idx(codec, 0xe, 0x8814); |
| 4898 | } |
| 4899 | |
| 4900 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) { |
| 4901 | val = alc_read_coef_idx(codec, 0x04); |
| 4902 | /* Power up output pin */ |
| 4903 | alc_write_coef_idx(codec, 0x04, val | (1<<11)); |
| 4904 | } |
| 4905 | |
| 4906 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) { |
| 4907 | val = alc_read_coef_idx(codec, 0xd); |
| 4908 | if ((val & 0x0c00) >> 10 != 0x1) { |
| 4909 | /* Capless ramp up clock control */ |
| 4910 | alc_write_coef_idx(codec, 0xd, val | (1<<10)); |
| 4911 | } |
| 4912 | val = alc_read_coef_idx(codec, 0x17); |
| 4913 | if ((val & 0x01c0) >> 6 != 0x4) { |
| 4914 | /* Class D power on reset */ |
| 4915 | alc_write_coef_idx(codec, 0x17, val | (1<<7)); |
| 4916 | } |
| 4917 | } |
| 4918 | |
| 4919 | val = alc_read_coef_idx(codec, 0xd); /* Class D */ |
| 4920 | alc_write_coef_idx(codec, 0xd, val | (1<<14)); |
| 4921 | |
| 4922 | val = alc_read_coef_idx(codec, 0x4); /* HP */ |
| 4923 | alc_write_coef_idx(codec, 0x4, val | (1<<11)); |
| 4924 | |
| 4925 | return 0; |
| 4926 | } |
| 4927 | |
| 4928 | /* |
| 4929 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4930 | static int patch_alc269(struct hda_codec *codec) |
| 4931 | { |
| 4932 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4933 | int err; |
| 4934 | |
| 4935 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4936 | if (spec == NULL) |
| 4937 | return -ENOMEM; |
| 4938 | |
| 4939 | codec->spec = spec; |
| 4940 | |
| 4941 | spec->mixer_nid = 0x0b; |
| 4942 | |
| 4943 | alc_auto_parse_customize_define(codec); |
| 4944 | |
| 4945 | if (codec->vendor_id == 0x10ec0269) { |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 4946 | unsigned int coef; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4947 | spec->codec_variant = ALC269_TYPE_ALC269VA; |
| 4948 | coef = alc_read_coef_idx(codec, 0); |
| 4949 | if ((coef & 0x00f0) == 0x0010) { |
| 4950 | if (codec->bus->pci->subsystem_vendor == 0x1025 && |
| 4951 | spec->cdefine.platform_type == 1) { |
| 4952 | alc_codec_rename(codec, "ALC271X"); |
| 4953 | } else if ((coef & 0xf000) == 0x2000) { |
| 4954 | alc_codec_rename(codec, "ALC259"); |
| 4955 | } else if ((coef & 0xf000) == 0x3000) { |
| 4956 | alc_codec_rename(codec, "ALC258"); |
| 4957 | } else if ((coef & 0xfff0) == 0x3010) { |
| 4958 | alc_codec_rename(codec, "ALC277"); |
| 4959 | } else { |
| 4960 | alc_codec_rename(codec, "ALC269VB"); |
| 4961 | } |
| 4962 | spec->codec_variant = ALC269_TYPE_ALC269VB; |
| 4963 | } else if ((coef & 0x00f0) == 0x0020) { |
| 4964 | if (coef == 0xa023) |
| 4965 | alc_codec_rename(codec, "ALC259"); |
| 4966 | else if (coef == 0x6023) |
| 4967 | alc_codec_rename(codec, "ALC281X"); |
| 4968 | else if (codec->bus->pci->subsystem_vendor == 0x17aa && |
| 4969 | codec->bus->pci->subsystem_device == 0x21f3) |
| 4970 | alc_codec_rename(codec, "ALC3202"); |
| 4971 | else |
| 4972 | alc_codec_rename(codec, "ALC269VC"); |
| 4973 | spec->codec_variant = ALC269_TYPE_ALC269VC; |
| 4974 | } else |
| 4975 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
| 4976 | alc269_fill_coef(codec); |
| 4977 | } |
| 4978 | |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 4979 | alc_pick_fixup(codec, alc269_fixup_models, |
| 4980 | alc269_fixup_tbl, alc269_fixups); |
| 4981 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4982 | |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 4983 | /* automatic parse from the BIOS config */ |
| 4984 | err = alc269_parse_auto_config(codec); |
| 4985 | if (err < 0) { |
| 4986 | alc_free(codec); |
| 4987 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4988 | } |
| 4989 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4990 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4991 | alc_auto_fill_adc_caps(codec); |
| 4992 | alc_rebuild_imux_for_auto_mic(codec); |
| 4993 | alc_remove_invalid_adc_nids(codec); |
| 4994 | } |
| 4995 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4996 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4997 | set_capture_mixer(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4998 | |
| 4999 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 5000 | err = snd_hda_attach_beep_device(codec, 0x1); |
| 5001 | if (err < 0) { |
| 5002 | alc_free(codec); |
| 5003 | return err; |
| 5004 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5005 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5006 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5007 | |
| 5008 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5009 | |
| 5010 | spec->vmaster_nid = 0x02; |
| 5011 | |
| 5012 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 5013 | #ifdef CONFIG_PM |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5014 | codec->patch_ops.resume = alc269_resume; |
| 5015 | #endif |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5016 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5017 | spec->shutup = alc269_shutup; |
| 5018 | |
| 5019 | alc_init_jacks(codec); |
| 5020 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5021 | if (!spec->loopback.amplist) |
| 5022 | spec->loopback.amplist = alc269_loopbacks; |
| 5023 | if (alc269_mic2_for_mute_led(codec)) |
| 5024 | codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps; |
| 5025 | #endif |
| 5026 | |
| 5027 | return 0; |
| 5028 | } |
| 5029 | |
| 5030 | /* |
| 5031 | * ALC861 |
| 5032 | */ |
| 5033 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5034 | static int alc861_parse_auto_config(struct hda_codec *codec) |
| 5035 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5036 | static const hda_nid_t alc861_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5037 | static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 }; |
| 5038 | return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5039 | } |
| 5040 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5041 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5042 | static const struct hda_amp_list alc861_loopbacks[] = { |
| 5043 | { 0x15, HDA_INPUT, 0 }, |
| 5044 | { 0x15, HDA_INPUT, 1 }, |
| 5045 | { 0x15, HDA_INPUT, 2 }, |
| 5046 | { 0x15, HDA_INPUT, 3 }, |
| 5047 | { } /* end */ |
| 5048 | }; |
| 5049 | #endif |
| 5050 | |
| 5051 | |
| 5052 | /* Pin config fixes */ |
| 5053 | enum { |
| 5054 | PINFIX_FSC_AMILO_PI1505, |
| 5055 | }; |
| 5056 | |
| 5057 | static const struct alc_fixup alc861_fixups[] = { |
| 5058 | [PINFIX_FSC_AMILO_PI1505] = { |
| 5059 | .type = ALC_FIXUP_PINS, |
| 5060 | .v.pins = (const struct alc_pincfg[]) { |
| 5061 | { 0x0b, 0x0221101f }, /* HP */ |
| 5062 | { 0x0f, 0x90170310 }, /* speaker */ |
| 5063 | { } |
| 5064 | } |
| 5065 | }, |
| 5066 | }; |
| 5067 | |
| 5068 | static const struct snd_pci_quirk alc861_fixup_tbl[] = { |
| 5069 | SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505), |
| 5070 | {} |
| 5071 | }; |
| 5072 | |
| 5073 | /* |
| 5074 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5075 | static int patch_alc861(struct hda_codec *codec) |
| 5076 | { |
| 5077 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5078 | int err; |
| 5079 | |
| 5080 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5081 | if (spec == NULL) |
| 5082 | return -ENOMEM; |
| 5083 | |
| 5084 | codec->spec = spec; |
| 5085 | |
| 5086 | spec->mixer_nid = 0x15; |
| 5087 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5088 | alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); |
| 5089 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5090 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5091 | /* automatic parse from the BIOS config */ |
| 5092 | err = alc861_parse_auto_config(codec); |
| 5093 | if (err < 0) { |
| 5094 | alc_free(codec); |
| 5095 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5096 | } |
| 5097 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5098 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5099 | alc_auto_fill_adc_caps(codec); |
| 5100 | alc_rebuild_imux_for_auto_mic(codec); |
| 5101 | alc_remove_invalid_adc_nids(codec); |
| 5102 | } |
| 5103 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5104 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5105 | set_capture_mixer(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5106 | |
| 5107 | if (!spec->no_analog) { |
| 5108 | err = snd_hda_attach_beep_device(codec, 0x23); |
| 5109 | if (err < 0) { |
| 5110 | alc_free(codec); |
| 5111 | return err; |
| 5112 | } |
| 5113 | set_beep_amp(spec, 0x23, 0, HDA_OUTPUT); |
| 5114 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5115 | |
| 5116 | spec->vmaster_nid = 0x03; |
| 5117 | |
| 5118 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5119 | |
| 5120 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5121 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5122 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5123 | spec->power_hook = alc_power_eapd; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5124 | if (!spec->loopback.amplist) |
| 5125 | spec->loopback.amplist = alc861_loopbacks; |
| 5126 | #endif |
| 5127 | |
| 5128 | return 0; |
| 5129 | } |
| 5130 | |
| 5131 | /* |
| 5132 | * ALC861-VD support |
| 5133 | * |
| 5134 | * Based on ALC882 |
| 5135 | * |
| 5136 | * In addition, an independent DAC |
| 5137 | */ |
| 5138 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5139 | #define alc861vd_loopbacks alc880_loopbacks |
| 5140 | #endif |
| 5141 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5142 | static int alc861vd_parse_auto_config(struct hda_codec *codec) |
| 5143 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5144 | static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5145 | static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5146 | return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5147 | } |
| 5148 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5149 | enum { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5150 | ALC660VD_FIX_ASUS_GPIO1, |
| 5151 | ALC861VD_FIX_DALLAS, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5152 | }; |
| 5153 | |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5154 | /* exclude VREF80 */ |
| 5155 | static void alc861vd_fixup_dallas(struct hda_codec *codec, |
| 5156 | const struct alc_fixup *fix, int action) |
| 5157 | { |
| 5158 | if (action == ALC_FIXUP_ACT_PRE_PROBE) { |
| 5159 | snd_hda_override_pin_caps(codec, 0x18, 0x00001714); |
| 5160 | snd_hda_override_pin_caps(codec, 0x19, 0x0000171c); |
| 5161 | } |
| 5162 | } |
| 5163 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5164 | static const struct alc_fixup alc861vd_fixups[] = { |
| 5165 | [ALC660VD_FIX_ASUS_GPIO1] = { |
| 5166 | .type = ALC_FIXUP_VERBS, |
| 5167 | .v.verbs = (const struct hda_verb[]) { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5168 | /* reset GPIO1 */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5169 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, |
| 5170 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, |
| 5171 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, |
| 5172 | { } |
| 5173 | } |
| 5174 | }, |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5175 | [ALC861VD_FIX_DALLAS] = { |
| 5176 | .type = ALC_FIXUP_FUNC, |
| 5177 | .v.func = alc861vd_fixup_dallas, |
| 5178 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5179 | }; |
| 5180 | |
| 5181 | static const struct snd_pci_quirk alc861vd_fixup_tbl[] = { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5182 | SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5183 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1), |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5184 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5185 | {} |
| 5186 | }; |
| 5187 | |
| 5188 | static const struct hda_verb alc660vd_eapd_verbs[] = { |
| 5189 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2}, |
| 5190 | {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2}, |
| 5191 | { } |
| 5192 | }; |
| 5193 | |
| 5194 | /* |
| 5195 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5196 | static int patch_alc861vd(struct hda_codec *codec) |
| 5197 | { |
| 5198 | struct alc_spec *spec; |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5199 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5200 | |
| 5201 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5202 | if (spec == NULL) |
| 5203 | return -ENOMEM; |
| 5204 | |
| 5205 | codec->spec = spec; |
| 5206 | |
| 5207 | spec->mixer_nid = 0x0b; |
| 5208 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5209 | alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); |
| 5210 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5211 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5212 | /* automatic parse from the BIOS config */ |
| 5213 | err = alc861vd_parse_auto_config(codec); |
| 5214 | if (err < 0) { |
| 5215 | alc_free(codec); |
| 5216 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5217 | } |
| 5218 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5219 | if (codec->vendor_id == 0x10ec0660) { |
| 5220 | /* always turn on EAPD */ |
| 5221 | add_verb(spec, alc660vd_eapd_verbs); |
| 5222 | } |
| 5223 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5224 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5225 | alc_auto_fill_adc_caps(codec); |
| 5226 | alc_rebuild_imux_for_auto_mic(codec); |
| 5227 | alc_remove_invalid_adc_nids(codec); |
| 5228 | } |
| 5229 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5230 | if (!spec->no_analog && !spec->cap_mixer) |
| 5231 | set_capture_mixer(codec); |
| 5232 | |
| 5233 | if (!spec->no_analog) { |
| 5234 | err = snd_hda_attach_beep_device(codec, 0x23); |
| 5235 | if (err < 0) { |
| 5236 | alc_free(codec); |
| 5237 | return err; |
| 5238 | } |
| 5239 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 5240 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5241 | |
| 5242 | spec->vmaster_nid = 0x02; |
| 5243 | |
| 5244 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5245 | |
| 5246 | codec->patch_ops = alc_patch_ops; |
| 5247 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5248 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5249 | spec->shutup = alc_eapd_shutup; |
| 5250 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5251 | if (!spec->loopback.amplist) |
| 5252 | spec->loopback.amplist = alc861vd_loopbacks; |
| 5253 | #endif |
| 5254 | |
| 5255 | return 0; |
| 5256 | } |
| 5257 | |
| 5258 | /* |
| 5259 | * ALC662 support |
| 5260 | * |
| 5261 | * ALC662 is almost identical with ALC880 but has cleaner and more flexible |
| 5262 | * configuration. Each pin widget can choose any input DACs and a mixer. |
| 5263 | * Each ADC is connected from a mixer of all inputs. This makes possible |
| 5264 | * 6-channel independent captures. |
| 5265 | * |
| 5266 | * In addition, an independent DAC for the multi-playback (not used in this |
| 5267 | * driver yet). |
| 5268 | */ |
| 5269 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5270 | #define alc662_loopbacks alc880_loopbacks |
| 5271 | #endif |
| 5272 | |
| 5273 | /* |
| 5274 | * BIOS auto configuration |
| 5275 | */ |
| 5276 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5277 | static int alc662_parse_auto_config(struct hda_codec *codec) |
| 5278 | { |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 5279 | static const hda_nid_t alc662_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5280 | static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 }; |
| 5281 | static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5282 | const hda_nid_t *ssids; |
Takashi Iwai | ee979a14 | 2008-09-02 15:42:20 +0200 | [diff] [blame] | 5283 | |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 5284 | if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 || |
| 5285 | codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670) |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5286 | ssids = alc663_ssids; |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 5287 | else |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5288 | ssids = alc662_ssids; |
| 5289 | return alc_parse_auto_config(codec, alc662_ignore, ssids); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5290 | } |
| 5291 | |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5292 | static void alc272_fixup_mario(struct hda_codec *codec, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5293 | const struct alc_fixup *fix, int action) |
Takashi Iwai | 6fc398c | 2011-01-13 14:36:37 +0100 | [diff] [blame] | 5294 | { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5295 | if (action != ALC_FIXUP_ACT_PROBE) |
Takashi Iwai | 6fc398c | 2011-01-13 14:36:37 +0100 | [diff] [blame] | 5296 | return; |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5297 | if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT, |
| 5298 | (0x3b << AC_AMPCAP_OFFSET_SHIFT) | |
| 5299 | (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 5300 | (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 5301 | (0 << AC_AMPCAP_MUTE_SHIFT))) |
| 5302 | printk(KERN_WARNING |
| 5303 | "hda_codec: failed to override amp caps for NID 0x2\n"); |
| 5304 | } |
| 5305 | |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5306 | enum { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5307 | ALC662_FIXUP_ASPIRE, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5308 | ALC662_FIXUP_IDEAPAD, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5309 | ALC272_FIXUP_MARIO, |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 5310 | ALC662_FIXUP_CZC_P10T, |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 5311 | ALC662_FIXUP_SKU_IGNORE, |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 5312 | ALC662_FIXUP_HP_RP5800, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5313 | ALC662_FIXUP_ASUS_MODE1, |
| 5314 | ALC662_FIXUP_ASUS_MODE2, |
| 5315 | ALC662_FIXUP_ASUS_MODE3, |
| 5316 | ALC662_FIXUP_ASUS_MODE4, |
| 5317 | ALC662_FIXUP_ASUS_MODE5, |
| 5318 | ALC662_FIXUP_ASUS_MODE6, |
| 5319 | ALC662_FIXUP_ASUS_MODE7, |
| 5320 | ALC662_FIXUP_ASUS_MODE8, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5321 | }; |
| 5322 | |
| 5323 | static const struct alc_fixup alc662_fixups[] = { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5324 | [ALC662_FIXUP_ASPIRE] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5325 | .type = ALC_FIXUP_PINS, |
| 5326 | .v.pins = (const struct alc_pincfg[]) { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5327 | { 0x15, 0x99130112 }, /* subwoofer */ |
| 5328 | { } |
| 5329 | } |
| 5330 | }, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5331 | [ALC662_FIXUP_IDEAPAD] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5332 | .type = ALC_FIXUP_PINS, |
| 5333 | .v.pins = (const struct alc_pincfg[]) { |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5334 | { 0x17, 0x99130112 }, /* subwoofer */ |
| 5335 | { } |
| 5336 | } |
| 5337 | }, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5338 | [ALC272_FIXUP_MARIO] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5339 | .type = ALC_FIXUP_FUNC, |
| 5340 | .v.func = alc272_fixup_mario, |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 5341 | }, |
| 5342 | [ALC662_FIXUP_CZC_P10T] = { |
| 5343 | .type = ALC_FIXUP_VERBS, |
| 5344 | .v.verbs = (const struct hda_verb[]) { |
| 5345 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, |
| 5346 | {} |
| 5347 | } |
| 5348 | }, |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 5349 | [ALC662_FIXUP_SKU_IGNORE] = { |
| 5350 | .type = ALC_FIXUP_SKU, |
| 5351 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
Takashi Iwai | c6b3587 | 2011-03-28 12:05:31 +0200 | [diff] [blame] | 5352 | }, |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 5353 | [ALC662_FIXUP_HP_RP5800] = { |
| 5354 | .type = ALC_FIXUP_PINS, |
| 5355 | .v.pins = (const struct alc_pincfg[]) { |
| 5356 | { 0x14, 0x0221201f }, /* HP out */ |
| 5357 | { } |
| 5358 | }, |
| 5359 | .chained = true, |
| 5360 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5361 | }, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5362 | [ALC662_FIXUP_ASUS_MODE1] = { |
| 5363 | .type = ALC_FIXUP_PINS, |
| 5364 | .v.pins = (const struct alc_pincfg[]) { |
| 5365 | { 0x14, 0x99130110 }, /* speaker */ |
| 5366 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5367 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 5368 | { 0x21, 0x0121401f }, /* HP out */ |
| 5369 | { } |
| 5370 | }, |
| 5371 | .chained = true, |
| 5372 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5373 | }, |
| 5374 | [ALC662_FIXUP_ASUS_MODE2] = { |
Takashi Iwai | 2996bdb | 2011-08-18 16:02:24 +0200 | [diff] [blame] | 5375 | .type = ALC_FIXUP_PINS, |
| 5376 | .v.pins = (const struct alc_pincfg[]) { |
| 5377 | { 0x14, 0x99130110 }, /* speaker */ |
| 5378 | { 0x18, 0x01a19820 }, /* mic */ |
| 5379 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 5380 | { 0x1b, 0x0121401f }, /* HP out */ |
| 5381 | { } |
| 5382 | }, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5383 | .chained = true, |
| 5384 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5385 | }, |
| 5386 | [ALC662_FIXUP_ASUS_MODE3] = { |
| 5387 | .type = ALC_FIXUP_PINS, |
| 5388 | .v.pins = (const struct alc_pincfg[]) { |
| 5389 | { 0x14, 0x99130110 }, /* speaker */ |
| 5390 | { 0x15, 0x0121441f }, /* HP */ |
| 5391 | { 0x18, 0x01a19840 }, /* mic */ |
| 5392 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5393 | { 0x21, 0x01211420 }, /* HP2 */ |
| 5394 | { } |
| 5395 | }, |
| 5396 | .chained = true, |
| 5397 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5398 | }, |
| 5399 | [ALC662_FIXUP_ASUS_MODE4] = { |
| 5400 | .type = ALC_FIXUP_PINS, |
| 5401 | .v.pins = (const struct alc_pincfg[]) { |
| 5402 | { 0x14, 0x99130110 }, /* speaker */ |
| 5403 | { 0x16, 0x99130111 }, /* speaker */ |
| 5404 | { 0x18, 0x01a19840 }, /* mic */ |
| 5405 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5406 | { 0x21, 0x0121441f }, /* HP */ |
| 5407 | { } |
| 5408 | }, |
| 5409 | .chained = true, |
| 5410 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5411 | }, |
| 5412 | [ALC662_FIXUP_ASUS_MODE5] = { |
| 5413 | .type = ALC_FIXUP_PINS, |
| 5414 | .v.pins = (const struct alc_pincfg[]) { |
| 5415 | { 0x14, 0x99130110 }, /* speaker */ |
| 5416 | { 0x15, 0x0121441f }, /* HP */ |
| 5417 | { 0x16, 0x99130111 }, /* speaker */ |
| 5418 | { 0x18, 0x01a19840 }, /* mic */ |
| 5419 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5420 | { } |
| 5421 | }, |
| 5422 | .chained = true, |
| 5423 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5424 | }, |
| 5425 | [ALC662_FIXUP_ASUS_MODE6] = { |
| 5426 | .type = ALC_FIXUP_PINS, |
| 5427 | .v.pins = (const struct alc_pincfg[]) { |
| 5428 | { 0x14, 0x99130110 }, /* speaker */ |
| 5429 | { 0x15, 0x01211420 }, /* HP2 */ |
| 5430 | { 0x18, 0x01a19840 }, /* mic */ |
| 5431 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5432 | { 0x1b, 0x0121441f }, /* HP */ |
| 5433 | { } |
| 5434 | }, |
| 5435 | .chained = true, |
| 5436 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5437 | }, |
| 5438 | [ALC662_FIXUP_ASUS_MODE7] = { |
| 5439 | .type = ALC_FIXUP_PINS, |
| 5440 | .v.pins = (const struct alc_pincfg[]) { |
| 5441 | { 0x14, 0x99130110 }, /* speaker */ |
| 5442 | { 0x17, 0x99130111 }, /* speaker */ |
| 5443 | { 0x18, 0x01a19840 }, /* mic */ |
| 5444 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5445 | { 0x1b, 0x01214020 }, /* HP */ |
| 5446 | { 0x21, 0x0121401f }, /* HP */ |
| 5447 | { } |
| 5448 | }, |
| 5449 | .chained = true, |
| 5450 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5451 | }, |
| 5452 | [ALC662_FIXUP_ASUS_MODE8] = { |
| 5453 | .type = ALC_FIXUP_PINS, |
| 5454 | .v.pins = (const struct alc_pincfg[]) { |
| 5455 | { 0x14, 0x99130110 }, /* speaker */ |
| 5456 | { 0x12, 0x99a30970 }, /* int-mic */ |
| 5457 | { 0x15, 0x01214020 }, /* HP */ |
| 5458 | { 0x17, 0x99130111 }, /* speaker */ |
| 5459 | { 0x18, 0x01a19840 }, /* mic */ |
| 5460 | { 0x21, 0x0121401f }, /* HP */ |
| 5461 | { } |
| 5462 | }, |
| 5463 | .chained = true, |
| 5464 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
Takashi Iwai | 2996bdb | 2011-08-18 16:02:24 +0200 | [diff] [blame] | 5465 | }, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5466 | }; |
| 5467 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 5468 | static const struct snd_pci_quirk alc662_fixup_tbl[] = { |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5469 | SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2), |
David Henningsson | a6c47a8 | 2011-02-10 15:39:19 +0100 | [diff] [blame] | 5470 | SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE), |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 5471 | SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE), |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5472 | SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE), |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 5473 | SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5474 | SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2), |
Daniel T Chen | a0e90ac | 2010-11-20 10:20:35 -0500 | [diff] [blame] | 5475 | SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD), |
Valentine Sinitsyn | d411858 | 2010-10-01 22:24:08 +0600 | [diff] [blame] | 5476 | SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD), |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5477 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD), |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 5478 | SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T), |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5479 | |
| 5480 | #if 0 |
| 5481 | /* Below is a quirk table taken from the old code. |
| 5482 | * Basically the device should work as is without the fixup table. |
| 5483 | * If BIOS doesn't give a proper info, enable the corresponding |
| 5484 | * fixup entry. |
| 5485 | */ |
| 5486 | SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1), |
| 5487 | SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3), |
| 5488 | SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1), |
| 5489 | SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3), |
| 5490 | SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 5491 | SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5492 | SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 5493 | SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1), |
| 5494 | SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1), |
| 5495 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5496 | SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7), |
| 5497 | SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7), |
| 5498 | SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8), |
| 5499 | SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3), |
| 5500 | SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1), |
| 5501 | SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5502 | SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2), |
| 5503 | SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1), |
| 5504 | SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5505 | SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 5506 | SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 5507 | SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5508 | SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1), |
| 5509 | SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3), |
| 5510 | SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2), |
| 5511 | SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5512 | SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5), |
| 5513 | SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 5514 | SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5515 | SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1), |
| 5516 | SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5517 | SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5518 | SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3), |
| 5519 | SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3), |
| 5520 | SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1), |
| 5521 | SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1), |
| 5522 | SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1), |
| 5523 | SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1), |
| 5524 | SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1), |
| 5525 | SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5526 | SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2), |
| 5527 | SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1), |
| 5528 | SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 5529 | SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3), |
| 5530 | SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1), |
| 5531 | SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1), |
| 5532 | SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1), |
| 5533 | SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2), |
| 5534 | SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 5535 | SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4), |
| 5536 | #endif |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5537 | {} |
| 5538 | }; |
| 5539 | |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5540 | static const struct alc_model_fixup alc662_fixup_models[] = { |
| 5541 | {.id = ALC272_FIXUP_MARIO, .name = "mario"}, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5542 | {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"}, |
| 5543 | {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"}, |
| 5544 | {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"}, |
| 5545 | {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"}, |
| 5546 | {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"}, |
| 5547 | {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"}, |
| 5548 | {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"}, |
| 5549 | {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"}, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5550 | {} |
| 5551 | }; |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5552 | |
| 5553 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5554 | /* |
| 5555 | */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5556 | static int patch_alc662(struct hda_codec *codec) |
| 5557 | { |
| 5558 | struct alc_spec *spec; |
Takashi Iwai | b9c5106 | 2011-08-24 18:08:07 +0200 | [diff] [blame^] | 5559 | int err; |
Kailang Yang | 693194f | 2010-10-21 08:51:48 +0200 | [diff] [blame] | 5560 | int coef; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5561 | |
| 5562 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5563 | if (!spec) |
| 5564 | return -ENOMEM; |
| 5565 | |
| 5566 | codec->spec = spec; |
| 5567 | |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 5568 | spec->mixer_nid = 0x0b; |
| 5569 | |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5570 | /* handle multiple HPs as is */ |
| 5571 | spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; |
| 5572 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 5573 | alc_auto_parse_customize_define(codec); |
| 5574 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 5575 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
| 5576 | |
Kailang Yang | 693194f | 2010-10-21 08:51:48 +0200 | [diff] [blame] | 5577 | coef = alc_read_coef_idx(codec, 0); |
| 5578 | if (coef == 0x8020 || coef == 0x8011) |
Kailang Yang | c027ddc | 2010-03-19 11:33:06 +0100 | [diff] [blame] | 5579 | alc_codec_rename(codec, "ALC661"); |
Kailang Yang | 693194f | 2010-10-21 08:51:48 +0200 | [diff] [blame] | 5580 | else if (coef & (1 << 14) && |
| 5581 | codec->bus->pci->subsystem_vendor == 0x1025 && |
| 5582 | spec->cdefine.platform_type == 1) |
Kailang Yang | c027ddc | 2010-03-19 11:33:06 +0100 | [diff] [blame] | 5583 | alc_codec_rename(codec, "ALC272X"); |
Kailang Yang | 693194f | 2010-10-21 08:51:48 +0200 | [diff] [blame] | 5584 | else if (coef == 0x4011) |
| 5585 | alc_codec_rename(codec, "ALC656"); |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 5586 | |
Takashi Iwai | b9c5106 | 2011-08-24 18:08:07 +0200 | [diff] [blame^] | 5587 | alc_pick_fixup(codec, alc662_fixup_models, |
| 5588 | alc662_fixup_tbl, alc662_fixups); |
| 5589 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 5590 | /* automatic parse from the BIOS config */ |
| 5591 | err = alc662_parse_auto_config(codec); |
| 5592 | if (err < 0) { |
| 5593 | alc_free(codec); |
| 5594 | return err; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5595 | } |
| 5596 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5597 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 5598 | alc_auto_fill_adc_caps(codec); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 5599 | alc_rebuild_imux_for_auto_mic(codec); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 5600 | alc_remove_invalid_adc_nids(codec); |
Takashi Iwai | dd70469 | 2009-08-11 08:45:11 +0200 | [diff] [blame] | 5601 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5602 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5603 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | b59bdf3 | 2009-08-11 09:47:30 +0200 | [diff] [blame] | 5604 | set_capture_mixer(codec); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 5605 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5606 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 5607 | err = snd_hda_attach_beep_device(codec, 0x1); |
| 5608 | if (err < 0) { |
| 5609 | alc_free(codec); |
| 5610 | return err; |
| 5611 | } |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 5612 | switch (codec->vendor_id) { |
| 5613 | case 0x10ec0662: |
| 5614 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 5615 | break; |
| 5616 | case 0x10ec0272: |
| 5617 | case 0x10ec0663: |
| 5618 | case 0x10ec0665: |
| 5619 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
| 5620 | break; |
| 5621 | case 0x10ec0273: |
| 5622 | set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT); |
| 5623 | break; |
| 5624 | } |
Kailang Yang | cec27c8 | 2010-02-04 14:18:18 +0100 | [diff] [blame] | 5625 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 5626 | spec->vmaster_nid = 0x02; |
| 5627 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5628 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5629 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5630 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | b9c5106 | 2011-08-24 18:08:07 +0200 | [diff] [blame^] | 5631 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 5632 | spec->shutup = alc_eapd_shutup; |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5633 | |
Kailang Yang | bf1b022 | 2010-10-21 08:49:56 +0200 | [diff] [blame] | 5634 | alc_init_jacks(codec); |
| 5635 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 5636 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5637 | if (!spec->loopback.amplist) |
| 5638 | spec->loopback.amplist = alc662_loopbacks; |
| 5639 | #endif |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5640 | |
| 5641 | return 0; |
| 5642 | } |
| 5643 | |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 5644 | static int patch_alc888(struct hda_codec *codec) |
| 5645 | { |
| 5646 | if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){ |
| 5647 | kfree(codec->chip_name); |
Kailang Yang | 01e0f13 | 2010-11-22 10:59:36 +0100 | [diff] [blame] | 5648 | if (codec->vendor_id == 0x10ec0887) |
| 5649 | codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL); |
| 5650 | else |
| 5651 | codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL); |
Takashi Iwai | ac2c92e | 2009-12-03 10:14:10 +0100 | [diff] [blame] | 5652 | if (!codec->chip_name) { |
| 5653 | alc_free(codec); |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 5654 | return -ENOMEM; |
Takashi Iwai | ac2c92e | 2009-12-03 10:14:10 +0100 | [diff] [blame] | 5655 | } |
| 5656 | return patch_alc662(codec); |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 5657 | } |
Takashi Iwai | ac2c92e | 2009-12-03 10:14:10 +0100 | [diff] [blame] | 5658 | return patch_alc882(codec); |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 5659 | } |
| 5660 | |
Kailang Yang | b478b99 | 2011-05-18 11:51:15 +0200 | [diff] [blame] | 5661 | static int patch_alc899(struct hda_codec *codec) |
| 5662 | { |
| 5663 | if ((alc_read_coef_idx(codec, 0) & 0x2000) != 0x2000) { |
| 5664 | kfree(codec->chip_name); |
| 5665 | codec->chip_name = kstrdup("ALC898", GFP_KERNEL); |
| 5666 | } |
| 5667 | return patch_alc882(codec); |
| 5668 | } |
| 5669 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5670 | /* |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5671 | * ALC680 support |
| 5672 | */ |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5673 | |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5674 | static int alc680_parse_auto_config(struct hda_codec *codec) |
| 5675 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5676 | return alc_parse_auto_config(codec, NULL, NULL); |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5677 | } |
| 5678 | |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5679 | /* |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5680 | */ |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5681 | static int patch_alc680(struct hda_codec *codec) |
| 5682 | { |
| 5683 | struct alc_spec *spec; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5684 | int err; |
| 5685 | |
| 5686 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5687 | if (spec == NULL) |
| 5688 | return -ENOMEM; |
| 5689 | |
| 5690 | codec->spec = spec; |
| 5691 | |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 5692 | /* ALC680 has no aa-loopback mixer */ |
| 5693 | |
Takashi Iwai | 1ebec5f | 2011-08-15 13:21:48 +0200 | [diff] [blame] | 5694 | /* automatic parse from the BIOS config */ |
| 5695 | err = alc680_parse_auto_config(codec); |
| 5696 | if (err < 0) { |
| 5697 | alc_free(codec); |
| 5698 | return err; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5699 | } |
| 5700 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5701 | if (!spec->no_analog && !spec->cap_mixer) |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5702 | set_capture_mixer(codec); |
| 5703 | |
| 5704 | spec->vmaster_nid = 0x02; |
| 5705 | |
| 5706 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 1ebec5f | 2011-08-15 13:21:48 +0200 | [diff] [blame] | 5707 | spec->init_hook = alc_auto_init_std; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5708 | |
| 5709 | return 0; |
| 5710 | } |
| 5711 | |
| 5712 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5713 | * patch entries |
| 5714 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 5715 | static const struct hda_codec_preset snd_hda_preset_realtek[] = { |
Kailang Yang | 296f033 | 2011-05-18 11:52:36 +0200 | [diff] [blame] | 5716 | { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 | { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 }, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 5718 | { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 }, |
Kailang Yang | f6a9224 | 2007-12-13 16:52:54 +0100 | [diff] [blame] | 5719 | { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 }, |
Kailang Yang | a361d84 | 2007-06-05 12:30:55 +0200 | [diff] [blame] | 5720 | { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 }, |
Kailang Yang | f6a9224 | 2007-12-13 16:52:54 +0100 | [diff] [blame] | 5721 | { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 }, |
Kailang Yang | ebb83ee | 2009-12-17 12:23:00 +0100 | [diff] [blame] | 5722 | { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 }, |
Kailang Yang | 01afd41 | 2008-10-15 11:22:09 +0200 | [diff] [blame] | 5723 | { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 }, |
Kailang Yang | ebb83ee | 2009-12-17 12:23:00 +0100 | [diff] [blame] | 5724 | { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 }, |
Kailang Yang | 296f033 | 2011-05-18 11:52:36 +0200 | [diff] [blame] | 5725 | { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 5726 | { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660", |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5727 | .patch = patch_alc861 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 5728 | { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd }, |
| 5729 | { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 }, |
| 5730 | { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd }, |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5731 | { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5732 | .patch = patch_alc882 }, |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5733 | { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1", |
| 5734 | .patch = patch_alc662 }, |
Kailang Yang | 6dda9f4 | 2008-05-27 12:05:31 +0200 | [diff] [blame] | 5735 | { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 }, |
Kailang Yang | cec27c8 | 2010-02-04 14:18:18 +0100 | [diff] [blame] | 5736 | { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 }, |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 5737 | { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 }, |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5738 | { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 5739 | { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5740 | { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5741 | { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 }, |
Clive Messer | 669faba | 2008-09-30 15:49:13 +0200 | [diff] [blame] | 5742 | { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5743 | .patch = patch_alc882 }, |
Takashi Iwai | cb308f9 | 2008-04-16 14:13:29 +0200 | [diff] [blame] | 5744 | { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5745 | .patch = patch_alc882 }, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 5746 | { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, |
Kailang Yang | 01e0f13 | 2010-11-22 10:59:36 +0100 | [diff] [blame] | 5747 | { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 }, |
Kailang Yang | 4442608 | 2008-10-15 11:18:05 +0200 | [diff] [blame] | 5748 | { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5749 | .patch = patch_alc882 }, |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 5750 | { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 }, |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5751 | { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 }, |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 5752 | { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 }, |
Kailang Yang | b478b99 | 2011-05-18 11:51:15 +0200 | [diff] [blame] | 5753 | { .id = 0x10ec0899, .name = "ALC899", .patch = patch_alc899 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5754 | {} /* terminator */ |
| 5755 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 5756 | |
| 5757 | MODULE_ALIAS("snd-hda-codec-id:10ec*"); |
| 5758 | |
| 5759 | MODULE_LICENSE("GPL"); |
| 5760 | MODULE_DESCRIPTION("Realtek HD-audio codec"); |
| 5761 | |
| 5762 | static struct hda_codec_preset_list realtek_list = { |
| 5763 | .preset = snd_hda_preset_realtek, |
| 5764 | .owner = THIS_MODULE, |
| 5765 | }; |
| 5766 | |
| 5767 | static int __init patch_realtek_init(void) |
| 5768 | { |
| 5769 | return snd_hda_add_codec_preset(&realtek_list); |
| 5770 | } |
| 5771 | |
| 5772 | static void __exit patch_realtek_exit(void) |
| 5773 | { |
| 5774 | snd_hda_delete_codec_preset(&realtek_list); |
| 5775 | } |
| 5776 | |
| 5777 | module_init(patch_realtek_init) |
| 5778 | module_exit(patch_realtek_exit) |