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