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