Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Universal Interface for Intel High Definition Audio Codec |
| 3 | * |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4 | * HD audio interface patch for Realtek ALC codecs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 6 | * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw> |
| 7 | * PeiSen Hou <pshou@realtek.com.tw> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Takashi Iwai <tiwai@suse.de> |
Jonathan Woithe | 7cf51e48 | 2006-02-09 12:01:26 +0100 | [diff] [blame] | 9 | * Jonathan Woithe <jwoithe@physics.adelaide.edu.au> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * This driver is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This driver is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | */ |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/init.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/pci.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 30 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <sound/core.h> |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 32 | #include <sound/jack.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "hda_codec.h" |
| 34 | #include "hda_local.h" |
Kusanagi Kouichi | 680cd53 | 2009-02-05 00:00:58 +0900 | [diff] [blame] | 35 | #include "hda_beep.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 37 | /* unsol event tags */ |
| 38 | #define ALC_FRONT_EVENT 0x01 |
| 39 | #define ALC_DCVOL_EVENT 0x02 |
| 40 | #define ALC_HP_EVENT 0x04 |
| 41 | #define ALC_MIC_EVENT 0x08 |
Takashi Iwai | d4a86d8 | 2010-06-23 17:51:26 +0200 | [diff] [blame] | 42 | |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 43 | /* for GPIO Poll */ |
| 44 | #define GPIO_MASK 0x03 |
| 45 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 46 | /* extra amp-initialization sequence types */ |
| 47 | enum { |
| 48 | ALC_INIT_NONE, |
| 49 | ALC_INIT_DEFAULT, |
| 50 | ALC_INIT_GPIO1, |
| 51 | ALC_INIT_GPIO2, |
| 52 | ALC_INIT_GPIO3, |
| 53 | }; |
| 54 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 55 | struct alc_customize_define { |
| 56 | unsigned int sku_cfg; |
| 57 | unsigned char port_connectivity; |
| 58 | unsigned char check_sum; |
| 59 | unsigned char customization; |
| 60 | unsigned char external_amp; |
| 61 | unsigned int enable_pcbeep:1; |
| 62 | unsigned int platform_type:1; |
| 63 | unsigned int swap:1; |
| 64 | unsigned int override:1; |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 65 | 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] | 66 | }; |
| 67 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 68 | struct alc_fixup; |
| 69 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 70 | struct alc_multi_io { |
| 71 | hda_nid_t pin; /* multi-io widget pin NID */ |
| 72 | hda_nid_t dac; /* DAC to be connected */ |
| 73 | unsigned int ctl_in; /* cached input-pin control value */ |
| 74 | }; |
| 75 | |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 76 | enum { |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 77 | ALC_AUTOMUTE_PIN, /* change the pin control */ |
| 78 | ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */ |
| 79 | ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */ |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | struct alc_spec { |
| 83 | /* codec parameterization */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 84 | const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | unsigned int num_mixers; |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 86 | const struct snd_kcontrol_new *cap_mixer; /* capture mixer */ |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 87 | unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Takashi Iwai | 2d9c648 | 2009-10-13 08:06:55 +0200 | [diff] [blame] | 89 | const struct hda_verb *init_verbs[10]; /* initialization verbs |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 90 | * don't forget NULL |
| 91 | * termination! |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 92 | */ |
| 93 | unsigned int num_init_verbs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Takashi Iwai | aa563af | 2009-07-31 10:05:11 +0200 | [diff] [blame] | 95 | char stream_name_analog[32]; /* analog PCM stream */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 96 | const struct hda_pcm_stream *stream_analog_playback; |
| 97 | const struct hda_pcm_stream *stream_analog_capture; |
| 98 | const struct hda_pcm_stream *stream_analog_alt_playback; |
| 99 | const struct hda_pcm_stream *stream_analog_alt_capture; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Takashi Iwai | aa563af | 2009-07-31 10:05:11 +0200 | [diff] [blame] | 101 | char stream_name_digital[32]; /* digital PCM stream */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 102 | const struct hda_pcm_stream *stream_digital_playback; |
| 103 | const struct hda_pcm_stream *stream_digital_capture; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | /* playback */ |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 106 | struct hda_multi_out multiout; /* playback set-up |
| 107 | * max_channels, dacs must be set |
| 108 | * dig_out_nid and hp_nid are optional |
| 109 | */ |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 110 | hda_nid_t alt_dac_nid; |
Takashi Iwai | 6a05ac4 | 2009-02-13 11:19:09 +0100 | [diff] [blame] | 111 | hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */ |
Takashi Iwai | 8c44198 | 2009-01-20 18:30:20 +0100 | [diff] [blame] | 112 | int dig_out_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | /* capture */ |
| 115 | unsigned int num_adc_nids; |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 116 | const hda_nid_t *adc_nids; |
| 117 | const hda_nid_t *capsrc_nids; |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 118 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 119 | hda_nid_t mixer_nid; /* analog-mixer NID */ |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 120 | DECLARE_BITMAP(vol_ctls, 0x20 << 1); |
| 121 | DECLARE_BITMAP(sw_ctls, 0x20 << 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 123 | /* capture setup for dynamic dual-adc switch */ |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 124 | hda_nid_t cur_adc; |
| 125 | unsigned int cur_adc_stream_tag; |
| 126 | unsigned int cur_adc_format; |
| 127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | /* capture source */ |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 129 | unsigned int num_mux_defs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | const struct hda_input_mux *input_mux; |
| 131 | unsigned int cur_mux[3]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 132 | hda_nid_t ext_mic_pin; |
| 133 | hda_nid_t dock_mic_pin; |
| 134 | hda_nid_t int_mic_pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | /* channel model */ |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 137 | const struct hda_channel_mode *channel_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | int num_channel_mode; |
Takashi Iwai | 4e195a7 | 2006-07-28 14:47:34 +0200 | [diff] [blame] | 139 | int need_dac_fix; |
Hector Martin | 3b315d7 | 2009-06-02 10:54:19 +0200 | [diff] [blame] | 140 | int const_channel_count; |
| 141 | int ext_channel_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
| 143 | /* PCM information */ |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 144 | struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */ |
Takashi Iwai | 41e41f1 | 2005-06-08 14:48:49 +0200 | [diff] [blame] | 145 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 146 | /* dynamic controls, init_verbs and input_mux */ |
| 147 | struct auto_pin_cfg autocfg; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 148 | struct alc_customize_define cdefine; |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 149 | struct snd_array kctls; |
Herton Ronaldo Krzesinski | 61b9b9b | 2009-01-28 09:16:33 -0200 | [diff] [blame] | 150 | struct hda_input_mux private_imux[3]; |
Takashi Iwai | 41923e4 | 2007-10-22 17:20:10 +0200 | [diff] [blame] | 151 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 152 | hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS]; |
| 153 | hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 154 | hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS]; |
| 155 | unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS]; |
| 156 | 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] | 157 | |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 158 | /* hooks */ |
| 159 | void (*init_hook)(struct hda_codec *codec); |
| 160 | void (*unsol_event)(struct hda_codec *codec, unsigned int res); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 161 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 162 | void (*power_hook)(struct hda_codec *codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 163 | #endif |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 164 | void (*shutup)(struct hda_codec *codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 165 | void (*automute_hook)(struct hda_codec *codec); |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 166 | |
Takashi Iwai | 834be88 | 2006-03-01 14:16:17 +0100 | [diff] [blame] | 167 | /* for pin sensing */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 168 | unsigned int hp_jack_present:1; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 169 | unsigned int line_jack_present:1; |
Takashi Iwai | e942796 | 2011-04-28 15:46:07 +0200 | [diff] [blame] | 170 | unsigned int master_mute:1; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 171 | unsigned int auto_mic:1; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 172 | unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 173 | unsigned int automute_speaker:1; /* automute speaker outputs */ |
| 174 | unsigned int automute_lo:1; /* automute LO outputs */ |
| 175 | unsigned int detect_hp:1; /* Headphone detection enabled */ |
| 176 | unsigned int detect_lo:1; /* Line-out detection enabled */ |
| 177 | unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */ |
| 178 | unsigned int automute_lo_possible:1; /* there are line outs and HP */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 179 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 180 | /* other flags */ |
| 181 | unsigned int no_analog :1; /* digital I/O only */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 182 | unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */ |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 183 | unsigned int single_input_src:1; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 184 | unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */ |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 185 | unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */ |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 186 | |
| 187 | /* auto-mute control */ |
| 188 | int automute_mode; |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 189 | hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 190 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 191 | int init_amp; |
Takashi Iwai | d433a67 | 2010-09-20 15:11:54 +0200 | [diff] [blame] | 192 | int codec_variant; /* flag for other variants */ |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 193 | |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 194 | /* for virtual master */ |
| 195 | hda_nid_t vmaster_nid; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 196 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 197 | struct hda_loopback_check loopback; |
| 198 | #endif |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 199 | |
| 200 | /* for PLL fix */ |
| 201 | hda_nid_t pll_nid; |
| 202 | unsigned int pll_coef_idx, pll_coef_bit; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 203 | unsigned int coef0; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 204 | |
| 205 | /* fix-up list */ |
| 206 | int fixup_id; |
| 207 | const struct alc_fixup *fixup_list; |
| 208 | const char *fixup_name; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 209 | |
| 210 | /* multi-io */ |
| 211 | int multi_ios; |
| 212 | struct alc_multi_io multi_io[4]; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 213 | |
| 214 | /* bind volumes */ |
| 215 | struct snd_array bind_ctls; |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 216 | }; |
| 217 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 218 | #define ALC_MODEL_AUTO 0 /* common for all chips */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 220 | static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, |
| 221 | int dir, unsigned int bits) |
| 222 | { |
| 223 | if (!nid) |
| 224 | return false; |
| 225 | if (get_wcaps(codec, nid) & (1 << (dir + 1))) |
| 226 | if (query_amp_caps(codec, nid, dir) & bits) |
| 227 | return true; |
| 228 | return false; |
| 229 | } |
| 230 | |
| 231 | #define nid_has_mute(codec, nid, dir) \ |
| 232 | check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE) |
| 233 | #define nid_has_volume(codec, nid, dir) \ |
| 234 | check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS) |
| 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | /* |
| 237 | * input MUX handling |
| 238 | */ |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 239 | static int alc_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 240 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
| 242 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 243 | struct alc_spec *spec = codec->spec; |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 244 | unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id); |
| 245 | if (mux_idx >= spec->num_mux_defs) |
| 246 | mux_idx = 0; |
Takashi Iwai | 5311114 | 2010-03-08 12:13:07 +0100 | [diff] [blame] | 247 | if (!spec->input_mux[mux_idx].num_items && mux_idx > 0) |
| 248 | mux_idx = 0; |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 249 | return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 252 | static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 253 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
| 255 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 256 | struct alc_spec *spec = codec->spec; |
| 257 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 258 | |
| 259 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
| 260 | return 0; |
| 261 | } |
| 262 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 263 | 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] | 264 | { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 265 | struct alc_spec *spec = codec->spec; |
| 266 | hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]]; |
| 267 | |
| 268 | if (spec->cur_adc && spec->cur_adc != new_adc) { |
| 269 | /* stream is running, let's swap the current ADC */ |
| 270 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); |
| 271 | spec->cur_adc = new_adc; |
| 272 | snd_hda_codec_setup_stream(codec, new_adc, |
| 273 | spec->cur_adc_stream_tag, 0, |
| 274 | spec->cur_adc_format); |
| 275 | return true; |
| 276 | } |
| 277 | return false; |
| 278 | } |
| 279 | |
| 280 | /* select the given imux item; either unmute exclusively or select the route */ |
| 281 | static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx, |
| 282 | unsigned int idx, bool force) |
| 283 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 285 | const struct hda_input_mux *imux; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 286 | unsigned int mux_idx; |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 287 | int i, type, num_conns; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 288 | hda_nid_t nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 290 | mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; |
| 291 | imux = &spec->input_mux[mux_idx]; |
Takashi Iwai | 5311114 | 2010-03-08 12:13:07 +0100 | [diff] [blame] | 292 | if (!imux->num_items && mux_idx > 0) |
| 293 | imux = &spec->input_mux[0]; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 294 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 295 | if (idx >= imux->num_items) |
| 296 | idx = imux->num_items - 1; |
| 297 | if (spec->cur_mux[adc_idx] == idx && !force) |
| 298 | return 0; |
| 299 | spec->cur_mux[adc_idx] = idx; |
| 300 | |
| 301 | if (spec->dyn_adc_switch) { |
| 302 | alc_dyn_adc_pcm_resetup(codec, idx); |
| 303 | adc_idx = spec->dyn_adc_idx[idx]; |
| 304 | } |
| 305 | |
| 306 | nid = spec->capsrc_nids ? |
| 307 | spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx]; |
| 308 | |
| 309 | /* no selection? */ |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 310 | num_conns = snd_hda_get_conn_list(codec, nid, NULL); |
| 311 | if (num_conns <= 1) |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 312 | return 1; |
| 313 | |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 314 | type = get_wcaps_type(get_wcaps(codec, nid)); |
Takashi Iwai | 0169b6b | 2009-06-22 10:50:19 +0200 | [diff] [blame] | 315 | if (type == AC_WID_AUD_MIX) { |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 316 | /* Matrix-mixer style (e.g. ALC882) */ |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 317 | int active = imux->items[idx].index; |
| 318 | for (i = 0; i < num_conns; i++) { |
| 319 | unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE; |
| 320 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i, |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 321 | HDA_AMP_MUTE, v); |
| 322 | } |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 323 | } else { |
| 324 | /* MUX style (e.g. ALC880) */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 325 | snd_hda_codec_write_cache(codec, nid, 0, |
| 326 | AC_VERB_SET_CONNECT_SEL, |
| 327 | imux->items[idx].index); |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 328 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 329 | return 1; |
| 330 | } |
| 331 | |
| 332 | static int alc_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 333 | struct snd_ctl_elem_value *ucontrol) |
| 334 | { |
| 335 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 336 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 337 | return alc_mux_select(codec, adc_idx, |
| 338 | ucontrol->value.enumerated.item[0], false); |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 339 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | /* |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 342 | * set up the input pin config (depending on the given auto-pin type) |
| 343 | */ |
| 344 | static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid, |
| 345 | int auto_pin_type) |
| 346 | { |
| 347 | unsigned int val = PIN_IN; |
| 348 | |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 349 | if (auto_pin_type == AUTO_PIN_MIC) { |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 350 | unsigned int pincap; |
Takashi Iwai | 954a29c | 2010-07-30 10:55:44 +0200 | [diff] [blame] | 351 | unsigned int oldval; |
| 352 | oldval = snd_hda_codec_read(codec, nid, 0, |
| 353 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
Takashi Iwai | 1327a32 | 2009-03-23 13:07:47 +0100 | [diff] [blame] | 354 | pincap = snd_hda_query_pin_caps(codec, nid); |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 355 | pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; |
Takashi Iwai | 954a29c | 2010-07-30 10:55:44 +0200 | [diff] [blame] | 356 | /* if the default pin setup is vref50, we give it priority */ |
| 357 | if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50) |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 358 | val = PIN_VREF80; |
Takashi Iwai | 461c6c3 | 2009-05-25 08:06:02 +0200 | [diff] [blame] | 359 | else if (pincap & AC_PINCAP_VREF_50) |
| 360 | val = PIN_VREF50; |
| 361 | else if (pincap & AC_PINCAP_VREF_100) |
| 362 | val = PIN_VREF100; |
| 363 | else if (pincap & AC_PINCAP_VREF_GRD) |
| 364 | val = PIN_VREFGRD; |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 365 | } |
| 366 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val); |
| 367 | } |
| 368 | |
| 369 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 370 | * Append the given mixer and verb elements for the later use |
| 371 | * The mixer array is referred in build_controls(), and init_verbs are |
| 372 | * called in init(). |
Takashi Iwai | d88897e | 2008-10-31 15:01:37 +0100 | [diff] [blame] | 373 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 374 | 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] | 375 | { |
| 376 | if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers))) |
| 377 | return; |
| 378 | spec->mixers[spec->num_mixers++] = mix; |
| 379 | } |
| 380 | |
| 381 | static void add_verb(struct alc_spec *spec, const struct hda_verb *verb) |
| 382 | { |
| 383 | if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs))) |
| 384 | return; |
| 385 | spec->init_verbs[spec->num_init_verbs++] = verb; |
| 386 | } |
| 387 | |
| 388 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 389 | * GPIO setup tables, used in initialization |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 390 | */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 391 | /* Enable GPIO mask and set output */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 392 | static const struct hda_verb alc_gpio1_init_verbs[] = { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 393 | {0x01, AC_VERB_SET_GPIO_MASK, 0x01}, |
| 394 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, |
| 395 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, |
| 396 | { } |
| 397 | }; |
| 398 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 399 | static const struct hda_verb alc_gpio2_init_verbs[] = { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 400 | {0x01, AC_VERB_SET_GPIO_MASK, 0x02}, |
| 401 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02}, |
| 402 | {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, |
| 403 | { } |
| 404 | }; |
| 405 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 406 | static const struct hda_verb alc_gpio3_init_verbs[] = { |
Kailang Yang | bdd148a | 2007-05-08 15:19:08 +0200 | [diff] [blame] | 407 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, |
| 408 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03}, |
| 409 | {0x01, AC_VERB_SET_GPIO_DATA, 0x03}, |
| 410 | { } |
| 411 | }; |
| 412 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 413 | /* |
| 414 | * Fix hardware PLL issue |
| 415 | * On some codecs, the analog PLL gating control must be off while |
| 416 | * the default value is 1. |
| 417 | */ |
| 418 | static void alc_fix_pll(struct hda_codec *codec) |
| 419 | { |
| 420 | struct alc_spec *spec = codec->spec; |
| 421 | unsigned int val; |
| 422 | |
| 423 | if (!spec->pll_nid) |
| 424 | return; |
| 425 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, |
| 426 | spec->pll_coef_idx); |
| 427 | val = snd_hda_codec_read(codec, spec->pll_nid, 0, |
| 428 | AC_VERB_GET_PROC_COEF, 0); |
| 429 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, |
| 430 | spec->pll_coef_idx); |
| 431 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF, |
| 432 | val & ~(1 << spec->pll_coef_bit)); |
| 433 | } |
| 434 | |
| 435 | static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid, |
| 436 | unsigned int coef_idx, unsigned int coef_bit) |
| 437 | { |
| 438 | struct alc_spec *spec = codec->spec; |
| 439 | spec->pll_nid = nid; |
| 440 | spec->pll_coef_idx = coef_idx; |
| 441 | spec->pll_coef_bit = coef_bit; |
| 442 | alc_fix_pll(codec); |
| 443 | } |
| 444 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 445 | /* |
| 446 | * Jack-reporting via input-jack layer |
| 447 | */ |
| 448 | |
| 449 | /* initialization of jacks; currently checks only a few known pins */ |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 450 | static int alc_init_jacks(struct hda_codec *codec) |
| 451 | { |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 452 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 453 | struct alc_spec *spec = codec->spec; |
| 454 | int err; |
| 455 | unsigned int hp_nid = spec->autocfg.hp_pins[0]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 456 | unsigned int mic_nid = spec->ext_mic_pin; |
| 457 | unsigned int dock_nid = spec->dock_mic_pin; |
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 (hp_nid) { |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 460 | err = snd_hda_input_jack_add(codec, hp_nid, |
| 461 | SND_JACK_HEADPHONE, 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, hp_nid); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 465 | } |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 466 | |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 467 | if (mic_nid) { |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 468 | err = snd_hda_input_jack_add(codec, mic_nid, |
| 469 | SND_JACK_MICROPHONE, NULL); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 470 | if (err < 0) |
| 471 | return err; |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 472 | snd_hda_input_jack_report(codec, mic_nid); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 473 | } |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 474 | if (dock_nid) { |
| 475 | err = snd_hda_input_jack_add(codec, dock_nid, |
| 476 | SND_JACK_MICROPHONE, NULL); |
| 477 | if (err < 0) |
| 478 | return err; |
| 479 | snd_hda_input_jack_report(codec, dock_nid); |
| 480 | } |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 481 | #endif /* CONFIG_SND_HDA_INPUT_JACK */ |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 482 | return 0; |
| 483 | } |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 484 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 485 | /* |
| 486 | * Jack detections for HP auto-mute and mic-switch |
| 487 | */ |
| 488 | |
| 489 | /* check each pin in the given array; returns true if any of them is plugged */ |
| 490 | 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] | 491 | { |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 492 | int i, present = 0; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 493 | |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 494 | for (i = 0; i < num_pins; i++) { |
| 495 | hda_nid_t nid = pins[i]; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 496 | if (!nid) |
| 497 | break; |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 498 | snd_hda_input_jack_report(codec, nid); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 499 | present |= snd_hda_jack_detect(codec, nid); |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 500 | } |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 501 | return present; |
| 502 | } |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 503 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 504 | /* standard HP/line-out auto-mute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 505 | 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] | 506 | bool mute, bool hp_out) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 507 | { |
| 508 | struct alc_spec *spec = codec->spec; |
| 509 | unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0; |
Takashi Iwai | e942796 | 2011-04-28 15:46:07 +0200 | [diff] [blame] | 510 | unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 511 | int i; |
| 512 | |
| 513 | for (i = 0; i < num_pins; i++) { |
| 514 | hda_nid_t nid = pins[i]; |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 515 | if (!nid) |
| 516 | break; |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 517 | switch (spec->automute_mode) { |
| 518 | case ALC_AUTOMUTE_PIN: |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 519 | snd_hda_codec_write(codec, nid, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 520 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 521 | pin_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 522 | break; |
| 523 | case ALC_AUTOMUTE_AMP: |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 524 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 525 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 526 | break; |
| 527 | case ALC_AUTOMUTE_MIXER: |
| 528 | nid = spec->automute_mixer_nid[i]; |
| 529 | if (!nid) |
| 530 | break; |
| 531 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 532 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 533 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 534 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 535 | break; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 536 | } |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 537 | } |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 538 | } |
| 539 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 540 | /* Toggle outputs muting */ |
| 541 | static void update_outputs(struct hda_codec *codec) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 542 | { |
| 543 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 544 | int on; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 545 | |
Takashi Iwai | c0a2026 | 2011-06-10 15:28:15 +0200 | [diff] [blame] | 546 | /* Control HP pins/amps depending on master_mute state; |
| 547 | * in general, HP pins/amps control should be enabled in all cases, |
| 548 | * but currently set only for master_mute, just to be safe |
| 549 | */ |
| 550 | do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins), |
| 551 | spec->autocfg.hp_pins, spec->master_mute, true); |
| 552 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 553 | if (!spec->automute_speaker) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 554 | on = 0; |
| 555 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 556 | on = spec->hp_jack_present | spec->line_jack_present; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 557 | on |= spec->master_mute; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 558 | do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins), |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 559 | spec->autocfg.speaker_pins, on, false); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 560 | |
| 561 | /* toggle line-out mutes if needed, too */ |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 562 | /* if LO is a copy of either HP or Speaker, don't need to handle it */ |
| 563 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] || |
| 564 | spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0]) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 565 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 566 | if (!spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 567 | on = 0; |
| 568 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 569 | on = spec->hp_jack_present; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 570 | on |= spec->master_mute; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 571 | do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 572 | spec->autocfg.line_out_pins, on, false); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 573 | } |
| 574 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 575 | static void call_update_outputs(struct hda_codec *codec) |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 576 | { |
| 577 | struct alc_spec *spec = codec->spec; |
| 578 | if (spec->automute_hook) |
| 579 | spec->automute_hook(codec); |
| 580 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 581 | update_outputs(codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 582 | } |
| 583 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 584 | /* standard HP-automute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 585 | static void alc_hp_automute(struct hda_codec *codec) |
| 586 | { |
| 587 | struct alc_spec *spec = codec->spec; |
| 588 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 589 | spec->hp_jack_present = |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 590 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins), |
| 591 | spec->autocfg.hp_pins); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 592 | if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo)) |
Takashi Iwai | 3c715a9 | 2011-08-23 12:41:09 +0200 | [diff] [blame] | 593 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 594 | call_update_outputs(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 595 | } |
| 596 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 597 | /* standard line-out-automute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 598 | static void alc_line_automute(struct hda_codec *codec) |
| 599 | { |
| 600 | struct alc_spec *spec = codec->spec; |
| 601 | |
Takashi Iwai | e0d32e3 | 2011-09-26 15:19:55 +0200 | [diff] [blame] | 602 | /* check LO jack only when it's different from HP */ |
| 603 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0]) |
| 604 | return; |
| 605 | |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 606 | spec->line_jack_present = |
| 607 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
| 608 | spec->autocfg.line_out_pins); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 609 | if (!spec->automute_speaker || !spec->detect_lo) |
Takashi Iwai | 3c715a9 | 2011-08-23 12:41:09 +0200 | [diff] [blame] | 610 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 611 | call_update_outputs(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 612 | } |
| 613 | |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 614 | #define get_connection_index(codec, mux, nid) \ |
| 615 | snd_hda_get_conn_index(codec, mux, nid, 0) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 616 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 617 | /* standard mic auto-switch helper */ |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 618 | static void alc_mic_automute(struct hda_codec *codec) |
| 619 | { |
| 620 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 621 | hda_nid_t *pins = spec->imux_pins; |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 622 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 623 | if (!spec->auto_mic || !spec->auto_mic_valid_imux) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 624 | return; |
| 625 | if (snd_BUG_ON(!spec->adc_nids)) |
| 626 | return; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 627 | 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] | 628 | return; |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 629 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 630 | if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx])) |
| 631 | alc_mux_select(codec, 0, spec->ext_mic_idx, false); |
| 632 | else if (spec->dock_mic_idx >= 0 && |
| 633 | snd_hda_jack_detect(codec, pins[spec->dock_mic_idx])) |
| 634 | alc_mux_select(codec, 0, spec->dock_mic_idx, false); |
| 635 | else |
| 636 | alc_mux_select(codec, 0, spec->int_mic_idx, false); |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 637 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 638 | snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]); |
| 639 | if (spec->dock_mic_idx >= 0) |
| 640 | snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 641 | } |
| 642 | |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 643 | /* unsolicited event for HP jack sensing */ |
| 644 | static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res) |
| 645 | { |
| 646 | if (codec->vendor_id == 0x10ec0880) |
| 647 | res >>= 28; |
| 648 | else |
| 649 | res >>= 26; |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 650 | switch (res) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 651 | case ALC_HP_EVENT: |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 652 | alc_hp_automute(codec); |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 653 | break; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 654 | case ALC_FRONT_EVENT: |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 655 | alc_line_automute(codec); |
| 656 | break; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 657 | case ALC_MIC_EVENT: |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 658 | alc_mic_automute(codec); |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 659 | break; |
| 660 | } |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 661 | } |
| 662 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 663 | /* call init functions of standard auto-mute helpers */ |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 664 | static void alc_inithook(struct hda_codec *codec) |
| 665 | { |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 666 | alc_hp_automute(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 667 | alc_line_automute(codec); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 668 | alc_mic_automute(codec); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 669 | } |
| 670 | |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 671 | /* additional initialization for ALC888 variants */ |
| 672 | static void alc888_coef_init(struct hda_codec *codec) |
| 673 | { |
| 674 | unsigned int tmp; |
| 675 | |
| 676 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0); |
| 677 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 678 | 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] | 679 | if ((tmp & 0xf0) == 0x20) |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 680 | /* alc888S-VC */ |
| 681 | snd_hda_codec_read(codec, 0x20, 0, |
| 682 | AC_VERB_SET_PROC_COEF, 0x830); |
| 683 | else |
| 684 | /* alc888-VB */ |
| 685 | snd_hda_codec_read(codec, 0x20, 0, |
| 686 | AC_VERB_SET_PROC_COEF, 0x3030); |
| 687 | } |
| 688 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 689 | /* additional initialization for ALC889 variants */ |
Jaroslav Kysela | 87a8c37 | 2009-07-23 10:58:29 +0200 | [diff] [blame] | 690 | static void alc889_coef_init(struct hda_codec *codec) |
| 691 | { |
| 692 | unsigned int tmp; |
| 693 | |
| 694 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 695 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 696 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 697 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010); |
| 698 | } |
| 699 | |
Takashi Iwai | 3fb4a50 | 2010-01-19 15:46:37 +0100 | [diff] [blame] | 700 | /* turn on/off EAPD control (only if available) */ |
| 701 | static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on) |
| 702 | { |
| 703 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) |
| 704 | return; |
| 705 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) |
| 706 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE, |
| 707 | on ? 2 : 0); |
| 708 | } |
| 709 | |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 710 | /* turn on/off EAPD controls of the codec */ |
| 711 | static void alc_auto_setup_eapd(struct hda_codec *codec, bool on) |
| 712 | { |
| 713 | /* We currently only handle front, HP */ |
Takashi Iwai | 39fa84e | 2011-06-27 15:28:57 +0200 | [diff] [blame] | 714 | static hda_nid_t pins[] = { |
| 715 | 0x0f, 0x10, 0x14, 0x15, 0 |
| 716 | }; |
| 717 | hda_nid_t *p; |
| 718 | for (p = pins; *p; p++) |
| 719 | set_eapd(codec, *p, on); |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 720 | } |
| 721 | |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 722 | /* generic shutup callback; |
| 723 | * just turning off EPAD and a little pause for avoiding pop-noise |
| 724 | */ |
| 725 | static void alc_eapd_shutup(struct hda_codec *codec) |
| 726 | { |
| 727 | alc_auto_setup_eapd(codec, false); |
| 728 | msleep(200); |
| 729 | } |
| 730 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 731 | /* generic EAPD initialization */ |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 732 | static void alc_auto_init_amp(struct hda_codec *codec, int type) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 733 | { |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 734 | unsigned int tmp; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 735 | |
Takashi Iwai | 39fa84e | 2011-06-27 15:28:57 +0200 | [diff] [blame] | 736 | alc_auto_setup_eapd(codec, true); |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 737 | switch (type) { |
| 738 | case ALC_INIT_GPIO1: |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 739 | snd_hda_sequence_write(codec, alc_gpio1_init_verbs); |
| 740 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 741 | case ALC_INIT_GPIO2: |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 742 | snd_hda_sequence_write(codec, alc_gpio2_init_verbs); |
| 743 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 744 | case ALC_INIT_GPIO3: |
Kailang Yang | bdd148a | 2007-05-08 15:19:08 +0200 | [diff] [blame] | 745 | snd_hda_sequence_write(codec, alc_gpio3_init_verbs); |
| 746 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 747 | case ALC_INIT_DEFAULT: |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 748 | switch (codec->vendor_id) { |
| 749 | case 0x10ec0260: |
| 750 | snd_hda_codec_write(codec, 0x1a, 0, |
| 751 | AC_VERB_SET_COEF_INDEX, 7); |
| 752 | tmp = snd_hda_codec_read(codec, 0x1a, 0, |
| 753 | AC_VERB_GET_PROC_COEF, 0); |
| 754 | snd_hda_codec_write(codec, 0x1a, 0, |
| 755 | AC_VERB_SET_COEF_INDEX, 7); |
| 756 | snd_hda_codec_write(codec, 0x1a, 0, |
| 757 | AC_VERB_SET_PROC_COEF, |
| 758 | tmp | 0x2010); |
| 759 | break; |
| 760 | case 0x10ec0262: |
| 761 | case 0x10ec0880: |
| 762 | case 0x10ec0882: |
| 763 | case 0x10ec0883: |
| 764 | case 0x10ec0885: |
Takashi Iwai | 4a5a4c5 | 2009-02-06 12:46:59 +0100 | [diff] [blame] | 765 | case 0x10ec0887: |
Takashi Iwai | 20b67dd | 2011-03-23 22:54:32 +0100 | [diff] [blame] | 766 | /*case 0x10ec0889:*/ /* this causes an SPDIF problem */ |
Jaroslav Kysela | 87a8c37 | 2009-07-23 10:58:29 +0200 | [diff] [blame] | 767 | alc889_coef_init(codec); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 768 | break; |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 769 | case 0x10ec0888: |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 770 | alc888_coef_init(codec); |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 771 | break; |
Takashi Iwai | 0aea778 | 2010-01-25 15:44:11 +0100 | [diff] [blame] | 772 | #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] | 773 | case 0x10ec0267: |
| 774 | case 0x10ec0268: |
| 775 | snd_hda_codec_write(codec, 0x20, 0, |
| 776 | AC_VERB_SET_COEF_INDEX, 7); |
| 777 | tmp = snd_hda_codec_read(codec, 0x20, 0, |
| 778 | AC_VERB_GET_PROC_COEF, 0); |
| 779 | snd_hda_codec_write(codec, 0x20, 0, |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 780 | AC_VERB_SET_COEF_INDEX, 7); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 781 | snd_hda_codec_write(codec, 0x20, 0, |
| 782 | AC_VERB_SET_PROC_COEF, |
| 783 | tmp | 0x3000); |
| 784 | break; |
Takashi Iwai | 0aea778 | 2010-01-25 15:44:11 +0100 | [diff] [blame] | 785 | #endif /* XXX */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 786 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 787 | break; |
| 788 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 789 | } |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 790 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 791 | /* |
| 792 | * Auto-Mute mode mixer enum support |
| 793 | */ |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 794 | static int alc_automute_mode_info(struct snd_kcontrol *kcontrol, |
| 795 | struct snd_ctl_elem_info *uinfo) |
| 796 | { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 797 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 798 | struct alc_spec *spec = codec->spec; |
| 799 | static const char * const texts2[] = { |
| 800 | "Disabled", "Enabled" |
| 801 | }; |
| 802 | static const char * const texts3[] = { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 803 | "Disabled", "Speaker Only", "Line-Out+Speaker" |
| 804 | }; |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 805 | const char * const *texts; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 806 | |
| 807 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 808 | uinfo->count = 1; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 809 | if (spec->automute_speaker_possible && spec->automute_lo_possible) { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 810 | uinfo->value.enumerated.items = 3; |
| 811 | texts = texts3; |
| 812 | } else { |
| 813 | uinfo->value.enumerated.items = 2; |
| 814 | texts = texts2; |
| 815 | } |
| 816 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 817 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 818 | strcpy(uinfo->value.enumerated.name, |
| 819 | texts[uinfo->value.enumerated.item]); |
| 820 | return 0; |
| 821 | } |
| 822 | |
| 823 | static int alc_automute_mode_get(struct snd_kcontrol *kcontrol, |
| 824 | struct snd_ctl_elem_value *ucontrol) |
| 825 | { |
| 826 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 827 | struct alc_spec *spec = codec->spec; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 828 | unsigned int val = 0; |
| 829 | if (spec->automute_speaker) |
| 830 | val++; |
| 831 | if (spec->automute_lo) |
| 832 | val++; |
| 833 | |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 834 | ucontrol->value.enumerated.item[0] = val; |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | static int alc_automute_mode_put(struct snd_kcontrol *kcontrol, |
| 839 | struct snd_ctl_elem_value *ucontrol) |
| 840 | { |
| 841 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 842 | struct alc_spec *spec = codec->spec; |
| 843 | |
| 844 | switch (ucontrol->value.enumerated.item[0]) { |
| 845 | case 0: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 846 | if (!spec->automute_speaker && !spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 847 | return 0; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 848 | spec->automute_speaker = 0; |
| 849 | spec->automute_lo = 0; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 850 | break; |
| 851 | case 1: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 852 | if (spec->automute_speaker_possible) { |
| 853 | if (!spec->automute_lo && spec->automute_speaker) |
| 854 | return 0; |
| 855 | spec->automute_speaker = 1; |
| 856 | spec->automute_lo = 0; |
| 857 | } else if (spec->automute_lo_possible) { |
| 858 | if (spec->automute_lo) |
| 859 | return 0; |
| 860 | spec->automute_lo = 1; |
| 861 | } else |
| 862 | return -EINVAL; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 863 | break; |
| 864 | case 2: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 865 | if (!spec->automute_lo_possible || !spec->automute_speaker_possible) |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 866 | return -EINVAL; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 867 | if (spec->automute_speaker && spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 868 | return 0; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 869 | spec->automute_speaker = 1; |
| 870 | spec->automute_lo = 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 871 | break; |
| 872 | default: |
| 873 | return -EINVAL; |
| 874 | } |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 875 | call_update_outputs(codec); |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 876 | return 1; |
| 877 | } |
| 878 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 879 | static const struct snd_kcontrol_new alc_automute_mode_enum = { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 880 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 881 | .name = "Auto-Mute Mode", |
| 882 | .info = alc_automute_mode_info, |
| 883 | .get = alc_automute_mode_get, |
| 884 | .put = alc_automute_mode_put, |
| 885 | }; |
| 886 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 887 | static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec) |
| 888 | { |
| 889 | snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32); |
| 890 | return snd_array_new(&spec->kctls); |
| 891 | } |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 892 | |
| 893 | static int alc_add_automute_mode_enum(struct hda_codec *codec) |
| 894 | { |
| 895 | struct alc_spec *spec = codec->spec; |
| 896 | struct snd_kcontrol_new *knew; |
| 897 | |
| 898 | knew = alc_kcontrol_new(spec); |
| 899 | if (!knew) |
| 900 | return -ENOMEM; |
| 901 | *knew = alc_automute_mode_enum; |
| 902 | knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL); |
| 903 | if (!knew->name) |
| 904 | return -ENOMEM; |
| 905 | return 0; |
| 906 | } |
| 907 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 908 | /* |
| 909 | * Check the availability of HP/line-out auto-mute; |
| 910 | * Set up appropriately if really supported |
| 911 | */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 912 | static void alc_init_automute(struct hda_codec *codec) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 913 | { |
| 914 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 915 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 1daf5f4 | 2011-04-28 17:57:46 +0200 | [diff] [blame] | 916 | int present = 0; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 917 | int i; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 918 | |
Takashi Iwai | 1daf5f4 | 2011-04-28 17:57:46 +0200 | [diff] [blame] | 919 | if (cfg->hp_pins[0]) |
| 920 | present++; |
| 921 | if (cfg->line_out_pins[0]) |
| 922 | present++; |
| 923 | if (cfg->speaker_pins[0]) |
| 924 | present++; |
| 925 | if (present < 2) /* need two different output types */ |
| 926 | return; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 927 | |
Takashi Iwai | c48a8fb | 2011-07-27 16:41:57 +0200 | [diff] [blame] | 928 | if (!cfg->speaker_pins[0] && |
| 929 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 930 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 931 | sizeof(cfg->speaker_pins)); |
| 932 | cfg->speaker_outs = cfg->line_outs; |
| 933 | } |
| 934 | |
Takashi Iwai | c48a8fb | 2011-07-27 16:41:57 +0200 | [diff] [blame] | 935 | if (!cfg->hp_pins[0] && |
| 936 | cfg->line_out_type == AUTO_PIN_HP_OUT) { |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 937 | memcpy(cfg->hp_pins, cfg->line_out_pins, |
| 938 | sizeof(cfg->hp_pins)); |
| 939 | cfg->hp_outs = cfg->line_outs; |
| 940 | } |
| 941 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 942 | spec->automute_mode = ALC_AUTOMUTE_PIN; |
| 943 | |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 944 | for (i = 0; i < cfg->hp_outs; i++) { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 945 | hda_nid_t nid = cfg->hp_pins[i]; |
Takashi Iwai | 06dec22 | 2011-05-17 10:00:16 +0200 | [diff] [blame] | 946 | if (!is_jack_detectable(codec, nid)) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 947 | continue; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 948 | snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n", |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 949 | nid); |
| 950 | snd_hda_codec_write_cache(codec, nid, 0, |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 951 | AC_VERB_SET_UNSOLICITED_ENABLE, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 952 | AC_USRSP_EN | ALC_HP_EVENT); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 953 | spec->detect_hp = 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 954 | } |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 955 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 956 | if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) { |
| 957 | if (cfg->speaker_outs) |
| 958 | for (i = 0; i < cfg->line_outs; i++) { |
| 959 | hda_nid_t nid = cfg->line_out_pins[i]; |
| 960 | if (!is_jack_detectable(codec, nid)) |
| 961 | continue; |
| 962 | snd_printdd("realtek: Enable Line-Out " |
| 963 | "auto-muting on NID 0x%x\n", nid); |
| 964 | snd_hda_codec_write_cache(codec, nid, 0, |
| 965 | AC_VERB_SET_UNSOLICITED_ENABLE, |
| 966 | AC_USRSP_EN | ALC_FRONT_EVENT); |
| 967 | spec->detect_lo = 1; |
| 968 | } |
| 969 | spec->automute_lo_possible = spec->detect_hp; |
| 970 | } |
| 971 | |
| 972 | spec->automute_speaker_possible = cfg->speaker_outs && |
| 973 | (spec->detect_hp || spec->detect_lo); |
| 974 | |
| 975 | spec->automute_lo = spec->automute_lo_possible; |
| 976 | spec->automute_speaker = spec->automute_speaker_possible; |
| 977 | |
| 978 | if (spec->automute_speaker_possible || spec->automute_lo_possible) { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 979 | /* create a control for automute mode */ |
| 980 | alc_add_automute_mode_enum(codec); |
| 981 | spec->unsol_event = alc_sku_unsol_event; |
| 982 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 983 | } |
| 984 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 985 | /* 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] | 986 | static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 987 | { |
| 988 | int i; |
| 989 | for (i = 0; i < nums; i++) |
| 990 | if (list[i] == nid) |
| 991 | return i; |
| 992 | return -1; |
| 993 | } |
| 994 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 995 | /* check whether dynamic ADC-switching is available */ |
| 996 | static bool alc_check_dyn_adc_switch(struct hda_codec *codec) |
| 997 | { |
| 998 | struct alc_spec *spec = codec->spec; |
| 999 | struct hda_input_mux *imux = &spec->private_imux[0]; |
| 1000 | int i, n, idx; |
| 1001 | hda_nid_t cap, pin; |
| 1002 | |
| 1003 | if (imux != spec->input_mux) /* no dynamic imux? */ |
| 1004 | return false; |
| 1005 | |
| 1006 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 1007 | cap = spec->private_capsrc_nids[n]; |
| 1008 | for (i = 0; i < imux->num_items; i++) { |
| 1009 | pin = spec->imux_pins[i]; |
| 1010 | if (!pin) |
| 1011 | return false; |
| 1012 | if (get_connection_index(codec, cap, pin) < 0) |
| 1013 | break; |
| 1014 | } |
| 1015 | if (i >= imux->num_items) |
Takashi Iwai | 268ff6f | 2011-07-08 14:37:35 +0200 | [diff] [blame] | 1016 | return true; /* no ADC-switch is needed */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | for (i = 0; i < imux->num_items; i++) { |
| 1020 | pin = spec->imux_pins[i]; |
| 1021 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 1022 | cap = spec->private_capsrc_nids[n]; |
| 1023 | idx = get_connection_index(codec, cap, pin); |
| 1024 | if (idx >= 0) { |
| 1025 | imux->items[i].index = idx; |
| 1026 | spec->dyn_adc_idx[i] = n; |
| 1027 | break; |
| 1028 | } |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | snd_printdd("realtek: enabling ADC switching\n"); |
| 1033 | spec->dyn_adc_switch = 1; |
| 1034 | return true; |
| 1035 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1036 | |
| 1037 | /* rebuild imux for matching with the given auto-mic pins (if not yet) */ |
| 1038 | static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec) |
| 1039 | { |
| 1040 | struct alc_spec *spec = codec->spec; |
| 1041 | struct hda_input_mux *imux; |
| 1042 | static char * const texts[3] = { |
| 1043 | "Mic", "Internal Mic", "Dock Mic" |
| 1044 | }; |
| 1045 | int i; |
| 1046 | |
| 1047 | if (!spec->auto_mic) |
| 1048 | return false; |
| 1049 | imux = &spec->private_imux[0]; |
| 1050 | if (spec->input_mux == imux) |
| 1051 | return true; |
| 1052 | spec->imux_pins[0] = spec->ext_mic_pin; |
| 1053 | spec->imux_pins[1] = spec->int_mic_pin; |
| 1054 | spec->imux_pins[2] = spec->dock_mic_pin; |
| 1055 | for (i = 0; i < 3; i++) { |
| 1056 | strcpy(imux->items[i].label, texts[i]); |
| 1057 | if (spec->imux_pins[i]) |
| 1058 | imux->num_items = i + 1; |
| 1059 | } |
| 1060 | spec->num_mux_defs = 1; |
| 1061 | spec->input_mux = imux; |
| 1062 | return true; |
| 1063 | } |
| 1064 | |
| 1065 | /* check whether all auto-mic pins are valid; setup indices if OK */ |
| 1066 | static bool alc_auto_mic_check_imux(struct hda_codec *codec) |
| 1067 | { |
| 1068 | struct alc_spec *spec = codec->spec; |
| 1069 | const struct hda_input_mux *imux; |
| 1070 | |
| 1071 | if (!spec->auto_mic) |
| 1072 | return false; |
| 1073 | if (spec->auto_mic_valid_imux) |
| 1074 | return true; /* already checked */ |
| 1075 | |
| 1076 | /* fill up imux indices */ |
| 1077 | if (!alc_check_dyn_adc_switch(codec)) { |
| 1078 | spec->auto_mic = 0; |
| 1079 | return false; |
| 1080 | } |
| 1081 | |
| 1082 | imux = spec->input_mux; |
| 1083 | spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin, |
| 1084 | spec->imux_pins, imux->num_items); |
| 1085 | spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin, |
| 1086 | spec->imux_pins, imux->num_items); |
| 1087 | spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin, |
| 1088 | spec->imux_pins, imux->num_items); |
| 1089 | if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) { |
| 1090 | spec->auto_mic = 0; |
| 1091 | return false; /* no corresponding imux */ |
| 1092 | } |
| 1093 | |
| 1094 | snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0, |
| 1095 | AC_VERB_SET_UNSOLICITED_ENABLE, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1096 | AC_USRSP_EN | ALC_MIC_EVENT); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1097 | if (spec->dock_mic_pin) |
| 1098 | snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0, |
| 1099 | AC_VERB_SET_UNSOLICITED_ENABLE, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1100 | AC_USRSP_EN | ALC_MIC_EVENT); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1101 | |
| 1102 | spec->auto_mic_valid_imux = 1; |
| 1103 | spec->auto_mic = 1; |
| 1104 | return true; |
| 1105 | } |
| 1106 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1107 | /* |
| 1108 | * Check the availability of auto-mic switch; |
| 1109 | * Set up if really supported |
| 1110 | */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1111 | static void alc_init_auto_mic(struct hda_codec *codec) |
| 1112 | { |
| 1113 | struct alc_spec *spec = codec->spec; |
| 1114 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1115 | hda_nid_t fixed, ext, dock; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1116 | int i; |
| 1117 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1118 | spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1; |
| 1119 | |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1120 | fixed = ext = dock = 0; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 1121 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1122 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1123 | unsigned int defcfg; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1124 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1125 | switch (snd_hda_get_input_pin_attr(defcfg)) { |
| 1126 | case INPUT_PIN_ATTR_INT: |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1127 | if (fixed) |
| 1128 | return; /* already occupied */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1129 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 1130 | return; /* invalid type */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1131 | fixed = nid; |
| 1132 | break; |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1133 | case INPUT_PIN_ATTR_UNUSED: |
| 1134 | return; /* invalid entry */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1135 | case INPUT_PIN_ATTR_DOCK: |
| 1136 | if (dock) |
| 1137 | return; /* already occupied */ |
| 1138 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) |
| 1139 | return; /* invalid type */ |
| 1140 | dock = nid; |
| 1141 | break; |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1142 | default: |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1143 | if (ext) |
| 1144 | return; /* already occupied */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1145 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 1146 | return; /* invalid type */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1147 | ext = nid; |
| 1148 | break; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1149 | } |
| 1150 | } |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1151 | if (!ext && dock) { |
| 1152 | ext = dock; |
| 1153 | dock = 0; |
| 1154 | } |
Takashi Iwai | eaa9b3a | 2010-01-17 13:09:33 +0100 | [diff] [blame] | 1155 | if (!ext || !fixed) |
| 1156 | return; |
Takashi Iwai | e35d9d6 | 2011-05-17 11:28:16 +0200 | [diff] [blame] | 1157 | if (!is_jack_detectable(codec, ext)) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1158 | return; /* no unsol support */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1159 | if (dock && !is_jack_detectable(codec, dock)) |
| 1160 | return; /* no unsol support */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1161 | |
| 1162 | /* check imux indices */ |
| 1163 | spec->ext_mic_pin = ext; |
| 1164 | spec->int_mic_pin = fixed; |
| 1165 | spec->dock_mic_pin = dock; |
| 1166 | |
| 1167 | spec->auto_mic = 1; |
| 1168 | if (!alc_auto_mic_check_imux(codec)) |
| 1169 | return; |
| 1170 | |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1171 | snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n", |
| 1172 | ext, fixed, dock); |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1173 | spec->unsol_event = alc_sku_unsol_event; |
| 1174 | } |
| 1175 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1176 | /* check the availabilities of auto-mute and auto-mic switches */ |
| 1177 | static void alc_auto_check_switches(struct hda_codec *codec) |
| 1178 | { |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 1179 | alc_init_automute(codec); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1180 | alc_init_auto_mic(codec); |
| 1181 | } |
| 1182 | |
| 1183 | /* |
| 1184 | * Realtek SSID verification |
| 1185 | */ |
| 1186 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1187 | /* Could be any non-zero and even value. When used as fixup, tells |
| 1188 | * the driver to ignore any present sku defines. |
| 1189 | */ |
| 1190 | #define ALC_FIXUP_SKU_IGNORE (2) |
| 1191 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1192 | static int alc_auto_parse_customize_define(struct hda_codec *codec) |
| 1193 | { |
| 1194 | unsigned int ass, tmp, i; |
Takashi Iwai | 7fb5622 | 2010-03-22 17:09:47 +0100 | [diff] [blame] | 1195 | unsigned nid = 0; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1196 | struct alc_spec *spec = codec->spec; |
| 1197 | |
Takashi Iwai | b6cbe51 | 2010-07-28 17:43:36 +0200 | [diff] [blame] | 1198 | spec->cdefine.enable_pcbeep = 1; /* assume always enabled */ |
| 1199 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1200 | if (spec->cdefine.fixup) { |
| 1201 | ass = spec->cdefine.sku_cfg; |
| 1202 | if (ass == ALC_FIXUP_SKU_IGNORE) |
| 1203 | return -1; |
| 1204 | goto do_sku; |
| 1205 | } |
| 1206 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1207 | ass = codec->subsystem_id & 0xffff; |
Takashi Iwai | b6cbe51 | 2010-07-28 17:43:36 +0200 | [diff] [blame] | 1208 | if (ass != codec->bus->pci->subsystem_device && (ass & 1)) |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1209 | goto do_sku; |
| 1210 | |
| 1211 | nid = 0x1d; |
| 1212 | if (codec->vendor_id == 0x10ec0260) |
| 1213 | nid = 0x17; |
| 1214 | ass = snd_hda_codec_get_pincfg(codec, nid); |
| 1215 | |
| 1216 | if (!(ass & 1)) { |
| 1217 | printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n", |
| 1218 | codec->chip_name, ass); |
| 1219 | return -1; |
| 1220 | } |
| 1221 | |
| 1222 | /* check sum */ |
| 1223 | tmp = 0; |
| 1224 | for (i = 1; i < 16; i++) { |
| 1225 | if ((ass >> i) & 1) |
| 1226 | tmp++; |
| 1227 | } |
| 1228 | if (((ass >> 16) & 0xf) != tmp) |
| 1229 | return -1; |
| 1230 | |
| 1231 | spec->cdefine.port_connectivity = ass >> 30; |
| 1232 | spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20; |
| 1233 | spec->cdefine.check_sum = (ass >> 16) & 0xf; |
| 1234 | spec->cdefine.customization = ass >> 8; |
| 1235 | do_sku: |
| 1236 | spec->cdefine.sku_cfg = ass; |
| 1237 | spec->cdefine.external_amp = (ass & 0x38) >> 3; |
| 1238 | spec->cdefine.platform_type = (ass & 0x4) >> 2; |
| 1239 | spec->cdefine.swap = (ass & 0x2) >> 1; |
| 1240 | spec->cdefine.override = ass & 0x1; |
| 1241 | |
| 1242 | snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n", |
| 1243 | nid, spec->cdefine.sku_cfg); |
| 1244 | snd_printd("SKU: port_connectivity=0x%x\n", |
| 1245 | spec->cdefine.port_connectivity); |
| 1246 | snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep); |
| 1247 | snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum); |
| 1248 | snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization); |
| 1249 | snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp); |
| 1250 | snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type); |
| 1251 | snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap); |
| 1252 | snd_printd("SKU: override=0x%x\n", spec->cdefine.override); |
| 1253 | |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1257 | /* return true if the given NID is found in the list */ |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1258 | static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 1259 | { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1260 | return find_idx_in_nid_list(nid, list, nums) >= 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1261 | } |
| 1262 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1263 | /* check subsystem ID and set up device-specific initialization; |
| 1264 | * return 1 if initialized, 0 if invalid SSID |
| 1265 | */ |
| 1266 | /* 32-bit subsystem ID for BIOS loading in HD Audio codec. |
| 1267 | * 31 ~ 16 : Manufacture ID |
| 1268 | * 15 ~ 8 : SKU ID |
| 1269 | * 7 ~ 0 : Assembly ID |
| 1270 | * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36 |
| 1271 | */ |
| 1272 | static int alc_subsystem_id(struct hda_codec *codec, |
| 1273 | hda_nid_t porta, hda_nid_t porte, |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1274 | hda_nid_t portd, hda_nid_t porti) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1275 | { |
| 1276 | unsigned int ass, tmp, i; |
| 1277 | unsigned nid; |
| 1278 | struct alc_spec *spec = codec->spec; |
| 1279 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1280 | if (spec->cdefine.fixup) { |
| 1281 | ass = spec->cdefine.sku_cfg; |
| 1282 | if (ass == ALC_FIXUP_SKU_IGNORE) |
| 1283 | return 0; |
| 1284 | goto do_sku; |
| 1285 | } |
| 1286 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1287 | ass = codec->subsystem_id & 0xffff; |
| 1288 | if ((ass != codec->bus->pci->subsystem_device) && (ass & 1)) |
| 1289 | goto do_sku; |
| 1290 | |
| 1291 | /* invalid SSID, check the special NID pin defcfg instead */ |
| 1292 | /* |
Sasha Alexandr | def319f | 2009-06-16 16:00:15 -0400 | [diff] [blame] | 1293 | * 31~30 : port connectivity |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1294 | * 29~21 : reserve |
| 1295 | * 20 : PCBEEP input |
| 1296 | * 19~16 : Check sum (15:1) |
| 1297 | * 15~1 : Custom |
| 1298 | * 0 : override |
| 1299 | */ |
| 1300 | nid = 0x1d; |
| 1301 | if (codec->vendor_id == 0x10ec0260) |
| 1302 | nid = 0x17; |
| 1303 | ass = snd_hda_codec_get_pincfg(codec, nid); |
| 1304 | snd_printd("realtek: No valid SSID, " |
| 1305 | "checking pincfg 0x%08x for NID 0x%x\n", |
Takashi Iwai | cb6605c | 2009-04-28 13:03:19 +0200 | [diff] [blame] | 1306 | ass, nid); |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1307 | if (!(ass & 1)) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1308 | return 0; |
| 1309 | if ((ass >> 30) != 1) /* no physical connection */ |
| 1310 | return 0; |
| 1311 | |
| 1312 | /* check sum */ |
| 1313 | tmp = 0; |
| 1314 | for (i = 1; i < 16; i++) { |
| 1315 | if ((ass >> i) & 1) |
| 1316 | tmp++; |
| 1317 | } |
| 1318 | if (((ass >> 16) & 0xf) != tmp) |
| 1319 | return 0; |
| 1320 | do_sku: |
| 1321 | snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n", |
| 1322 | ass & 0xffff, codec->vendor_id); |
| 1323 | /* |
| 1324 | * 0 : override |
| 1325 | * 1 : Swap Jack |
| 1326 | * 2 : 0 --> Desktop, 1 --> Laptop |
| 1327 | * 3~5 : External Amplifier control |
| 1328 | * 7~6 : Reserved |
| 1329 | */ |
| 1330 | tmp = (ass & 0x38) >> 3; /* external Amp control */ |
| 1331 | switch (tmp) { |
| 1332 | case 1: |
| 1333 | spec->init_amp = ALC_INIT_GPIO1; |
| 1334 | break; |
| 1335 | case 3: |
| 1336 | spec->init_amp = ALC_INIT_GPIO2; |
| 1337 | break; |
| 1338 | case 7: |
| 1339 | spec->init_amp = ALC_INIT_GPIO3; |
| 1340 | break; |
| 1341 | case 5: |
Takashi Iwai | 5a8cfb4 | 2010-11-26 17:11:18 +0100 | [diff] [blame] | 1342 | default: |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1343 | spec->init_amp = ALC_INIT_DEFAULT; |
| 1344 | break; |
| 1345 | } |
| 1346 | |
| 1347 | /* is laptop or Desktop and enable the function "Mute internal speaker |
| 1348 | * when the external headphone out jack is plugged" |
| 1349 | */ |
| 1350 | if (!(ass & 0x8000)) |
| 1351 | return 1; |
| 1352 | /* |
| 1353 | * 10~8 : Jack location |
| 1354 | * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered |
| 1355 | * 14~13: Resvered |
| 1356 | * 15 : 1 --> enable the function "Mute internal speaker |
| 1357 | * when the external headphone out jack is plugged" |
| 1358 | */ |
Takashi Iwai | 5fe6e01 | 2011-09-26 10:41:21 +0200 | [diff] [blame] | 1359 | if (!spec->autocfg.hp_pins[0] && |
| 1360 | !(spec->autocfg.line_out_pins[0] && |
| 1361 | spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) { |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1362 | hda_nid_t nid; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1363 | tmp = (ass >> 11) & 0x3; /* HP to chassis */ |
| 1364 | if (tmp == 0) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1365 | nid = porta; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1366 | else if (tmp == 1) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1367 | nid = porte; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1368 | else if (tmp == 2) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1369 | nid = portd; |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1370 | else if (tmp == 3) |
| 1371 | nid = porti; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1372 | else |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1373 | return 1; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1374 | if (found_in_nid_list(nid, spec->autocfg.line_out_pins, |
| 1375 | spec->autocfg.line_outs)) |
| 1376 | return 1; |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1377 | spec->autocfg.hp_pins[0] = nid; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1378 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1379 | return 1; |
| 1380 | } |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 1381 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 1382 | /* Check the validity of ALC subsystem-id |
| 1383 | * ports contains an array of 4 pin NIDs for port-A, E, D and I */ |
| 1384 | 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] | 1385 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 1386 | 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] | 1387 | struct alc_spec *spec = codec->spec; |
| 1388 | snd_printd("realtek: " |
| 1389 | "Enable default setup for auto mode as fallback\n"); |
| 1390 | spec->init_amp = ALC_INIT_DEFAULT; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1391 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1392 | } |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 1393 | |
Takashi Iwai | 41e41f1 | 2005-06-08 14:48:49 +0200 | [diff] [blame] | 1394 | /* |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1395 | * Fix-up pin default configurations and add default verbs |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1396 | */ |
| 1397 | |
| 1398 | struct alc_pincfg { |
| 1399 | hda_nid_t nid; |
| 1400 | u32 val; |
| 1401 | }; |
| 1402 | |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1403 | struct alc_model_fixup { |
| 1404 | const int id; |
| 1405 | const char *name; |
| 1406 | }; |
| 1407 | |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1408 | struct alc_fixup { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1409 | int type; |
Takashi Iwai | 361fe6e | 2011-01-14 09:55:32 +0100 | [diff] [blame] | 1410 | bool chained; |
| 1411 | int chain_id; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1412 | union { |
| 1413 | unsigned int sku; |
| 1414 | const struct alc_pincfg *pins; |
| 1415 | const struct hda_verb *verbs; |
| 1416 | void (*func)(struct hda_codec *codec, |
| 1417 | const struct alc_fixup *fix, |
| 1418 | int action); |
| 1419 | } v; |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1420 | }; |
| 1421 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1422 | enum { |
| 1423 | ALC_FIXUP_INVALID, |
| 1424 | ALC_FIXUP_SKU, |
| 1425 | ALC_FIXUP_PINS, |
| 1426 | ALC_FIXUP_VERBS, |
| 1427 | ALC_FIXUP_FUNC, |
| 1428 | }; |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1429 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1430 | enum { |
| 1431 | ALC_FIXUP_ACT_PRE_PROBE, |
| 1432 | ALC_FIXUP_ACT_PROBE, |
Takashi Iwai | 5870112 | 2011-01-13 15:41:45 +0100 | [diff] [blame] | 1433 | ALC_FIXUP_ACT_INIT, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1434 | }; |
| 1435 | |
| 1436 | static void alc_apply_fixup(struct hda_codec *codec, int action) |
| 1437 | { |
| 1438 | struct alc_spec *spec = codec->spec; |
| 1439 | int id = spec->fixup_id; |
Takashi Iwai | aa1d0c5 | 2011-01-19 17:27:58 +0100 | [diff] [blame] | 1440 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1441 | const char *modelname = spec->fixup_name; |
Takashi Iwai | aa1d0c5 | 2011-01-19 17:27:58 +0100 | [diff] [blame] | 1442 | #endif |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1443 | int depth = 0; |
| 1444 | |
| 1445 | if (!spec->fixup_list) |
| 1446 | return; |
| 1447 | |
| 1448 | while (id >= 0) { |
| 1449 | const struct alc_fixup *fix = spec->fixup_list + id; |
| 1450 | const struct alc_pincfg *cfg; |
| 1451 | |
| 1452 | switch (fix->type) { |
| 1453 | case ALC_FIXUP_SKU: |
| 1454 | if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku) |
| 1455 | break;; |
| 1456 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1457 | "Apply sku override for %s\n", |
| 1458 | codec->chip_name, modelname); |
| 1459 | spec->cdefine.sku_cfg = fix->v.sku; |
| 1460 | spec->cdefine.fixup = 1; |
| 1461 | break; |
| 1462 | case ALC_FIXUP_PINS: |
| 1463 | cfg = fix->v.pins; |
| 1464 | if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg) |
| 1465 | break; |
| 1466 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1467 | "Apply pincfg for %s\n", |
| 1468 | codec->chip_name, modelname); |
| 1469 | for (; cfg->nid; cfg++) |
| 1470 | snd_hda_codec_set_pincfg(codec, cfg->nid, |
| 1471 | cfg->val); |
| 1472 | break; |
| 1473 | case ALC_FIXUP_VERBS: |
| 1474 | if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs) |
| 1475 | break; |
| 1476 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1477 | "Apply fix-verbs for %s\n", |
| 1478 | codec->chip_name, modelname); |
| 1479 | add_verb(codec->spec, fix->v.verbs); |
| 1480 | break; |
| 1481 | case ALC_FIXUP_FUNC: |
| 1482 | if (!fix->v.func) |
| 1483 | break; |
| 1484 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1485 | "Apply fix-func for %s\n", |
| 1486 | codec->chip_name, modelname); |
| 1487 | fix->v.func(codec, fix, action); |
| 1488 | break; |
| 1489 | default: |
| 1490 | snd_printk(KERN_ERR "hda_codec: %s: " |
| 1491 | "Invalid fixup type %d\n", |
| 1492 | codec->chip_name, fix->type); |
| 1493 | break; |
| 1494 | } |
Takashi Iwai | 24af2b1 | 2011-05-02 13:55:36 +0200 | [diff] [blame] | 1495 | if (!fix->chained) |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1496 | break; |
| 1497 | if (++depth > 10) |
| 1498 | break; |
Takashi Iwai | 24af2b1 | 2011-05-02 13:55:36 +0200 | [diff] [blame] | 1499 | id = fix->chain_id; |
Takashi Iwai | 9d57883 | 2010-11-22 13:29:19 +0100 | [diff] [blame] | 1500 | } |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1501 | } |
| 1502 | |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1503 | static void alc_pick_fixup(struct hda_codec *codec, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1504 | const struct alc_model_fixup *models, |
| 1505 | const struct snd_pci_quirk *quirk, |
| 1506 | const struct alc_fixup *fixlist) |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1507 | { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1508 | struct alc_spec *spec = codec->spec; |
| 1509 | int id = -1; |
| 1510 | const char *name = NULL; |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1511 | |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1512 | if (codec->modelname && models) { |
| 1513 | while (models->name) { |
| 1514 | if (!strcmp(codec->modelname, models->name)) { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1515 | id = models->id; |
| 1516 | name = models->name; |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1517 | break; |
| 1518 | } |
| 1519 | models++; |
| 1520 | } |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1521 | } |
| 1522 | if (id < 0) { |
| 1523 | quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk); |
| 1524 | if (quirk) { |
| 1525 | id = quirk->value; |
| 1526 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
| 1527 | name = quirk->name; |
| 1528 | #endif |
| 1529 | } |
| 1530 | } |
| 1531 | |
| 1532 | spec->fixup_id = id; |
| 1533 | if (id >= 0) { |
| 1534 | spec->fixup_list = fixlist; |
| 1535 | spec->fixup_name = name; |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1536 | } |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1537 | } |
| 1538 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1539 | /* |
| 1540 | * COEF access helper functions |
| 1541 | */ |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 1542 | static int alc_read_coef_idx(struct hda_codec *codec, |
| 1543 | unsigned int coef_idx) |
| 1544 | { |
| 1545 | unsigned int val; |
| 1546 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, |
| 1547 | coef_idx); |
| 1548 | val = snd_hda_codec_read(codec, 0x20, 0, |
| 1549 | AC_VERB_GET_PROC_COEF, 0); |
| 1550 | return val; |
| 1551 | } |
| 1552 | |
Kailang Yang | 977ddd6 | 2010-09-15 10:02:29 +0200 | [diff] [blame] | 1553 | static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx, |
| 1554 | unsigned int coef_val) |
| 1555 | { |
| 1556 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, |
| 1557 | coef_idx); |
| 1558 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, |
| 1559 | coef_val); |
| 1560 | } |
| 1561 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 1562 | /* a special bypass for COEF 0; read the cached value at the second time */ |
| 1563 | static unsigned int alc_get_coef0(struct hda_codec *codec) |
| 1564 | { |
| 1565 | struct alc_spec *spec = codec->spec; |
| 1566 | if (!spec->coef0) |
| 1567 | spec->coef0 = alc_read_coef_idx(codec, 0); |
| 1568 | return spec->coef0; |
| 1569 | } |
| 1570 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1571 | /* |
| 1572 | * Digital I/O handling |
| 1573 | */ |
| 1574 | |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1575 | /* set right pin controls for digital I/O */ |
| 1576 | static void alc_auto_init_digital(struct hda_codec *codec) |
| 1577 | { |
| 1578 | struct alc_spec *spec = codec->spec; |
| 1579 | int i; |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 1580 | hda_nid_t pin, dac; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1581 | |
| 1582 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
| 1583 | pin = spec->autocfg.dig_out_pins[i]; |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 1584 | if (!pin) |
| 1585 | continue; |
| 1586 | snd_hda_codec_write(codec, pin, 0, |
| 1587 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); |
| 1588 | if (!i) |
| 1589 | dac = spec->multiout.dig_out_nid; |
| 1590 | else |
| 1591 | dac = spec->slave_dig_outs[i - 1]; |
| 1592 | if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP)) |
| 1593 | continue; |
| 1594 | snd_hda_codec_write(codec, dac, 0, |
| 1595 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 1596 | AMP_OUT_UNMUTE); |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1597 | } |
| 1598 | pin = spec->autocfg.dig_in_pin; |
| 1599 | if (pin) |
| 1600 | snd_hda_codec_write(codec, pin, 0, |
| 1601 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1602 | PIN_IN); |
| 1603 | } |
| 1604 | |
| 1605 | /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */ |
| 1606 | static void alc_auto_parse_digital(struct hda_codec *codec) |
| 1607 | { |
| 1608 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1609 | int i, err, nums; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1610 | hda_nid_t dig_nid; |
| 1611 | |
| 1612 | /* support multiple SPDIFs; the secondary is set up as a slave */ |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1613 | nums = 0; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1614 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1615 | hda_nid_t conn[4]; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1616 | err = snd_hda_get_connections(codec, |
| 1617 | spec->autocfg.dig_out_pins[i], |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1618 | conn, ARRAY_SIZE(conn)); |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1619 | if (err <= 0) |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1620 | continue; |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1621 | dig_nid = conn[0]; /* assume the first element is audio-out */ |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1622 | if (!nums) { |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1623 | spec->multiout.dig_out_nid = dig_nid; |
| 1624 | spec->dig_out_type = spec->autocfg.dig_out_type[0]; |
| 1625 | } else { |
| 1626 | spec->multiout.slave_dig_outs = spec->slave_dig_outs; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1627 | if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1) |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1628 | break; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1629 | spec->slave_dig_outs[nums - 1] = dig_nid; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1630 | } |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1631 | nums++; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | if (spec->autocfg.dig_in_pin) { |
Takashi Iwai | 01fdf18 | 2010-09-24 09:09:42 +0200 | [diff] [blame] | 1635 | dig_nid = codec->start_nid; |
| 1636 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { |
| 1637 | unsigned int wcaps = get_wcaps(codec, dig_nid); |
| 1638 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
| 1639 | continue; |
| 1640 | if (!(wcaps & AC_WCAP_DIGITAL)) |
| 1641 | continue; |
| 1642 | if (!(wcaps & AC_WCAP_CONN_LIST)) |
| 1643 | continue; |
| 1644 | err = get_connection_index(codec, dig_nid, |
| 1645 | spec->autocfg.dig_in_pin); |
| 1646 | if (err >= 0) { |
| 1647 | spec->dig_in_nid = dig_nid; |
| 1648 | break; |
| 1649 | } |
| 1650 | } |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1651 | } |
| 1652 | } |
| 1653 | |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1654 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1655 | * capture mixer elements |
Vincent Petry | ef8ef5f | 2008-11-23 11:31:41 +0800 | [diff] [blame] | 1656 | */ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1657 | static int alc_cap_vol_info(struct snd_kcontrol *kcontrol, |
| 1658 | struct snd_ctl_elem_info *uinfo) |
| 1659 | { |
| 1660 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1661 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1662 | unsigned long val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1663 | int err; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1664 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1665 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1666 | if (spec->vol_in_capsrc) |
| 1667 | val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT); |
| 1668 | else |
| 1669 | val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT); |
| 1670 | kcontrol->private_value = val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1671 | err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo); |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1672 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1673 | return err; |
| 1674 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1676 | static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, |
| 1677 | unsigned int size, unsigned int __user *tlv) |
| 1678 | { |
| 1679 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1680 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1681 | unsigned long val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1682 | int err; |
| 1683 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1684 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1685 | if (spec->vol_in_capsrc) |
| 1686 | val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT); |
| 1687 | else |
| 1688 | val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT); |
| 1689 | kcontrol->private_value = val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1690 | err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv); |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1691 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1692 | return err; |
| 1693 | } |
| 1694 | |
| 1695 | typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol, |
| 1696 | struct snd_ctl_elem_value *ucontrol); |
| 1697 | |
| 1698 | static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol, |
| 1699 | struct snd_ctl_elem_value *ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1700 | getput_call_t func, bool check_adc_switch) |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1701 | { |
| 1702 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1703 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1704 | int i, err = 0; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1705 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1706 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1707 | if (check_adc_switch && spec->dyn_adc_switch) { |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1708 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 1709 | kcontrol->private_value = |
| 1710 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], |
| 1711 | 3, 0, HDA_INPUT); |
| 1712 | err = func(kcontrol, ucontrol); |
| 1713 | if (err < 0) |
| 1714 | goto error; |
| 1715 | } |
| 1716 | } else { |
| 1717 | i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1718 | if (spec->vol_in_capsrc) |
| 1719 | kcontrol->private_value = |
| 1720 | HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i], |
| 1721 | 3, 0, HDA_OUTPUT); |
| 1722 | else |
| 1723 | kcontrol->private_value = |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1724 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], |
| 1725 | 3, 0, HDA_INPUT); |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1726 | err = func(kcontrol, ucontrol); |
| 1727 | } |
| 1728 | error: |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1729 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1730 | return err; |
| 1731 | } |
| 1732 | |
| 1733 | static int alc_cap_vol_get(struct snd_kcontrol *kcontrol, |
| 1734 | struct snd_ctl_elem_value *ucontrol) |
| 1735 | { |
| 1736 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1737 | snd_hda_mixer_amp_volume_get, false); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | static int alc_cap_vol_put(struct snd_kcontrol *kcontrol, |
| 1741 | struct snd_ctl_elem_value *ucontrol) |
| 1742 | { |
| 1743 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1744 | snd_hda_mixer_amp_volume_put, true); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | /* capture mixer elements */ |
| 1748 | #define alc_cap_sw_info snd_ctl_boolean_stereo_info |
| 1749 | |
| 1750 | static int alc_cap_sw_get(struct snd_kcontrol *kcontrol, |
| 1751 | struct snd_ctl_elem_value *ucontrol) |
| 1752 | { |
| 1753 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1754 | snd_hda_mixer_amp_switch_get, false); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | static int alc_cap_sw_put(struct snd_kcontrol *kcontrol, |
| 1758 | struct snd_ctl_elem_value *ucontrol) |
| 1759 | { |
| 1760 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1761 | snd_hda_mixer_amp_switch_put, true); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1762 | } |
| 1763 | |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1764 | #define _DEFINE_CAPMIX(num) \ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1765 | { \ |
| 1766 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1767 | .name = "Capture Switch", \ |
| 1768 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \ |
| 1769 | .count = num, \ |
| 1770 | .info = alc_cap_sw_info, \ |
| 1771 | .get = alc_cap_sw_get, \ |
| 1772 | .put = alc_cap_sw_put, \ |
| 1773 | }, \ |
| 1774 | { \ |
| 1775 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1776 | .name = "Capture Volume", \ |
| 1777 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \ |
| 1778 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ |
| 1779 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \ |
| 1780 | .count = num, \ |
| 1781 | .info = alc_cap_vol_info, \ |
| 1782 | .get = alc_cap_vol_get, \ |
| 1783 | .put = alc_cap_vol_put, \ |
| 1784 | .tlv = { .c = alc_cap_vol_tlv }, \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | #define _DEFINE_CAPSRC(num) \ |
Takashi Iwai | 3c3e989 | 2008-10-31 17:48:56 +0100 | [diff] [blame] | 1788 | { \ |
| 1789 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1790 | /* .name = "Capture Source", */ \ |
| 1791 | .name = "Input Source", \ |
| 1792 | .count = num, \ |
| 1793 | .info = alc_mux_enum_info, \ |
| 1794 | .get = alc_mux_enum_get, \ |
| 1795 | .put = alc_mux_enum_put, \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | #define DEFINE_CAPMIX(num) \ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1799 | static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1800 | _DEFINE_CAPMIX(num), \ |
| 1801 | _DEFINE_CAPSRC(num), \ |
| 1802 | { } /* end */ \ |
| 1803 | } |
| 1804 | |
| 1805 | #define DEFINE_CAPMIX_NOSRC(num) \ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1806 | static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1807 | _DEFINE_CAPMIX(num), \ |
| 1808 | { } /* end */ \ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | /* up to three ADCs */ |
| 1812 | DEFINE_CAPMIX(1); |
| 1813 | DEFINE_CAPMIX(2); |
| 1814 | DEFINE_CAPMIX(3); |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1815 | DEFINE_CAPMIX_NOSRC(1); |
| 1816 | DEFINE_CAPMIX_NOSRC(2); |
| 1817 | DEFINE_CAPMIX_NOSRC(3); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1818 | |
| 1819 | /* |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1820 | * virtual master controls |
| 1821 | */ |
| 1822 | |
| 1823 | /* |
| 1824 | * slave controls for virtual master |
| 1825 | */ |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1826 | static const char * const alc_slave_vols[] = { |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1827 | "Front Playback Volume", |
| 1828 | "Surround Playback Volume", |
| 1829 | "Center Playback Volume", |
| 1830 | "LFE Playback Volume", |
| 1831 | "Side Playback Volume", |
| 1832 | "Headphone Playback Volume", |
| 1833 | "Speaker Playback Volume", |
| 1834 | "Mono Playback Volume", |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1835 | "Line-Out Playback Volume", |
Takashi Iwai | 3fe45ae | 2011-08-18 15:13:17 +0200 | [diff] [blame] | 1836 | "PCM Playback Volume", |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1837 | NULL, |
| 1838 | }; |
| 1839 | |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1840 | static const char * const alc_slave_sws[] = { |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1841 | "Front Playback Switch", |
| 1842 | "Surround Playback Switch", |
| 1843 | "Center Playback Switch", |
| 1844 | "LFE Playback Switch", |
| 1845 | "Side Playback Switch", |
| 1846 | "Headphone Playback Switch", |
| 1847 | "Speaker Playback Switch", |
| 1848 | "Mono Playback Switch", |
Takashi Iwai | edb54a5 | 2008-01-29 12:47:02 +0100 | [diff] [blame] | 1849 | "IEC958 Playback Switch", |
Takashi Iwai | 23033b2 | 2009-12-08 12:36:52 +0100 | [diff] [blame] | 1850 | "Line-Out Playback Switch", |
Takashi Iwai | 3fe45ae | 2011-08-18 15:13:17 +0200 | [diff] [blame] | 1851 | "PCM Playback Switch", |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1852 | NULL, |
| 1853 | }; |
| 1854 | |
| 1855 | /* |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1856 | * build control elements |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | */ |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1858 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1859 | #define NID_MAPPING (-1) |
| 1860 | |
| 1861 | #define SUBDEV_SPEAKER_ (0 << 6) |
| 1862 | #define SUBDEV_HP_ (1 << 6) |
| 1863 | #define SUBDEV_LINE_ (2 << 6) |
| 1864 | #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f)) |
| 1865 | #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f)) |
| 1866 | #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f)) |
| 1867 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1868 | static void alc_free_kctls(struct hda_codec *codec); |
| 1869 | |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1870 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1871 | /* additional beep mixers; the actual parameters are overwritten at build */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1872 | static const struct snd_kcontrol_new alc_beep_mixer[] = { |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1873 | HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT), |
Jaroslav Kysela | 123c07a | 2009-10-21 14:48:23 +0200 | [diff] [blame] | 1874 | HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT), |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1875 | { } /* end */ |
| 1876 | }; |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1877 | #endif |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | static int alc_build_controls(struct hda_codec *codec) |
| 1880 | { |
| 1881 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2f44f84 | 2010-06-22 11:12:32 +0200 | [diff] [blame] | 1882 | struct snd_kcontrol *kctl = NULL; |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1883 | const struct snd_kcontrol_new *knew; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1884 | int i, j, err; |
| 1885 | unsigned int u; |
| 1886 | hda_nid_t nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | |
| 1888 | for (i = 0; i < spec->num_mixers; i++) { |
| 1889 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 1890 | if (err < 0) |
| 1891 | return err; |
| 1892 | } |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1893 | if (spec->cap_mixer) { |
| 1894 | err = snd_hda_add_new_ctls(codec, spec->cap_mixer); |
| 1895 | if (err < 0) |
| 1896 | return err; |
| 1897 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | if (spec->multiout.dig_out_nid) { |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 1899 | err = snd_hda_create_spdif_out_ctls(codec, |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 1900 | spec->multiout.dig_out_nid, |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 1901 | spec->multiout.dig_out_nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | if (err < 0) |
| 1903 | return err; |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1904 | if (!spec->no_analog) { |
| 1905 | err = snd_hda_create_spdif_share_sw(codec, |
| 1906 | &spec->multiout); |
| 1907 | if (err < 0) |
| 1908 | return err; |
| 1909 | spec->multiout.share_spdif = 1; |
| 1910 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | } |
| 1912 | if (spec->dig_in_nid) { |
| 1913 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); |
| 1914 | if (err < 0) |
| 1915 | return err; |
| 1916 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1917 | |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1918 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1919 | /* create beep controls if needed */ |
| 1920 | if (spec->beep_amp) { |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1921 | const struct snd_kcontrol_new *knew; |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1922 | for (knew = alc_beep_mixer; knew->name; knew++) { |
| 1923 | struct snd_kcontrol *kctl; |
| 1924 | kctl = snd_ctl_new1(knew, codec); |
| 1925 | if (!kctl) |
| 1926 | return -ENOMEM; |
| 1927 | kctl->private_value = spec->beep_amp; |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 1928 | err = snd_hda_ctl_add(codec, 0, kctl); |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1929 | if (err < 0) |
| 1930 | return err; |
| 1931 | } |
| 1932 | } |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1933 | #endif |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1934 | |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1935 | /* if we have no master control, let's create it */ |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1936 | if (!spec->no_analog && |
| 1937 | !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1938 | unsigned int vmaster_tlv[4]; |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1939 | snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1940 | HDA_OUTPUT, vmaster_tlv); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1941 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1942 | vmaster_tlv, alc_slave_vols); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1943 | if (err < 0) |
| 1944 | return err; |
| 1945 | } |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1946 | if (!spec->no_analog && |
| 1947 | !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1948 | err = snd_hda_add_vmaster(codec, "Master Playback Switch", |
| 1949 | NULL, alc_slave_sws); |
| 1950 | if (err < 0) |
| 1951 | return err; |
| 1952 | } |
| 1953 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1954 | /* assign Capture Source enums to NID */ |
Takashi Iwai | fbe618f | 2010-06-11 11:24:58 +0200 | [diff] [blame] | 1955 | if (spec->capsrc_nids || spec->adc_nids) { |
| 1956 | kctl = snd_hda_find_mixer_ctl(codec, "Capture Source"); |
| 1957 | if (!kctl) |
| 1958 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); |
| 1959 | for (i = 0; kctl && i < kctl->count; i++) { |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1960 | const hda_nid_t *nids = spec->capsrc_nids; |
Takashi Iwai | fbe618f | 2010-06-11 11:24:58 +0200 | [diff] [blame] | 1961 | if (!nids) |
| 1962 | nids = spec->adc_nids; |
| 1963 | err = snd_hda_add_nid(codec, kctl, i, nids[i]); |
| 1964 | if (err < 0) |
| 1965 | return err; |
| 1966 | } |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1967 | } |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 1968 | if (spec->cap_mixer && spec->adc_nids) { |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1969 | const char *kname = kctl ? kctl->id.name : NULL; |
| 1970 | for (knew = spec->cap_mixer; knew->name; knew++) { |
| 1971 | if (kname && strcmp(knew->name, kname) == 0) |
| 1972 | continue; |
| 1973 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 1974 | for (i = 0; kctl && i < kctl->count; i++) { |
| 1975 | err = snd_hda_add_nid(codec, kctl, i, |
| 1976 | spec->adc_nids[i]); |
| 1977 | if (err < 0) |
| 1978 | return err; |
| 1979 | } |
| 1980 | } |
| 1981 | } |
| 1982 | |
| 1983 | /* other nid->control mapping */ |
| 1984 | for (i = 0; i < spec->num_mixers; i++) { |
| 1985 | for (knew = spec->mixers[i]; knew->name; knew++) { |
| 1986 | if (knew->iface != NID_MAPPING) |
| 1987 | continue; |
| 1988 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 1989 | if (kctl == NULL) |
| 1990 | continue; |
| 1991 | u = knew->subdevice; |
| 1992 | for (j = 0; j < 4; j++, u >>= 8) { |
| 1993 | nid = u & 0x3f; |
| 1994 | if (nid == 0) |
| 1995 | continue; |
| 1996 | switch (u & 0xc0) { |
| 1997 | case SUBDEV_SPEAKER_: |
| 1998 | nid = spec->autocfg.speaker_pins[nid]; |
| 1999 | break; |
| 2000 | case SUBDEV_LINE_: |
| 2001 | nid = spec->autocfg.line_out_pins[nid]; |
| 2002 | break; |
| 2003 | case SUBDEV_HP_: |
| 2004 | nid = spec->autocfg.hp_pins[nid]; |
| 2005 | break; |
| 2006 | default: |
| 2007 | continue; |
| 2008 | } |
| 2009 | err = snd_hda_add_nid(codec, kctl, 0, nid); |
| 2010 | if (err < 0) |
| 2011 | return err; |
| 2012 | } |
| 2013 | u = knew->private_value; |
| 2014 | for (j = 0; j < 4; j++, u >>= 8) { |
| 2015 | nid = u & 0xff; |
| 2016 | if (nid == 0) |
| 2017 | continue; |
| 2018 | err = snd_hda_add_nid(codec, kctl, 0, nid); |
| 2019 | if (err < 0) |
| 2020 | return err; |
| 2021 | } |
| 2022 | } |
| 2023 | } |
Takashi Iwai | bae84e7 | 2010-03-22 08:30:20 +0100 | [diff] [blame] | 2024 | |
| 2025 | alc_free_kctls(codec); /* no longer needed */ |
| 2026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | return 0; |
| 2028 | } |
| 2029 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2030 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | /* |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2032 | * Common callbacks |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2033 | */ |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 2034 | |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 2035 | static void alc_init_special_input_src(struct hda_codec *codec); |
| 2036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | static int alc_init(struct hda_codec *codec) |
| 2038 | { |
| 2039 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2040 | unsigned int i; |
| 2041 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 2042 | alc_fix_pll(codec); |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 2043 | alc_auto_init_amp(codec, spec->init_amp); |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 2044 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2045 | for (i = 0; i < spec->num_init_verbs; i++) |
| 2046 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 2047 | alc_init_special_input_src(codec); |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2048 | |
| 2049 | if (spec->init_hook) |
| 2050 | spec->init_hook(codec); |
| 2051 | |
Takashi Iwai | 5870112 | 2011-01-13 15:41:45 +0100 | [diff] [blame] | 2052 | alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT); |
| 2053 | |
Takashi Iwai | 9e5341b | 2010-09-21 09:57:06 +0200 | [diff] [blame] | 2054 | hda_call_check_power_status(codec, 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | return 0; |
| 2056 | } |
| 2057 | |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2058 | static void alc_unsol_event(struct hda_codec *codec, unsigned int res) |
| 2059 | { |
| 2060 | struct alc_spec *spec = codec->spec; |
| 2061 | |
| 2062 | if (spec->unsol_event) |
| 2063 | spec->unsol_event(codec, res); |
| 2064 | } |
| 2065 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2066 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2067 | static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 2068 | { |
| 2069 | struct alc_spec *spec = codec->spec; |
| 2070 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); |
| 2071 | } |
| 2072 | #endif |
| 2073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | /* |
| 2075 | * Analog playback callbacks |
| 2076 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2077 | static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2079 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | { |
| 2081 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 2082 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 2083 | hinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2086 | static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | struct hda_codec *codec, |
| 2088 | unsigned int stream_tag, |
| 2089 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2090 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | { |
| 2092 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 2093 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, |
| 2094 | stream_tag, format, substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2097 | static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2099 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | { |
| 2101 | struct alc_spec *spec = codec->spec; |
| 2102 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
| 2103 | } |
| 2104 | |
| 2105 | /* |
| 2106 | * Digital out |
| 2107 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2108 | static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2110 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | { |
| 2112 | struct alc_spec *spec = codec->spec; |
| 2113 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 2114 | } |
| 2115 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2116 | static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 2117 | struct hda_codec *codec, |
| 2118 | unsigned int stream_tag, |
| 2119 | unsigned int format, |
| 2120 | struct snd_pcm_substream *substream) |
| 2121 | { |
| 2122 | struct alc_spec *spec = codec->spec; |
| 2123 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 2124 | stream_tag, format, substream); |
| 2125 | } |
| 2126 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2127 | static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 9b5f12e | 2009-02-13 11:47:37 +0100 | [diff] [blame] | 2128 | struct hda_codec *codec, |
| 2129 | struct snd_pcm_substream *substream) |
| 2130 | { |
| 2131 | struct alc_spec *spec = codec->spec; |
| 2132 | return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
| 2133 | } |
| 2134 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2135 | static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2137 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | { |
| 2139 | struct alc_spec *spec = codec->spec; |
| 2140 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 2141 | } |
| 2142 | |
| 2143 | /* |
| 2144 | * Analog capture |
| 2145 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2146 | static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | struct hda_codec *codec, |
| 2148 | unsigned int stream_tag, |
| 2149 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2150 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | { |
| 2152 | struct alc_spec *spec = codec->spec; |
| 2153 | |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2154 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | stream_tag, 0, format); |
| 2156 | return 0; |
| 2157 | } |
| 2158 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2159 | static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2161 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | { |
| 2163 | struct alc_spec *spec = codec->spec; |
| 2164 | |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 2165 | snd_hda_codec_cleanup_stream(codec, |
| 2166 | spec->adc_nids[substream->number + 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | return 0; |
| 2168 | } |
| 2169 | |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2170 | /* analog capture with dynamic dual-adc changes */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2171 | static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2172 | struct hda_codec *codec, |
| 2173 | unsigned int stream_tag, |
| 2174 | unsigned int format, |
| 2175 | struct snd_pcm_substream *substream) |
| 2176 | { |
| 2177 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2178 | 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] | 2179 | spec->cur_adc_stream_tag = stream_tag; |
| 2180 | spec->cur_adc_format = format; |
| 2181 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); |
| 2182 | return 0; |
| 2183 | } |
| 2184 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2185 | static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2186 | struct hda_codec *codec, |
| 2187 | struct snd_pcm_substream *substream) |
| 2188 | { |
| 2189 | struct alc_spec *spec = codec->spec; |
| 2190 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
| 2191 | spec->cur_adc = 0; |
| 2192 | return 0; |
| 2193 | } |
| 2194 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2195 | static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = { |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2196 | .substreams = 1, |
| 2197 | .channels_min = 2, |
| 2198 | .channels_max = 2, |
| 2199 | .nid = 0, /* fill later */ |
| 2200 | .ops = { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2201 | .prepare = dyn_adc_capture_pcm_prepare, |
| 2202 | .cleanup = dyn_adc_capture_pcm_cleanup |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2203 | }, |
| 2204 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | |
| 2206 | /* |
| 2207 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2208 | static const struct hda_pcm_stream alc_pcm_analog_playback = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | .substreams = 1, |
| 2210 | .channels_min = 2, |
| 2211 | .channels_max = 8, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2212 | /* NID is set in alc_build_pcms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2214 | .open = alc_playback_pcm_open, |
| 2215 | .prepare = alc_playback_pcm_prepare, |
| 2216 | .cleanup = alc_playback_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | }, |
| 2218 | }; |
| 2219 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2220 | static const struct hda_pcm_stream alc_pcm_analog_capture = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2221 | .substreams = 1, |
| 2222 | .channels_min = 2, |
| 2223 | .channels_max = 2, |
| 2224 | /* NID is set in alc_build_pcms */ |
| 2225 | }; |
| 2226 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2227 | static const struct hda_pcm_stream alc_pcm_analog_alt_playback = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2228 | .substreams = 1, |
| 2229 | .channels_min = 2, |
| 2230 | .channels_max = 2, |
| 2231 | /* NID is set in alc_build_pcms */ |
| 2232 | }; |
| 2233 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2234 | static const struct hda_pcm_stream alc_pcm_analog_alt_capture = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2235 | .substreams = 2, /* can be overridden */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | .channels_min = 2, |
| 2237 | .channels_max = 2, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2238 | /* NID is set in alc_build_pcms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2240 | .prepare = alc_alt_capture_pcm_prepare, |
| 2241 | .cleanup = alc_alt_capture_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | }, |
| 2243 | }; |
| 2244 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2245 | static const struct hda_pcm_stream alc_pcm_digital_playback = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | .substreams = 1, |
| 2247 | .channels_min = 2, |
| 2248 | .channels_max = 2, |
| 2249 | /* NID is set in alc_build_pcms */ |
| 2250 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2251 | .open = alc_dig_playback_pcm_open, |
| 2252 | .close = alc_dig_playback_pcm_close, |
| 2253 | .prepare = alc_dig_playback_pcm_prepare, |
| 2254 | .cleanup = alc_dig_playback_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | }, |
| 2256 | }; |
| 2257 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2258 | static const struct hda_pcm_stream alc_pcm_digital_capture = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | .substreams = 1, |
| 2260 | .channels_min = 2, |
| 2261 | .channels_max = 2, |
| 2262 | /* NID is set in alc_build_pcms */ |
| 2263 | }; |
| 2264 | |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 2265 | /* 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] | 2266 | static const struct hda_pcm_stream alc_pcm_null_stream = { |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 2267 | .substreams = 0, |
| 2268 | .channels_min = 0, |
| 2269 | .channels_max = 0, |
| 2270 | }; |
| 2271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | static int alc_build_pcms(struct hda_codec *codec) |
| 2273 | { |
| 2274 | struct alc_spec *spec = codec->spec; |
| 2275 | struct hda_pcm *info = spec->pcm_rec; |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2276 | const struct hda_pcm_stream *p; |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2277 | bool have_multi_adcs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | int i; |
| 2279 | |
| 2280 | codec->num_pcms = 1; |
| 2281 | codec->pcm_info = info; |
| 2282 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2283 | if (spec->no_analog) |
| 2284 | goto skip_analog; |
| 2285 | |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 2286 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), |
| 2287 | "%s Analog", codec->chip_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | info->name = spec->stream_name_analog; |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 2289 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2290 | if (spec->multiout.dac_nids > 0) { |
| 2291 | p = spec->stream_analog_playback; |
| 2292 | if (!p) |
| 2293 | p = &alc_pcm_analog_playback; |
| 2294 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2295 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; |
| 2296 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2297 | if (spec->adc_nids) { |
| 2298 | p = spec->stream_analog_capture; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2299 | if (!p) { |
| 2300 | if (spec->dyn_adc_switch) |
| 2301 | p = &dyn_adc_pcm_analog_capture; |
| 2302 | else |
| 2303 | p = &alc_pcm_analog_capture; |
| 2304 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2305 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2306 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 2307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2309 | if (spec->channel_mode) { |
| 2310 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0; |
| 2311 | for (i = 0; i < spec->num_channel_mode; i++) { |
| 2312 | if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) { |
| 2313 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels; |
| 2314 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | } |
| 2316 | } |
| 2317 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2318 | skip_analog: |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2319 | /* SPDIF for stream index #1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 2321 | snprintf(spec->stream_name_digital, |
| 2322 | sizeof(spec->stream_name_digital), |
| 2323 | "%s Digital", codec->chip_name); |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2324 | codec->num_pcms = 2; |
Wu Fengguang | b25c9da | 2009-02-06 15:02:27 +0800 | [diff] [blame] | 2325 | codec->slave_dig_outs = spec->multiout.slave_dig_outs; |
Takashi Iwai | c06134d | 2006-10-11 18:49:13 +0200 | [diff] [blame] | 2326 | info = spec->pcm_rec + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | info->name = spec->stream_name_digital; |
Takashi Iwai | 8c44198 | 2009-01-20 18:30:20 +0100 | [diff] [blame] | 2328 | if (spec->dig_out_type) |
| 2329 | info->pcm_type = spec->dig_out_type; |
| 2330 | else |
| 2331 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2332 | if (spec->multiout.dig_out_nid) { |
| 2333 | p = spec->stream_digital_playback; |
| 2334 | if (!p) |
| 2335 | p = &alc_pcm_digital_playback; |
| 2336 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; |
| 2338 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2339 | if (spec->dig_in_nid) { |
| 2340 | p = spec->stream_digital_capture; |
| 2341 | if (!p) |
| 2342 | p = &alc_pcm_digital_capture; |
| 2343 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; |
| 2345 | } |
Takashi Iwai | 963f803 | 2008-08-11 10:04:40 +0200 | [diff] [blame] | 2346 | /* FIXME: do we need this for all Realtek codec models? */ |
| 2347 | codec->spdif_status_reset = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2350 | if (spec->no_analog) |
| 2351 | return 0; |
| 2352 | |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2353 | /* If the use of more than one ADC is requested for the current |
| 2354 | * model, configure a second analog capture-only PCM. |
| 2355 | */ |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2356 | have_multi_adcs = (spec->num_adc_nids > 1) && |
| 2357 | !spec->dyn_adc_switch && !spec->auto_mic && |
| 2358 | (!spec->input_mux || spec->input_mux->num_items > 1); |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2359 | /* Additional Analaog capture for index #2 */ |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2360 | if (spec->alt_dac_nid || have_multi_adcs) { |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2361 | codec->num_pcms = 3; |
Takashi Iwai | c06134d | 2006-10-11 18:49:13 +0200 | [diff] [blame] | 2362 | info = spec->pcm_rec + 2; |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2363 | info->name = spec->stream_name_analog; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2364 | if (spec->alt_dac_nid) { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2365 | p = spec->stream_analog_alt_playback; |
| 2366 | if (!p) |
| 2367 | p = &alc_pcm_analog_alt_playback; |
| 2368 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2369 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 2370 | spec->alt_dac_nid; |
| 2371 | } else { |
| 2372 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 2373 | alc_pcm_null_stream; |
| 2374 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0; |
| 2375 | } |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2376 | if (have_multi_adcs) { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2377 | p = spec->stream_analog_alt_capture; |
| 2378 | if (!p) |
| 2379 | p = &alc_pcm_analog_alt_capture; |
| 2380 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2381 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 2382 | spec->adc_nids[1]; |
| 2383 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = |
| 2384 | spec->num_adc_nids - 1; |
| 2385 | } else { |
| 2386 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 2387 | alc_pcm_null_stream; |
| 2388 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0; |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2389 | } |
| 2390 | } |
| 2391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | return 0; |
| 2393 | } |
| 2394 | |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2395 | static inline void alc_shutup(struct hda_codec *codec) |
| 2396 | { |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 2397 | struct alc_spec *spec = codec->spec; |
| 2398 | |
| 2399 | if (spec && spec->shutup) |
| 2400 | spec->shutup(codec); |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2401 | snd_hda_shutup_pins(codec); |
| 2402 | } |
| 2403 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2404 | static void alc_free_kctls(struct hda_codec *codec) |
| 2405 | { |
| 2406 | struct alc_spec *spec = codec->spec; |
| 2407 | |
| 2408 | if (spec->kctls.list) { |
| 2409 | struct snd_kcontrol_new *kctl = spec->kctls.list; |
| 2410 | int i; |
| 2411 | for (i = 0; i < spec->kctls.used; i++) |
| 2412 | kfree(kctl[i].name); |
| 2413 | } |
| 2414 | snd_array_free(&spec->kctls); |
| 2415 | } |
| 2416 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2417 | static void alc_free_bind_ctls(struct hda_codec *codec) |
| 2418 | { |
| 2419 | struct alc_spec *spec = codec->spec; |
| 2420 | if (spec->bind_ctls.list) { |
| 2421 | struct hda_bind_ctls **ctl = spec->bind_ctls.list; |
| 2422 | int i; |
| 2423 | for (i = 0; i < spec->bind_ctls.used; i++) |
| 2424 | kfree(ctl[i]); |
| 2425 | } |
| 2426 | snd_array_free(&spec->bind_ctls); |
| 2427 | } |
| 2428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | static void alc_free(struct hda_codec *codec) |
| 2430 | { |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2431 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2432 | |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2433 | if (!spec) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2434 | return; |
| 2435 | |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2436 | alc_shutup(codec); |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 2437 | snd_hda_input_jack_free(codec); |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2438 | alc_free_kctls(codec); |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2439 | alc_free_bind_ctls(codec); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2440 | kfree(spec); |
Kusanagi Kouichi | 680cd53 | 2009-02-05 00:00:58 +0900 | [diff] [blame] | 2441 | snd_hda_detach_beep_device(codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | } |
| 2443 | |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2444 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2445 | static void alc_power_eapd(struct hda_codec *codec) |
| 2446 | { |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 2447 | alc_auto_setup_eapd(codec, false); |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2448 | } |
| 2449 | |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2450 | static int alc_suspend(struct hda_codec *codec, pm_message_t state) |
| 2451 | { |
| 2452 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2453 | alc_shutup(codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2454 | if (spec && spec->power_hook) |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2455 | spec->power_hook(codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2456 | return 0; |
| 2457 | } |
| 2458 | #endif |
| 2459 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 2460 | #ifdef CONFIG_PM |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2461 | static int alc_resume(struct hda_codec *codec) |
| 2462 | { |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 2463 | msleep(150); /* to avoid pop noise */ |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2464 | codec->patch_ops.init(codec); |
| 2465 | snd_hda_codec_resume_amp(codec); |
| 2466 | snd_hda_codec_resume_cache(codec); |
Takashi Iwai | 9e5341b | 2010-09-21 09:57:06 +0200 | [diff] [blame] | 2467 | hda_call_check_power_status(codec, 0x01); |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2468 | return 0; |
| 2469 | } |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2470 | #endif |
| 2471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | /* |
| 2473 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 2474 | static const struct hda_codec_ops alc_patch_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | .build_controls = alc_build_controls, |
| 2476 | .build_pcms = alc_build_pcms, |
| 2477 | .init = alc_init, |
| 2478 | .free = alc_free, |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2479 | .unsol_event = alc_unsol_event, |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 2480 | #ifdef CONFIG_PM |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2481 | .resume = alc_resume, |
| 2482 | #endif |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2483 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2484 | .suspend = alc_suspend, |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2485 | .check_power_status = alc_check_power_status, |
| 2486 | #endif |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2487 | .reboot_notify = alc_shutup, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | }; |
| 2489 | |
Kailang Yang | c027ddc | 2010-03-19 11:33:06 +0100 | [diff] [blame] | 2490 | /* replace the codec chip_name with the given string */ |
| 2491 | static int alc_codec_rename(struct hda_codec *codec, const char *name) |
| 2492 | { |
| 2493 | kfree(codec->chip_name); |
| 2494 | codec->chip_name = kstrdup(name, GFP_KERNEL); |
| 2495 | if (!codec->chip_name) { |
| 2496 | alc_free(codec); |
| 2497 | return -ENOMEM; |
| 2498 | } |
| 2499 | return 0; |
| 2500 | } |
| 2501 | |
Takashi Iwai | 2fa522b | 2005-05-12 14:51:12 +0200 | [diff] [blame] | 2502 | /* |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2503 | * Rename codecs appropriately from COEF value |
| 2504 | */ |
| 2505 | struct alc_codec_rename_table { |
| 2506 | unsigned int vendor_id; |
| 2507 | unsigned short coef_mask; |
| 2508 | unsigned short coef_bits; |
| 2509 | const char *name; |
| 2510 | }; |
| 2511 | |
| 2512 | static struct alc_codec_rename_table rename_tbl[] = { |
| 2513 | { 0x10ec0269, 0xfff0, 0x3010, "ALC277" }, |
| 2514 | { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" }, |
| 2515 | { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" }, |
| 2516 | { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" }, |
| 2517 | { 0x10ec0269, 0xffff, 0xa023, "ALC259" }, |
| 2518 | { 0x10ec0269, 0xffff, 0x6023, "ALC281X" }, |
| 2519 | { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" }, |
| 2520 | { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" }, |
| 2521 | { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" }, |
| 2522 | { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" }, |
| 2523 | { 0x10ec0899, 0x2000, 0x2000, "ALC899" }, |
| 2524 | { 0x10ec0892, 0xffff, 0x8020, "ALC661" }, |
| 2525 | { 0x10ec0892, 0xffff, 0x8011, "ALC661" }, |
| 2526 | { 0x10ec0892, 0xffff, 0x4011, "ALC656" }, |
| 2527 | { } /* terminator */ |
| 2528 | }; |
| 2529 | |
| 2530 | static int alc_codec_rename_from_preset(struct hda_codec *codec) |
| 2531 | { |
| 2532 | const struct alc_codec_rename_table *p; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2533 | |
| 2534 | for (p = rename_tbl; p->vendor_id; p++) { |
| 2535 | if (p->vendor_id != codec->vendor_id) |
| 2536 | continue; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 2537 | if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits) |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2538 | return alc_codec_rename(codec, p->name); |
| 2539 | } |
| 2540 | return 0; |
| 2541 | } |
| 2542 | |
| 2543 | /* |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2544 | * Automatic parse of I/O pins from the BIOS configuration |
| 2545 | */ |
| 2546 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2547 | enum { |
| 2548 | ALC_CTL_WIDGET_VOL, |
| 2549 | ALC_CTL_WIDGET_MUTE, |
| 2550 | ALC_CTL_BIND_MUTE, |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2551 | ALC_CTL_BIND_VOL, |
| 2552 | ALC_CTL_BIND_SW, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2553 | }; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2554 | static const struct snd_kcontrol_new alc_control_templates[] = { |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2555 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
| 2556 | HDA_CODEC_MUTE(NULL, 0, 0, 0), |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2557 | HDA_BIND_MUTE(NULL, 0, 0, 0), |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2558 | HDA_BIND_VOL(NULL, 0), |
| 2559 | HDA_BIND_SW(NULL, 0), |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2560 | }; |
| 2561 | |
| 2562 | /* add dynamic controls */ |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2563 | 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] | 2564 | int cidx, unsigned long val) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2565 | { |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2566 | struct snd_kcontrol_new *knew; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2567 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2568 | knew = alc_kcontrol_new(spec); |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2569 | if (!knew) |
| 2570 | return -ENOMEM; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2571 | *knew = alc_control_templates[type]; |
Paulo Marques | 543537b | 2005-06-23 00:09:02 -0700 | [diff] [blame] | 2572 | knew->name = kstrdup(name, GFP_KERNEL); |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2573 | if (!knew->name) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2574 | return -ENOMEM; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2575 | knew->index = cidx; |
Jaroslav Kysela | 4d02d1b | 2009-11-12 10:15:48 +0100 | [diff] [blame] | 2576 | if (get_amp_nid_(val)) |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 2577 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2578 | knew->private_value = val; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2579 | return 0; |
| 2580 | } |
| 2581 | |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2582 | static int add_control_with_pfx(struct alc_spec *spec, int type, |
| 2583 | const char *pfx, const char *dir, |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2584 | const char *sfx, int cidx, unsigned long val) |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2585 | { |
| 2586 | char name[32]; |
| 2587 | snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx); |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2588 | return add_control(spec, type, name, cidx, val); |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2589 | } |
| 2590 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2591 | #define add_pb_vol_ctrl(spec, type, pfx, val) \ |
| 2592 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val) |
| 2593 | #define add_pb_sw_ctrl(spec, type, pfx, val) \ |
| 2594 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val) |
| 2595 | #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \ |
| 2596 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val) |
| 2597 | #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \ |
| 2598 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val) |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2599 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2600 | static const char * const channel_name[4] = { |
| 2601 | "Front", "Surround", "CLFE", "Side" |
| 2602 | }; |
| 2603 | |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2604 | static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch, |
| 2605 | bool can_be_master, int *index) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2606 | { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2607 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2608 | |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2609 | *index = 0; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2610 | if (cfg->line_outs == 1 && !spec->multi_ios && |
| 2611 | !cfg->hp_outs && !cfg->speaker_outs && can_be_master) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2612 | return "Master"; |
| 2613 | |
| 2614 | switch (cfg->line_out_type) { |
| 2615 | case AUTO_PIN_SPEAKER_OUT: |
David Henningsson | ebbeb3d | 2011-03-04 14:08:30 +0100 | [diff] [blame] | 2616 | if (cfg->line_outs == 1) |
| 2617 | return "Speaker"; |
| 2618 | break; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2619 | case AUTO_PIN_HP_OUT: |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2620 | /* for multi-io case, only the primary out */ |
| 2621 | if (ch && spec->multi_ios) |
| 2622 | break; |
| 2623 | *index = ch; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2624 | return "Headphone"; |
| 2625 | default: |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2626 | if (cfg->line_outs == 1 && !spec->multi_ios) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2627 | return "PCM"; |
| 2628 | break; |
| 2629 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2630 | if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name))) |
| 2631 | return "PCM"; |
| 2632 | |
| 2633 | return channel_name[ch]; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2634 | } |
| 2635 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2636 | /* create input playback/capture controls for the given pin */ |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2637 | 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] | 2638 | const char *ctlname, int ctlidx, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 2639 | int idx, hda_nid_t mix_nid) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2640 | { |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 2641 | int err; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2642 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2643 | err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2644 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 2645 | if (err < 0) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2646 | return err; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2647 | err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2648 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 2649 | if (err < 0) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2650 | return err; |
| 2651 | return 0; |
| 2652 | } |
| 2653 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2654 | 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] | 2655 | { |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2656 | unsigned int pincap = snd_hda_query_pin_caps(codec, nid); |
| 2657 | return (pincap & AC_PINCAP_IN) != 0; |
| 2658 | } |
| 2659 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2660 | /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */ |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2661 | static int alc_auto_fill_adc_caps(struct hda_codec *codec) |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2662 | { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2663 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2664 | hda_nid_t nid; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2665 | hda_nid_t *adc_nids = spec->private_adc_nids; |
| 2666 | hda_nid_t *cap_nids = spec->private_capsrc_nids; |
| 2667 | int max_nums = ARRAY_SIZE(spec->private_adc_nids); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2668 | int i, nums = 0; |
| 2669 | |
| 2670 | nid = codec->start_nid; |
| 2671 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 2672 | hda_nid_t src; |
| 2673 | const hda_nid_t *list; |
| 2674 | unsigned int caps = get_wcaps(codec, nid); |
| 2675 | int type = get_wcaps_type(caps); |
| 2676 | |
| 2677 | if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL)) |
| 2678 | continue; |
| 2679 | adc_nids[nums] = nid; |
| 2680 | cap_nids[nums] = nid; |
| 2681 | src = nid; |
| 2682 | for (;;) { |
| 2683 | int n; |
| 2684 | type = get_wcaps_type(get_wcaps(codec, src)); |
| 2685 | if (type == AC_WID_PIN) |
| 2686 | break; |
| 2687 | if (type == AC_WID_AUD_SEL) { |
| 2688 | cap_nids[nums] = src; |
| 2689 | break; |
| 2690 | } |
| 2691 | n = snd_hda_get_conn_list(codec, src, &list); |
| 2692 | if (n > 1) { |
| 2693 | cap_nids[nums] = src; |
| 2694 | break; |
| 2695 | } else if (n != 1) |
| 2696 | break; |
| 2697 | src = *list; |
| 2698 | } |
| 2699 | if (++nums >= max_nums) |
| 2700 | break; |
| 2701 | } |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2702 | spec->adc_nids = spec->private_adc_nids; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2703 | spec->capsrc_nids = spec->private_capsrc_nids; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2704 | spec->num_adc_nids = nums; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2705 | return nums; |
| 2706 | } |
| 2707 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2708 | /* create playback/capture controls for input pins */ |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2709 | static int alc_auto_create_input_ctls(struct hda_codec *codec) |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2710 | { |
| 2711 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2712 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2713 | hda_nid_t mixer = spec->mixer_nid; |
Herton Ronaldo Krzesinski | 61b9b9b | 2009-01-28 09:16:33 -0200 | [diff] [blame] | 2714 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2715 | int num_adcs; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2716 | int i, c, err, idx, type_idx = 0; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2717 | const char *prev_label = NULL; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2718 | |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2719 | num_adcs = alc_auto_fill_adc_caps(codec); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2720 | if (num_adcs < 0) |
| 2721 | return 0; |
| 2722 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2723 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2724 | hda_nid_t pin; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2725 | const char *label; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2726 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2727 | pin = cfg->inputs[i].pin; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2728 | if (!alc_is_input_pin(codec, pin)) |
| 2729 | continue; |
| 2730 | |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2731 | label = hda_get_autocfg_input_label(codec, cfg, i); |
| 2732 | if (prev_label && !strcmp(label, prev_label)) |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2733 | type_idx++; |
| 2734 | else |
| 2735 | type_idx = 0; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2736 | prev_label = label; |
| 2737 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2738 | if (mixer) { |
| 2739 | idx = get_connection_index(codec, mixer, pin); |
| 2740 | if (idx >= 0) { |
| 2741 | err = new_analog_input(spec, pin, |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2742 | label, type_idx, |
| 2743 | idx, mixer); |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2744 | if (err < 0) |
| 2745 | return err; |
| 2746 | } |
| 2747 | } |
| 2748 | |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2749 | for (c = 0; c < num_adcs; c++) { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2750 | hda_nid_t cap = spec->capsrc_nids ? |
| 2751 | spec->capsrc_nids[c] : spec->adc_nids[c]; |
| 2752 | idx = get_connection_index(codec, cap, pin); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2753 | if (idx >= 0) { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2754 | spec->imux_pins[imux->num_items] = pin; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2755 | snd_hda_add_imux_item(imux, label, idx, NULL); |
| 2756 | break; |
| 2757 | } |
| 2758 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2759 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2760 | |
| 2761 | spec->num_mux_defs = 1; |
| 2762 | spec->input_mux = imux; |
| 2763 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2764 | return 0; |
| 2765 | } |
| 2766 | |
Takashi Iwai | f6c7e54 | 2008-02-12 18:32:23 +0100 | [diff] [blame] | 2767 | static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid, |
| 2768 | unsigned int pin_type) |
| 2769 | { |
| 2770 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 2771 | pin_type); |
| 2772 | /* unmute pin */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 2773 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
| 2774 | 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] | 2775 | AMP_OUT_UNMUTE); |
Takashi Iwai | f6c7e54 | 2008-02-12 18:32:23 +0100 | [diff] [blame] | 2776 | } |
| 2777 | |
Takashi Iwai | baba8ee | 2007-04-23 17:17:48 +0200 | [diff] [blame] | 2778 | static int get_pin_type(int line_out_type) |
| 2779 | { |
| 2780 | if (line_out_type == AUTO_PIN_HP_OUT) |
| 2781 | return PIN_HP; |
| 2782 | else |
| 2783 | return PIN_OUT; |
| 2784 | } |
| 2785 | |
Takashi Iwai | 0a7f532 | 2011-07-06 15:15:12 +0200 | [diff] [blame] | 2786 | static void alc_auto_init_analog_input(struct hda_codec *codec) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2787 | { |
| 2788 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2789 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2790 | int i; |
| 2791 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2792 | for (i = 0; i < cfg->num_inputs; i++) { |
| 2793 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2794 | if (alc_is_input_pin(codec, nid)) { |
Takashi Iwai | 30ea098 | 2010-09-16 18:47:56 +0200 | [diff] [blame] | 2795 | alc_set_input_pin(codec, nid, cfg->inputs[i].type); |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 2796 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2797 | snd_hda_codec_write(codec, nid, 0, |
| 2798 | AC_VERB_SET_AMP_GAIN_MUTE, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2799 | AMP_OUT_MUTE); |
| 2800 | } |
| 2801 | } |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 2802 | |
| 2803 | /* mute all loopback inputs */ |
| 2804 | if (spec->mixer_nid) { |
| 2805 | int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL); |
| 2806 | for (i = 0; i < nums; i++) |
| 2807 | snd_hda_codec_write(codec, spec->mixer_nid, 0, |
| 2808 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 2809 | AMP_IN_MUTE(i)); |
| 2810 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2811 | } |
| 2812 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2813 | /* convert from MIX nid to DAC */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2814 | 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] | 2815 | { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2816 | hda_nid_t list[5]; |
Takashi Iwai | 1304ac8 | 2011-04-06 15:16:21 +0200 | [diff] [blame] | 2817 | int i, num; |
| 2818 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 2819 | if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT) |
| 2820 | return nid; |
Takashi Iwai | 1304ac8 | 2011-04-06 15:16:21 +0200 | [diff] [blame] | 2821 | num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list)); |
| 2822 | for (i = 0; i < num; i++) { |
| 2823 | if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT) |
| 2824 | return list[i]; |
| 2825 | } |
| 2826 | return 0; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2827 | } |
| 2828 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2829 | /* go down to the selector widget before the mixer */ |
| 2830 | static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin) |
| 2831 | { |
| 2832 | hda_nid_t srcs[5]; |
| 2833 | int num = snd_hda_get_connections(codec, pin, srcs, |
| 2834 | ARRAY_SIZE(srcs)); |
| 2835 | if (num != 1 || |
| 2836 | get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL) |
| 2837 | return pin; |
| 2838 | return srcs[0]; |
| 2839 | } |
| 2840 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2841 | /* get MIX nid connected to the given pin targeted to DAC */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2842 | 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] | 2843 | hda_nid_t dac) |
| 2844 | { |
David Henningsson | cc1c452 | 2010-11-24 14:17:47 +0100 | [diff] [blame] | 2845 | hda_nid_t mix[5]; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2846 | int i, num; |
| 2847 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2848 | pin = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2849 | num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); |
| 2850 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2851 | if (alc_auto_mix_to_dac(codec, mix[i]) == dac) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2852 | return mix[i]; |
| 2853 | } |
| 2854 | return 0; |
| 2855 | } |
| 2856 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2857 | /* select the connection from pin to DAC if needed */ |
| 2858 | static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin, |
| 2859 | hda_nid_t dac) |
| 2860 | { |
| 2861 | hda_nid_t mix[5]; |
| 2862 | int i, num; |
| 2863 | |
| 2864 | pin = alc_go_down_to_selector(codec, pin); |
| 2865 | num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); |
| 2866 | if (num < 2) |
| 2867 | return 0; |
| 2868 | for (i = 0; i < num; i++) { |
| 2869 | if (alc_auto_mix_to_dac(codec, mix[i]) == dac) { |
| 2870 | snd_hda_codec_update_cache(codec, pin, 0, |
| 2871 | AC_VERB_SET_CONNECT_SEL, i); |
| 2872 | return 0; |
| 2873 | } |
| 2874 | } |
| 2875 | return 0; |
| 2876 | } |
| 2877 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2878 | /* look for an empty DAC slot */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2879 | 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] | 2880 | { |
| 2881 | struct alc_spec *spec = codec->spec; |
| 2882 | hda_nid_t srcs[5]; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2883 | int i, num; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2884 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2885 | pin = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2886 | num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs)); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2887 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2888 | hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2889 | if (!nid) |
| 2890 | continue; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2891 | if (found_in_nid_list(nid, spec->multiout.dac_nids, |
| 2892 | spec->multiout.num_dacs)) |
| 2893 | continue; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 2894 | if (found_in_nid_list(nid, spec->multiout.hp_out_nid, |
| 2895 | ARRAY_SIZE(spec->multiout.hp_out_nid))) |
| 2896 | continue; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2897 | if (found_in_nid_list(nid, spec->multiout.extra_out_nid, |
| 2898 | ARRAY_SIZE(spec->multiout.extra_out_nid))) |
| 2899 | continue; |
| 2900 | return nid; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2901 | } |
| 2902 | return 0; |
| 2903 | } |
| 2904 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2905 | static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin) |
| 2906 | { |
| 2907 | hda_nid_t sel = alc_go_down_to_selector(codec, pin); |
| 2908 | if (snd_hda_get_conn_list(codec, sel, NULL) == 1) |
| 2909 | return alc_auto_look_for_dac(codec, pin); |
| 2910 | return 0; |
| 2911 | } |
| 2912 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 2913 | static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs, |
| 2914 | const hda_nid_t *pins, hda_nid_t *dacs) |
| 2915 | { |
| 2916 | int i; |
| 2917 | |
| 2918 | if (num_outs && !dacs[0]) { |
| 2919 | dacs[0] = alc_auto_look_for_dac(codec, pins[0]); |
| 2920 | if (!dacs[0]) |
| 2921 | return 0; |
| 2922 | } |
| 2923 | |
| 2924 | for (i = 1; i < num_outs; i++) |
| 2925 | dacs[i] = get_dac_if_single(codec, pins[i]); |
| 2926 | for (i = 1; i < num_outs; i++) { |
| 2927 | if (!dacs[i]) |
| 2928 | dacs[i] = alc_auto_look_for_dac(codec, pins[i]); |
| 2929 | } |
| 2930 | return 0; |
| 2931 | } |
| 2932 | |
| 2933 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, |
| 2934 | unsigned int location); |
| 2935 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2936 | /* fill in the dac_nids table from the parsed pin configuration */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 2937 | static int alc_auto_fill_dac_nids(struct hda_codec *codec) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2938 | { |
| 2939 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | cb053a8 | 2011-06-27 11:32:07 +0200 | [diff] [blame] | 2940 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 350434e | 2011-06-30 21:29:12 +0200 | [diff] [blame] | 2941 | bool redone = false; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2942 | int i; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2943 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2944 | again: |
Takashi Iwai | 8f398ae | 2011-07-23 18:57:11 +0200 | [diff] [blame] | 2945 | /* set num_dacs once to full for alc_auto_look_for_dac() */ |
| 2946 | spec->multiout.num_dacs = cfg->line_outs; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 2947 | spec->multiout.hp_out_nid[0] = 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2948 | spec->multiout.extra_out_nid[0] = 0; |
| 2949 | memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids)); |
| 2950 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 2951 | |
| 2952 | /* fill hard-wired DACs first */ |
| 2953 | if (!redone) { |
| 2954 | for (i = 0; i < cfg->line_outs; i++) |
| 2955 | spec->private_dac_nids[i] = |
| 2956 | get_dac_if_single(codec, cfg->line_out_pins[i]); |
| 2957 | if (cfg->hp_outs) |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 2958 | spec->multiout.hp_out_nid[0] = |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2959 | get_dac_if_single(codec, cfg->hp_pins[0]); |
| 2960 | if (cfg->speaker_outs) |
| 2961 | spec->multiout.extra_out_nid[0] = |
| 2962 | get_dac_if_single(codec, cfg->speaker_pins[0]); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2963 | } |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2964 | |
| 2965 | for (i = 0; i < cfg->line_outs; i++) { |
| 2966 | hda_nid_t pin = cfg->line_out_pins[i]; |
| 2967 | if (spec->private_dac_nids[i]) |
| 2968 | continue; |
| 2969 | spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin); |
| 2970 | if (!spec->private_dac_nids[i] && !redone) { |
| 2971 | /* if we can't find primary DACs, re-probe without |
| 2972 | * checking the hard-wired DACs |
| 2973 | */ |
| 2974 | redone = true; |
| 2975 | goto again; |
| 2976 | } |
| 2977 | } |
| 2978 | |
Takashi Iwai | 8f398ae | 2011-07-23 18:57:11 +0200 | [diff] [blame] | 2979 | /* re-count num_dacs and squash invalid entries */ |
| 2980 | spec->multiout.num_dacs = 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2981 | for (i = 0; i < cfg->line_outs; i++) { |
| 2982 | if (spec->private_dac_nids[i]) |
| 2983 | spec->multiout.num_dacs++; |
| 2984 | else |
| 2985 | memmove(spec->private_dac_nids + i, |
| 2986 | spec->private_dac_nids + i + 1, |
| 2987 | sizeof(hda_nid_t) * (cfg->line_outs - i - 1)); |
| 2988 | } |
| 2989 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 2990 | if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
| 2991 | /* try to fill multi-io first */ |
| 2992 | unsigned int location, defcfg; |
| 2993 | int num_pins; |
Takashi Iwai | bb8bf4d | 2011-07-06 13:07:54 +0200 | [diff] [blame] | 2994 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 2995 | defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]); |
| 2996 | location = get_defcfg_location(defcfg); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2997 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 2998 | num_pins = alc_auto_fill_multi_ios(codec, location); |
| 2999 | if (num_pins > 0) { |
| 3000 | spec->multi_ios = num_pins; |
| 3001 | spec->ext_channel_count = 2; |
| 3002 | spec->multiout.num_dacs = num_pins + 1; |
| 3003 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3004 | } |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3005 | |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3006 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) |
| 3007 | alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins, |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3008 | spec->multiout.hp_out_nid); |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3009 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) |
| 3010 | alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins, |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3011 | spec->multiout.extra_out_nid); |
| 3012 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3013 | return 0; |
| 3014 | } |
| 3015 | |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3016 | static inline unsigned int get_ctl_pos(unsigned int data) |
| 3017 | { |
| 3018 | hda_nid_t nid = get_amp_nid_(data); |
| 3019 | unsigned int dir = get_amp_direction_(data); |
| 3020 | return (nid << 1) | dir; |
| 3021 | } |
| 3022 | |
| 3023 | #define is_ctl_used(bits, data) \ |
| 3024 | test_bit(get_ctl_pos(data), bits) |
| 3025 | #define mark_ctl_usage(bits, data) \ |
| 3026 | set_bit(get_ctl_pos(data), bits) |
| 3027 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3028 | static int alc_auto_add_vol_ctl(struct hda_codec *codec, |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3029 | const char *pfx, int cidx, |
| 3030 | hda_nid_t nid, unsigned int chs) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3031 | { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3032 | struct alc_spec *spec = codec->spec; |
| 3033 | unsigned int val; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3034 | if (!nid) |
| 3035 | return 0; |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3036 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); |
| 3037 | if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */ |
| 3038 | return 0; |
| 3039 | mark_ctl_usage(spec->vol_ctls, val); |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3040 | return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3041 | val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3042 | } |
| 3043 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3044 | #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \ |
| 3045 | alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3) |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3046 | |
| 3047 | /* create a mute-switch for the given mixer widget; |
| 3048 | * if it has multiple sources (e.g. DAC and loopback), create a bind-mute |
| 3049 | */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3050 | static int alc_auto_add_sw_ctl(struct hda_codec *codec, |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3051 | const char *pfx, int cidx, |
| 3052 | hda_nid_t nid, unsigned int chs) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3053 | { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3054 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3055 | int wid_type; |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3056 | int type; |
| 3057 | unsigned long val; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3058 | if (!nid) |
| 3059 | return 0; |
| 3060 | wid_type = get_wcaps_type(get_wcaps(codec, nid)); |
| 3061 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) { |
| 3062 | type = ALC_CTL_WIDGET_MUTE; |
| 3063 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); |
| 3064 | } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) { |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3065 | type = ALC_CTL_WIDGET_MUTE; |
| 3066 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT); |
| 3067 | } else { |
| 3068 | type = ALC_CTL_BIND_MUTE; |
| 3069 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT); |
| 3070 | } |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3071 | if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */ |
| 3072 | return 0; |
| 3073 | mark_ctl_usage(spec->sw_ctls, val); |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3074 | return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3075 | } |
| 3076 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3077 | #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \ |
| 3078 | alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3079 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3080 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, |
| 3081 | hda_nid_t pin, hda_nid_t dac) |
| 3082 | { |
| 3083 | hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac); |
| 3084 | if (nid_has_mute(codec, pin, HDA_OUTPUT)) |
| 3085 | return pin; |
| 3086 | else if (mix && nid_has_mute(codec, mix, HDA_INPUT)) |
| 3087 | return mix; |
| 3088 | else if (nid_has_mute(codec, dac, HDA_OUTPUT)) |
| 3089 | return dac; |
| 3090 | return 0; |
| 3091 | } |
| 3092 | |
| 3093 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, |
| 3094 | hda_nid_t pin, hda_nid_t dac) |
| 3095 | { |
| 3096 | hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac); |
| 3097 | if (nid_has_volume(codec, dac, HDA_OUTPUT)) |
| 3098 | return dac; |
| 3099 | else if (nid_has_volume(codec, mix, HDA_OUTPUT)) |
| 3100 | return mix; |
| 3101 | else if (nid_has_volume(codec, pin, HDA_OUTPUT)) |
| 3102 | return pin; |
| 3103 | return 0; |
| 3104 | } |
| 3105 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3106 | /* add playback controls from the parsed DAC table */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3107 | static int alc_auto_create_multi_out_ctls(struct hda_codec *codec, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3108 | const struct auto_pin_cfg *cfg) |
| 3109 | { |
| 3110 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3111 | int i, err, noutputs; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3112 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3113 | noutputs = cfg->line_outs; |
| 3114 | if (spec->multi_ios > 0) |
| 3115 | noutputs += spec->multi_ios; |
| 3116 | |
| 3117 | for (i = 0; i < noutputs; i++) { |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 3118 | const char *name; |
| 3119 | int index; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3120 | hda_nid_t dac, pin; |
| 3121 | hda_nid_t sw, vol; |
| 3122 | |
| 3123 | dac = spec->multiout.dac_nids[i]; |
| 3124 | if (!dac) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3125 | continue; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3126 | if (i >= cfg->line_outs) |
| 3127 | pin = spec->multi_io[i - 1].pin; |
| 3128 | else |
| 3129 | pin = cfg->line_out_pins[i]; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3130 | |
| 3131 | sw = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3132 | vol = alc_look_for_out_vol_nid(codec, pin, dac); |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 3133 | name = alc_get_line_out_pfx(spec, i, true, &index); |
Takashi Iwai | 9c4e84d | 2011-08-24 17:27:52 +0200 | [diff] [blame] | 3134 | if (!name || !strcmp(name, "CLFE")) { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3135 | /* Center/LFE */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3136 | err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3137 | if (err < 0) |
| 3138 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3139 | err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3140 | if (err < 0) |
| 3141 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3142 | err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3143 | if (err < 0) |
| 3144 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3145 | err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3146 | if (err < 0) |
| 3147 | return err; |
| 3148 | } else { |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3149 | err = alc_auto_add_stereo_vol(codec, name, index, vol); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3150 | if (err < 0) |
| 3151 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3152 | err = alc_auto_add_stereo_sw(codec, name, index, sw); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3153 | if (err < 0) |
| 3154 | return err; |
| 3155 | } |
| 3156 | } |
| 3157 | return 0; |
| 3158 | } |
| 3159 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3160 | 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] | 3161 | hda_nid_t dac, const char *pfx) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3162 | { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3163 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3164 | hda_nid_t sw, vol; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3165 | int err; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3166 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3167 | if (!dac) { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3168 | unsigned int val; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3169 | /* the corresponding DAC is already occupied */ |
| 3170 | if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)) |
| 3171 | return 0; /* no way */ |
| 3172 | /* create a switch only */ |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3173 | val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT); |
| 3174 | if (is_ctl_used(spec->sw_ctls, val)) |
| 3175 | return 0; /* already created */ |
| 3176 | mark_ctl_usage(spec->sw_ctls, val); |
| 3177 | return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3178 | } |
| 3179 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3180 | sw = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3181 | vol = alc_look_for_out_vol_nid(codec, pin, dac); |
| 3182 | err = alc_auto_add_stereo_vol(codec, pfx, 0, vol); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3183 | if (err < 0) |
Takashi Iwai | 24fb917 | 2008-09-02 14:48:20 +0200 | [diff] [blame] | 3184 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3185 | err = alc_auto_add_stereo_sw(codec, pfx, 0, sw); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3186 | if (err < 0) |
| 3187 | return err; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3188 | return 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3189 | } |
| 3190 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3191 | static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec, |
| 3192 | unsigned int nums, |
| 3193 | struct hda_ctl_ops *ops) |
| 3194 | { |
| 3195 | struct alc_spec *spec = codec->spec; |
| 3196 | struct hda_bind_ctls **ctlp, *ctl; |
| 3197 | snd_array_init(&spec->bind_ctls, sizeof(ctl), 8); |
| 3198 | ctlp = snd_array_new(&spec->bind_ctls); |
| 3199 | if (!ctlp) |
| 3200 | return NULL; |
| 3201 | ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL); |
| 3202 | *ctlp = ctl; |
| 3203 | if (ctl) |
| 3204 | ctl->ops = ops; |
| 3205 | return ctl; |
| 3206 | } |
| 3207 | |
| 3208 | /* add playback controls for speaker and HP outputs */ |
| 3209 | static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins, |
| 3210 | const hda_nid_t *pins, |
| 3211 | const hda_nid_t *dacs, |
| 3212 | const char *pfx) |
| 3213 | { |
| 3214 | struct alc_spec *spec = codec->spec; |
| 3215 | struct hda_bind_ctls *ctl; |
| 3216 | char name[32]; |
| 3217 | int i, n, err; |
| 3218 | |
| 3219 | if (!num_pins || !pins[0]) |
| 3220 | return 0; |
| 3221 | |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3222 | if (num_pins == 1) { |
| 3223 | hda_nid_t dac = *dacs; |
| 3224 | if (!dac) |
| 3225 | dac = spec->multiout.dac_nids[0]; |
| 3226 | return alc_auto_create_extra_out(codec, *pins, dac, pfx); |
| 3227 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3228 | |
| 3229 | if (dacs[num_pins - 1]) { |
| 3230 | /* OK, we have a multi-output system with individual volumes */ |
| 3231 | for (i = 0; i < num_pins; i++) { |
| 3232 | snprintf(name, sizeof(name), "%s %s", |
| 3233 | pfx, channel_name[i]); |
| 3234 | err = alc_auto_create_extra_out(codec, pins[i], dacs[i], |
| 3235 | name); |
| 3236 | if (err < 0) |
| 3237 | return err; |
| 3238 | } |
| 3239 | return 0; |
| 3240 | } |
| 3241 | |
| 3242 | /* Let's create a bind-controls */ |
| 3243 | ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw); |
| 3244 | if (!ctl) |
| 3245 | return -ENOMEM; |
| 3246 | n = 0; |
| 3247 | for (i = 0; i < num_pins; i++) { |
| 3248 | if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP) |
| 3249 | ctl->values[n++] = |
| 3250 | HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT); |
| 3251 | } |
| 3252 | if (n) { |
| 3253 | snprintf(name, sizeof(name), "%s Playback Switch", pfx); |
| 3254 | err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl); |
| 3255 | if (err < 0) |
| 3256 | return err; |
| 3257 | } |
| 3258 | |
| 3259 | ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol); |
| 3260 | if (!ctl) |
| 3261 | return -ENOMEM; |
| 3262 | n = 0; |
| 3263 | for (i = 0; i < num_pins; i++) { |
| 3264 | hda_nid_t vol; |
| 3265 | if (!pins[i] || !dacs[i]) |
| 3266 | continue; |
| 3267 | vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]); |
| 3268 | if (vol) |
| 3269 | ctl->values[n++] = |
| 3270 | HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT); |
| 3271 | } |
| 3272 | if (n) { |
| 3273 | snprintf(name, sizeof(name), "%s Playback Volume", pfx); |
| 3274 | err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl); |
| 3275 | if (err < 0) |
| 3276 | return err; |
| 3277 | } |
| 3278 | return 0; |
| 3279 | } |
| 3280 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3281 | static int alc_auto_create_hp_out(struct hda_codec *codec) |
| 3282 | { |
| 3283 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3284 | return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs, |
| 3285 | spec->autocfg.hp_pins, |
| 3286 | spec->multiout.hp_out_nid, |
| 3287 | "Headphone"); |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3288 | } |
| 3289 | |
| 3290 | static int alc_auto_create_speaker_out(struct hda_codec *codec) |
| 3291 | { |
| 3292 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3293 | return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs, |
| 3294 | spec->autocfg.speaker_pins, |
| 3295 | spec->multiout.extra_out_nid, |
| 3296 | "Speaker"); |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3297 | } |
| 3298 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3299 | static void alc_auto_set_output_and_unmute(struct hda_codec *codec, |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3300 | hda_nid_t pin, int pin_type, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3301 | hda_nid_t dac) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3302 | { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3303 | int i, num; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3304 | hda_nid_t nid, mix = 0; |
Takashi Iwai | ce503f3 | 2010-07-30 10:37:29 +0200 | [diff] [blame] | 3305 | hda_nid_t srcs[HDA_MAX_CONNECTIONS]; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3306 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3307 | alc_set_pin_output(codec, pin, pin_type); |
| 3308 | nid = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3309 | num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs)); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3310 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 3311 | if (alc_auto_mix_to_dac(codec, srcs[i]) != dac) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3312 | continue; |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3313 | mix = srcs[i]; |
| 3314 | break; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3315 | } |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3316 | if (!mix) |
| 3317 | return; |
| 3318 | |
| 3319 | /* need the manual connection? */ |
| 3320 | if (num > 1) |
| 3321 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i); |
| 3322 | /* unmute mixer widget inputs */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3323 | if (nid_has_mute(codec, mix, HDA_INPUT)) { |
| 3324 | 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] | 3325 | AMP_IN_UNMUTE(0)); |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3326 | 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] | 3327 | AMP_IN_UNMUTE(1)); |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3328 | } |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3329 | /* initialize volume */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3330 | nid = alc_look_for_out_vol_nid(codec, pin, dac); |
| 3331 | if (nid) |
| 3332 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 3333 | AMP_OUT_ZERO); |
Takashi Iwai | 43dea22 | 2011-11-06 11:25:34 +0100 | [diff] [blame] | 3334 | |
| 3335 | /* unmute DAC if it's not assigned to a mixer */ |
| 3336 | nid = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3337 | if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT)) |
| 3338 | snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 3339 | AMP_OUT_ZERO); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3340 | } |
| 3341 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3342 | static void alc_auto_init_multi_out(struct hda_codec *codec) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3343 | { |
| 3344 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3345 | int pin_type = get_pin_type(spec->autocfg.line_out_type); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3346 | int i; |
| 3347 | |
| 3348 | for (i = 0; i <= HDA_SIDE; i++) { |
| 3349 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; |
| 3350 | if (nid) |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3351 | alc_auto_set_output_and_unmute(codec, nid, pin_type, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3352 | spec->multiout.dac_nids[i]); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3353 | } |
| 3354 | } |
| 3355 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3356 | static void alc_auto_init_extra_out(struct hda_codec *codec) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3357 | { |
| 3358 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3359 | int i; |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3360 | hda_nid_t pin, dac; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3361 | |
David Henningsson | 636030e | 2011-10-12 19:26:03 +0200 | [diff] [blame] | 3362 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3363 | if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT) |
| 3364 | break; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3365 | pin = spec->autocfg.hp_pins[i]; |
| 3366 | if (!pin) |
| 3367 | break; |
| 3368 | dac = spec->multiout.hp_out_nid[i]; |
| 3369 | if (!dac) { |
| 3370 | if (i > 0 && spec->multiout.hp_out_nid[0]) |
| 3371 | dac = spec->multiout.hp_out_nid[0]; |
| 3372 | else |
| 3373 | dac = spec->multiout.dac_nids[0]; |
| 3374 | } |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3375 | alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac); |
| 3376 | } |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3377 | for (i = 0; i < spec->autocfg.speaker_outs; i++) { |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3378 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) |
| 3379 | break; |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3380 | pin = spec->autocfg.speaker_pins[i]; |
| 3381 | if (!pin) |
| 3382 | break; |
| 3383 | dac = spec->multiout.extra_out_nid[i]; |
| 3384 | if (!dac) { |
| 3385 | if (i > 0 && spec->multiout.extra_out_nid[0]) |
| 3386 | dac = spec->multiout.extra_out_nid[0]; |
| 3387 | else |
| 3388 | dac = spec->multiout.dac_nids[0]; |
| 3389 | } |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3390 | alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac); |
| 3391 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3392 | } |
| 3393 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3394 | /* |
| 3395 | * multi-io helper |
| 3396 | */ |
| 3397 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, |
| 3398 | unsigned int location) |
| 3399 | { |
| 3400 | struct alc_spec *spec = codec->spec; |
| 3401 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3402 | hda_nid_t prime_dac = spec->private_dac_nids[0]; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3403 | int type, i, num_pins = 0; |
| 3404 | |
| 3405 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { |
| 3406 | for (i = 0; i < cfg->num_inputs; i++) { |
| 3407 | hda_nid_t nid = cfg->inputs[i].pin; |
| 3408 | hda_nid_t dac; |
| 3409 | unsigned int defcfg, caps; |
| 3410 | if (cfg->inputs[i].type != type) |
| 3411 | continue; |
| 3412 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
| 3413 | if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX) |
| 3414 | continue; |
| 3415 | if (location && get_defcfg_location(defcfg) != location) |
| 3416 | continue; |
| 3417 | caps = snd_hda_query_pin_caps(codec, nid); |
| 3418 | if (!(caps & AC_PINCAP_OUT)) |
| 3419 | continue; |
| 3420 | dac = alc_auto_look_for_dac(codec, nid); |
| 3421 | if (!dac) |
| 3422 | continue; |
| 3423 | spec->multi_io[num_pins].pin = nid; |
| 3424 | spec->multi_io[num_pins].dac = dac; |
| 3425 | num_pins++; |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3426 | spec->private_dac_nids[spec->multiout.num_dacs++] = dac; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3427 | } |
| 3428 | } |
| 3429 | spec->multiout.num_dacs = 1; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3430 | if (num_pins < 2) { |
| 3431 | /* clear up again */ |
| 3432 | memset(spec->private_dac_nids, 0, |
| 3433 | sizeof(spec->private_dac_nids)); |
| 3434 | spec->private_dac_nids[0] = prime_dac; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3435 | return 0; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3436 | } |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3437 | return num_pins; |
| 3438 | } |
| 3439 | |
| 3440 | static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol, |
| 3441 | struct snd_ctl_elem_info *uinfo) |
| 3442 | { |
| 3443 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3444 | struct alc_spec *spec = codec->spec; |
| 3445 | |
| 3446 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 3447 | uinfo->count = 1; |
| 3448 | uinfo->value.enumerated.items = spec->multi_ios + 1; |
| 3449 | if (uinfo->value.enumerated.item > spec->multi_ios) |
| 3450 | uinfo->value.enumerated.item = spec->multi_ios; |
| 3451 | sprintf(uinfo->value.enumerated.name, "%dch", |
| 3452 | (uinfo->value.enumerated.item + 1) * 2); |
| 3453 | return 0; |
| 3454 | } |
| 3455 | |
| 3456 | static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol, |
| 3457 | struct snd_ctl_elem_value *ucontrol) |
| 3458 | { |
| 3459 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3460 | struct alc_spec *spec = codec->spec; |
| 3461 | ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2; |
| 3462 | return 0; |
| 3463 | } |
| 3464 | |
| 3465 | static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output) |
| 3466 | { |
| 3467 | struct alc_spec *spec = codec->spec; |
| 3468 | hda_nid_t nid = spec->multi_io[idx].pin; |
| 3469 | |
| 3470 | if (!spec->multi_io[idx].ctl_in) |
| 3471 | spec->multi_io[idx].ctl_in = |
| 3472 | snd_hda_codec_read(codec, nid, 0, |
| 3473 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 3474 | if (output) { |
| 3475 | snd_hda_codec_update_cache(codec, nid, 0, |
| 3476 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 3477 | PIN_OUT); |
| 3478 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
| 3479 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
| 3480 | HDA_AMP_MUTE, 0); |
| 3481 | alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac); |
| 3482 | } else { |
| 3483 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
| 3484 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
| 3485 | HDA_AMP_MUTE, HDA_AMP_MUTE); |
| 3486 | snd_hda_codec_update_cache(codec, nid, 0, |
| 3487 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 3488 | spec->multi_io[idx].ctl_in); |
| 3489 | } |
| 3490 | return 0; |
| 3491 | } |
| 3492 | |
| 3493 | static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol, |
| 3494 | struct snd_ctl_elem_value *ucontrol) |
| 3495 | { |
| 3496 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3497 | struct alc_spec *spec = codec->spec; |
| 3498 | int i, ch; |
| 3499 | |
| 3500 | ch = ucontrol->value.enumerated.item[0]; |
| 3501 | if (ch < 0 || ch > spec->multi_ios) |
| 3502 | return -EINVAL; |
| 3503 | if (ch == (spec->ext_channel_count - 1) / 2) |
| 3504 | return 0; |
| 3505 | spec->ext_channel_count = (ch + 1) * 2; |
| 3506 | for (i = 0; i < spec->multi_ios; i++) |
| 3507 | alc_set_multi_io(codec, i, i < ch); |
| 3508 | spec->multiout.max_channels = spec->ext_channel_count; |
Takashi Iwai | 7b1655f | 2011-07-14 15:31:21 +0200 | [diff] [blame] | 3509 | if (spec->need_dac_fix && !spec->const_channel_count) |
| 3510 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3511 | return 1; |
| 3512 | } |
| 3513 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 3514 | static const struct snd_kcontrol_new alc_auto_channel_mode_enum = { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3515 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3516 | .name = "Channel Mode", |
| 3517 | .info = alc_auto_ch_mode_info, |
| 3518 | .get = alc_auto_ch_mode_get, |
| 3519 | .put = alc_auto_ch_mode_put, |
| 3520 | }; |
| 3521 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3522 | static int alc_auto_add_multi_channel_mode(struct hda_codec *codec) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3523 | { |
| 3524 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3525 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3526 | if (spec->multi_ios > 0) { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3527 | struct snd_kcontrol_new *knew; |
| 3528 | |
| 3529 | knew = alc_kcontrol_new(spec); |
| 3530 | if (!knew) |
| 3531 | return -ENOMEM; |
| 3532 | *knew = alc_auto_channel_mode_enum; |
| 3533 | knew->name = kstrdup("Channel Mode", GFP_KERNEL); |
| 3534 | if (!knew->name) |
| 3535 | return -ENOMEM; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3536 | } |
| 3537 | return 0; |
| 3538 | } |
| 3539 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3540 | /* filter out invalid adc_nids (and capsrc_nids) that don't give all |
| 3541 | * active input pins |
| 3542 | */ |
| 3543 | static void alc_remove_invalid_adc_nids(struct hda_codec *codec) |
| 3544 | { |
| 3545 | struct alc_spec *spec = codec->spec; |
| 3546 | const struct hda_input_mux *imux; |
| 3547 | hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)]; |
| 3548 | hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)]; |
| 3549 | int i, n, nums; |
| 3550 | |
| 3551 | imux = spec->input_mux; |
| 3552 | if (!imux) |
| 3553 | return; |
| 3554 | if (spec->dyn_adc_switch) |
| 3555 | return; |
| 3556 | |
| 3557 | nums = 0; |
| 3558 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 3559 | hda_nid_t cap = spec->private_capsrc_nids[n]; |
| 3560 | int num_conns = snd_hda_get_conn_list(codec, cap, NULL); |
| 3561 | for (i = 0; i < imux->num_items; i++) { |
| 3562 | hda_nid_t pin = spec->imux_pins[i]; |
| 3563 | if (pin) { |
| 3564 | if (get_connection_index(codec, cap, pin) < 0) |
| 3565 | break; |
| 3566 | } else if (num_conns <= imux->items[i].index) |
| 3567 | break; |
| 3568 | } |
| 3569 | if (i >= imux->num_items) { |
| 3570 | adc_nids[nums] = spec->private_adc_nids[n]; |
| 3571 | capsrc_nids[nums++] = cap; |
| 3572 | } |
| 3573 | } |
| 3574 | if (!nums) { |
| 3575 | /* check whether ADC-switch is possible */ |
| 3576 | if (!alc_check_dyn_adc_switch(codec)) { |
| 3577 | printk(KERN_WARNING "hda_codec: %s: no valid ADC found;" |
| 3578 | " using fallback 0x%x\n", |
| 3579 | codec->chip_name, spec->private_adc_nids[0]); |
| 3580 | spec->num_adc_nids = 1; |
| 3581 | spec->auto_mic = 0; |
| 3582 | return; |
| 3583 | } |
| 3584 | } else if (nums != spec->num_adc_nids) { |
| 3585 | memcpy(spec->private_adc_nids, adc_nids, |
| 3586 | nums * sizeof(hda_nid_t)); |
| 3587 | memcpy(spec->private_capsrc_nids, capsrc_nids, |
| 3588 | nums * sizeof(hda_nid_t)); |
| 3589 | spec->num_adc_nids = nums; |
| 3590 | } |
| 3591 | |
| 3592 | if (spec->auto_mic) |
| 3593 | alc_auto_mic_check_imux(codec); /* check auto-mic setups */ |
| 3594 | else if (spec->input_mux->num_items == 1) |
| 3595 | spec->num_adc_nids = 1; /* reduce to a single ADC */ |
| 3596 | } |
| 3597 | |
| 3598 | /* |
| 3599 | * initialize ADC paths |
| 3600 | */ |
| 3601 | static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx) |
| 3602 | { |
| 3603 | struct alc_spec *spec = codec->spec; |
| 3604 | hda_nid_t nid; |
| 3605 | |
| 3606 | nid = spec->adc_nids[adc_idx]; |
| 3607 | /* mute ADC */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3608 | if (nid_has_mute(codec, nid, HDA_INPUT)) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3609 | snd_hda_codec_write(codec, nid, 0, |
| 3610 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 3611 | AMP_IN_MUTE(0)); |
| 3612 | return; |
| 3613 | } |
| 3614 | if (!spec->capsrc_nids) |
| 3615 | return; |
| 3616 | nid = spec->capsrc_nids[adc_idx]; |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3617 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3618 | snd_hda_codec_write(codec, nid, 0, |
| 3619 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 3620 | AMP_OUT_MUTE); |
| 3621 | } |
| 3622 | |
| 3623 | static void alc_auto_init_input_src(struct hda_codec *codec) |
| 3624 | { |
| 3625 | struct alc_spec *spec = codec->spec; |
| 3626 | int c, nums; |
| 3627 | |
| 3628 | for (c = 0; c < spec->num_adc_nids; c++) |
| 3629 | alc_auto_init_adc(codec, c); |
| 3630 | if (spec->dyn_adc_switch) |
| 3631 | nums = 1; |
| 3632 | else |
| 3633 | nums = spec->num_adc_nids; |
| 3634 | for (c = 0; c < nums; c++) |
| 3635 | alc_mux_select(codec, 0, spec->cur_mux[c], true); |
| 3636 | } |
| 3637 | |
| 3638 | /* add mic boosts if needed */ |
| 3639 | static int alc_auto_add_mic_boost(struct hda_codec *codec) |
| 3640 | { |
| 3641 | struct alc_spec *spec = codec->spec; |
| 3642 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3643 | int i, err; |
| 3644 | int type_idx = 0; |
| 3645 | hda_nid_t nid; |
| 3646 | const char *prev_label = NULL; |
| 3647 | |
| 3648 | for (i = 0; i < cfg->num_inputs; i++) { |
| 3649 | if (cfg->inputs[i].type > AUTO_PIN_MIC) |
| 3650 | break; |
| 3651 | nid = cfg->inputs[i].pin; |
| 3652 | if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { |
| 3653 | const char *label; |
| 3654 | char boost_label[32]; |
| 3655 | |
| 3656 | label = hda_get_autocfg_input_label(codec, cfg, i); |
| 3657 | if (prev_label && !strcmp(label, prev_label)) |
| 3658 | type_idx++; |
| 3659 | else |
| 3660 | type_idx = 0; |
| 3661 | prev_label = label; |
| 3662 | |
| 3663 | snprintf(boost_label, sizeof(boost_label), |
| 3664 | "%s Boost Volume", label); |
| 3665 | err = add_control(spec, ALC_CTL_WIDGET_VOL, |
| 3666 | boost_label, type_idx, |
| 3667 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT)); |
| 3668 | if (err < 0) |
| 3669 | return err; |
| 3670 | } |
| 3671 | } |
| 3672 | return 0; |
| 3673 | } |
| 3674 | |
| 3675 | /* select or unmute the given capsrc route */ |
| 3676 | static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap, |
| 3677 | int idx) |
| 3678 | { |
| 3679 | if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) { |
| 3680 | snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx, |
| 3681 | HDA_AMP_MUTE, 0); |
| 3682 | } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) { |
| 3683 | snd_hda_codec_write_cache(codec, cap, 0, |
| 3684 | AC_VERB_SET_CONNECT_SEL, idx); |
| 3685 | } |
| 3686 | } |
| 3687 | |
| 3688 | /* set the default connection to that pin */ |
| 3689 | static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin) |
| 3690 | { |
| 3691 | struct alc_spec *spec = codec->spec; |
| 3692 | int i; |
| 3693 | |
| 3694 | if (!pin) |
| 3695 | return 0; |
| 3696 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 3697 | hda_nid_t cap = spec->capsrc_nids ? |
| 3698 | spec->capsrc_nids[i] : spec->adc_nids[i]; |
| 3699 | int idx; |
| 3700 | |
| 3701 | idx = get_connection_index(codec, cap, pin); |
| 3702 | if (idx < 0) |
| 3703 | continue; |
| 3704 | select_or_unmute_capsrc(codec, cap, idx); |
| 3705 | return i; /* return the found index */ |
| 3706 | } |
| 3707 | return -1; /* not found */ |
| 3708 | } |
| 3709 | |
| 3710 | /* initialize some special cases for input sources */ |
| 3711 | static void alc_init_special_input_src(struct hda_codec *codec) |
| 3712 | { |
| 3713 | struct alc_spec *spec = codec->spec; |
| 3714 | int i; |
| 3715 | |
| 3716 | for (i = 0; i < spec->autocfg.num_inputs; i++) |
| 3717 | init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin); |
| 3718 | } |
| 3719 | |
| 3720 | /* assign appropriate capture mixers */ |
| 3721 | static void set_capture_mixer(struct hda_codec *codec) |
| 3722 | { |
| 3723 | struct alc_spec *spec = codec->spec; |
| 3724 | static const struct snd_kcontrol_new *caps[2][3] = { |
| 3725 | { alc_capture_mixer_nosrc1, |
| 3726 | alc_capture_mixer_nosrc2, |
| 3727 | alc_capture_mixer_nosrc3 }, |
| 3728 | { alc_capture_mixer1, |
| 3729 | alc_capture_mixer2, |
| 3730 | alc_capture_mixer3 }, |
| 3731 | }; |
| 3732 | |
| 3733 | /* check whether either of ADC or MUX has a volume control */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3734 | if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3735 | if (!spec->capsrc_nids) |
| 3736 | return; /* no volume */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3737 | if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT)) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3738 | return; /* no volume in capsrc, too */ |
| 3739 | spec->vol_in_capsrc = 1; |
| 3740 | } |
| 3741 | |
| 3742 | if (spec->num_adc_nids > 0) { |
| 3743 | int mux = 0; |
| 3744 | int num_adcs = 0; |
| 3745 | |
| 3746 | if (spec->input_mux && spec->input_mux->num_items > 1) |
| 3747 | mux = 1; |
| 3748 | if (spec->auto_mic) { |
| 3749 | num_adcs = 1; |
| 3750 | mux = 0; |
| 3751 | } else if (spec->dyn_adc_switch) |
| 3752 | num_adcs = 1; |
| 3753 | if (!num_adcs) { |
| 3754 | if (spec->num_adc_nids > 3) |
| 3755 | spec->num_adc_nids = 3; |
| 3756 | else if (!spec->num_adc_nids) |
| 3757 | return; |
| 3758 | num_adcs = spec->num_adc_nids; |
| 3759 | } |
| 3760 | spec->cap_mixer = caps[mux][num_adcs - 1]; |
| 3761 | } |
| 3762 | } |
| 3763 | |
| 3764 | /* |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 3765 | * standard auto-parser initializations |
| 3766 | */ |
| 3767 | static void alc_auto_init_std(struct hda_codec *codec) |
| 3768 | { |
| 3769 | struct alc_spec *spec = codec->spec; |
| 3770 | alc_auto_init_multi_out(codec); |
| 3771 | alc_auto_init_extra_out(codec); |
| 3772 | alc_auto_init_analog_input(codec); |
| 3773 | alc_auto_init_input_src(codec); |
| 3774 | alc_auto_init_digital(codec); |
| 3775 | if (spec->unsol_event) |
| 3776 | alc_inithook(codec); |
| 3777 | } |
| 3778 | |
| 3779 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3780 | * Digital-beep handlers |
| 3781 | */ |
| 3782 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
| 3783 | #define set_beep_amp(spec, nid, idx, dir) \ |
| 3784 | ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir)) |
| 3785 | |
| 3786 | static const struct snd_pci_quirk beep_white_list[] = { |
| 3787 | SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1), |
| 3788 | SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1), |
| 3789 | SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1), |
| 3790 | SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1), |
| 3791 | SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1), |
| 3792 | {} |
| 3793 | }; |
| 3794 | |
| 3795 | static inline int has_cdefine_beep(struct hda_codec *codec) |
| 3796 | { |
| 3797 | struct alc_spec *spec = codec->spec; |
| 3798 | const struct snd_pci_quirk *q; |
| 3799 | q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list); |
| 3800 | if (q) |
| 3801 | return q->value; |
| 3802 | return spec->cdefine.enable_pcbeep; |
| 3803 | } |
| 3804 | #else |
| 3805 | #define set_beep_amp(spec, nid, idx, dir) /* NOP */ |
| 3806 | #define has_cdefine_beep(codec) 0 |
| 3807 | #endif |
| 3808 | |
| 3809 | /* parse the BIOS configuration and set up the alc_spec */ |
| 3810 | /* return 1 if successful, 0 if the proper config is not found, |
| 3811 | * or a negative error code |
| 3812 | */ |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3813 | static int alc_parse_auto_config(struct hda_codec *codec, |
| 3814 | const hda_nid_t *ignore_nids, |
| 3815 | const hda_nid_t *ssid_nids) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3816 | { |
| 3817 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3818 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3819 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3820 | |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 3821 | err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids, |
| 3822 | spec->parse_flags); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3823 | if (err < 0) |
| 3824 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3825 | if (!cfg->line_outs) { |
| 3826 | if (cfg->dig_outs || cfg->dig_in_pin) { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3827 | spec->multiout.max_channels = 2; |
| 3828 | spec->no_analog = 1; |
| 3829 | goto dig_only; |
| 3830 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3831 | return 0; /* can't find valid BIOS pin config */ |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3832 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3833 | |
Takashi Iwai | 0650367 | 2011-10-06 08:27:19 +0200 | [diff] [blame] | 3834 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && |
| 3835 | cfg->line_outs <= cfg->hp_outs) { |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3836 | /* use HP as primary out */ |
| 3837 | cfg->speaker_outs = cfg->line_outs; |
| 3838 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 3839 | sizeof(cfg->speaker_pins)); |
| 3840 | cfg->line_outs = cfg->hp_outs; |
| 3841 | memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins)); |
| 3842 | cfg->hp_outs = 0; |
| 3843 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); |
| 3844 | cfg->line_out_type = AUTO_PIN_HP_OUT; |
| 3845 | } |
| 3846 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3847 | err = alc_auto_fill_dac_nids(codec); |
| 3848 | if (err < 0) |
| 3849 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3850 | err = alc_auto_add_multi_channel_mode(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3851 | if (err < 0) |
| 3852 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3853 | err = alc_auto_create_multi_out_ctls(codec, cfg); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3854 | if (err < 0) |
| 3855 | return err; |
| 3856 | err = alc_auto_create_hp_out(codec); |
| 3857 | if (err < 0) |
| 3858 | return err; |
| 3859 | err = alc_auto_create_speaker_out(codec); |
| 3860 | if (err < 0) |
| 3861 | return err; |
| 3862 | err = alc_auto_create_input_ctls(codec); |
| 3863 | if (err < 0) |
| 3864 | return err; |
| 3865 | |
| 3866 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3867 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3868 | dig_only: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3869 | alc_auto_parse_digital(codec); |
| 3870 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3871 | if (!spec->no_analog) |
| 3872 | alc_remove_invalid_adc_nids(codec); |
| 3873 | |
| 3874 | if (ssid_nids) |
| 3875 | alc_ssid_check(codec, ssid_nids); |
| 3876 | |
| 3877 | if (!spec->no_analog) { |
| 3878 | alc_auto_check_switches(codec); |
| 3879 | err = alc_auto_add_mic_boost(codec); |
| 3880 | if (err < 0) |
| 3881 | return err; |
| 3882 | } |
| 3883 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3884 | if (spec->kctls.list) |
| 3885 | add_mixer(spec, spec->kctls.list); |
| 3886 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3887 | return 1; |
| 3888 | } |
| 3889 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3890 | static int alc880_parse_auto_config(struct hda_codec *codec) |
| 3891 | { |
| 3892 | static const hda_nid_t alc880_ignore[] = { 0x1d, 0 }; |
| 3893 | static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 3894 | return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids); |
| 3895 | } |
| 3896 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3897 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3898 | static const struct hda_amp_list alc880_loopbacks[] = { |
| 3899 | { 0x0b, HDA_INPUT, 0 }, |
| 3900 | { 0x0b, HDA_INPUT, 1 }, |
| 3901 | { 0x0b, HDA_INPUT, 2 }, |
| 3902 | { 0x0b, HDA_INPUT, 3 }, |
| 3903 | { 0x0b, HDA_INPUT, 4 }, |
| 3904 | { } /* end */ |
| 3905 | }; |
| 3906 | #endif |
| 3907 | |
| 3908 | /* |
| 3909 | * board setups |
| 3910 | */ |
| 3911 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 3912 | #define alc_board_config \ |
| 3913 | snd_hda_check_board_config |
| 3914 | #define alc_board_codec_sid_config \ |
| 3915 | snd_hda_check_board_codec_sid_config |
| 3916 | #include "alc_quirks.c" |
| 3917 | #else |
| 3918 | #define alc_board_config(codec, nums, models, tbl) -1 |
| 3919 | #define alc_board_codec_sid_config(codec, nums, models, tbl) -1 |
| 3920 | #define setup_preset(codec, x) /* NOP */ |
| 3921 | #endif |
| 3922 | |
| 3923 | /* |
| 3924 | * OK, here we have finally the patch for ALC880 |
| 3925 | */ |
| 3926 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 3927 | #include "alc880_quirks.c" |
| 3928 | #endif |
| 3929 | |
| 3930 | static int patch_alc880(struct hda_codec *codec) |
| 3931 | { |
| 3932 | struct alc_spec *spec; |
| 3933 | int board_config; |
| 3934 | int err; |
| 3935 | |
| 3936 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 3937 | if (spec == NULL) |
| 3938 | return -ENOMEM; |
| 3939 | |
| 3940 | codec->spec = spec; |
| 3941 | |
| 3942 | spec->mixer_nid = 0x0b; |
Takashi Iwai | 7b1655f | 2011-07-14 15:31:21 +0200 | [diff] [blame] | 3943 | spec->need_dac_fix = 1; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3944 | |
| 3945 | board_config = alc_board_config(codec, ALC880_MODEL_LAST, |
| 3946 | alc880_models, alc880_cfg_tbl); |
| 3947 | if (board_config < 0) { |
| 3948 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 3949 | codec->chip_name); |
| 3950 | board_config = ALC_MODEL_AUTO; |
| 3951 | } |
| 3952 | |
| 3953 | if (board_config == ALC_MODEL_AUTO) { |
| 3954 | /* automatic parse from the BIOS config */ |
| 3955 | err = alc880_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 3956 | if (err < 0) |
| 3957 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3958 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 3959 | else if (!err) { |
| 3960 | printk(KERN_INFO |
| 3961 | "hda_codec: Cannot set up configuration " |
| 3962 | "from BIOS. Using 3-stack mode...\n"); |
| 3963 | board_config = ALC880_3ST; |
| 3964 | } |
| 3965 | #endif |
| 3966 | } |
| 3967 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3968 | if (board_config != ALC_MODEL_AUTO) |
| 3969 | setup_preset(codec, &alc880_presets[board_config]); |
| 3970 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 3971 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3972 | alc_auto_fill_adc_caps(codec); |
| 3973 | alc_rebuild_imux_for_auto_mic(codec); |
| 3974 | alc_remove_invalid_adc_nids(codec); |
| 3975 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3976 | |
| 3977 | if (!spec->no_analog && !spec->cap_mixer) |
| 3978 | set_capture_mixer(codec); |
| 3979 | |
| 3980 | if (!spec->no_analog) { |
| 3981 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 3982 | if (err < 0) |
| 3983 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3984 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 3985 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3986 | |
| 3987 | spec->vmaster_nid = 0x0c; |
| 3988 | |
| 3989 | codec->patch_ops = alc_patch_ops; |
| 3990 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 3991 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3992 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3993 | if (!spec->loopback.amplist) |
| 3994 | spec->loopback.amplist = alc880_loopbacks; |
| 3995 | #endif |
| 3996 | |
| 3997 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 3998 | |
| 3999 | error: |
| 4000 | alc_free(codec); |
| 4001 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4002 | } |
| 4003 | |
| 4004 | |
| 4005 | /* |
| 4006 | * ALC260 support |
| 4007 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4008 | static int alc260_parse_auto_config(struct hda_codec *codec) |
| 4009 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4010 | static const hda_nid_t alc260_ignore[] = { 0x17, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4011 | static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 }; |
| 4012 | return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4013 | } |
| 4014 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4015 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4016 | static const struct hda_amp_list alc260_loopbacks[] = { |
| 4017 | { 0x07, HDA_INPUT, 0 }, |
| 4018 | { 0x07, HDA_INPUT, 1 }, |
| 4019 | { 0x07, HDA_INPUT, 2 }, |
| 4020 | { 0x07, HDA_INPUT, 3 }, |
| 4021 | { 0x07, HDA_INPUT, 4 }, |
| 4022 | { } /* end */ |
| 4023 | }; |
| 4024 | #endif |
| 4025 | |
| 4026 | /* |
| 4027 | * Pin config fixes |
| 4028 | */ |
| 4029 | enum { |
| 4030 | PINFIX_HP_DC5750, |
| 4031 | }; |
| 4032 | |
| 4033 | static const struct alc_fixup alc260_fixups[] = { |
| 4034 | [PINFIX_HP_DC5750] = { |
| 4035 | .type = ALC_FIXUP_PINS, |
| 4036 | .v.pins = (const struct alc_pincfg[]) { |
| 4037 | { 0x11, 0x90130110 }, /* speaker */ |
| 4038 | { } |
| 4039 | } |
| 4040 | }, |
| 4041 | }; |
| 4042 | |
| 4043 | static const struct snd_pci_quirk alc260_fixup_tbl[] = { |
| 4044 | SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750), |
| 4045 | {} |
| 4046 | }; |
| 4047 | |
| 4048 | /* |
| 4049 | */ |
| 4050 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4051 | #include "alc260_quirks.c" |
| 4052 | #endif |
| 4053 | |
| 4054 | static int patch_alc260(struct hda_codec *codec) |
| 4055 | { |
| 4056 | struct alc_spec *spec; |
| 4057 | int err, board_config; |
| 4058 | |
| 4059 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4060 | if (spec == NULL) |
| 4061 | return -ENOMEM; |
| 4062 | |
| 4063 | codec->spec = spec; |
| 4064 | |
| 4065 | spec->mixer_nid = 0x07; |
| 4066 | |
| 4067 | board_config = alc_board_config(codec, ALC260_MODEL_LAST, |
| 4068 | alc260_models, alc260_cfg_tbl); |
| 4069 | if (board_config < 0) { |
| 4070 | snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 4071 | codec->chip_name); |
| 4072 | board_config = ALC_MODEL_AUTO; |
| 4073 | } |
| 4074 | |
| 4075 | if (board_config == ALC_MODEL_AUTO) { |
| 4076 | alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); |
| 4077 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 4078 | } |
| 4079 | |
| 4080 | if (board_config == ALC_MODEL_AUTO) { |
| 4081 | /* automatic parse from the BIOS config */ |
| 4082 | err = alc260_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4083 | if (err < 0) |
| 4084 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4085 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4086 | else if (!err) { |
| 4087 | printk(KERN_INFO |
| 4088 | "hda_codec: Cannot set up configuration " |
| 4089 | "from BIOS. Using base mode...\n"); |
| 4090 | board_config = ALC260_BASIC; |
| 4091 | } |
| 4092 | #endif |
| 4093 | } |
| 4094 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4095 | if (board_config != ALC_MODEL_AUTO) |
| 4096 | setup_preset(codec, &alc260_presets[board_config]); |
| 4097 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4098 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4099 | alc_auto_fill_adc_caps(codec); |
| 4100 | alc_rebuild_imux_for_auto_mic(codec); |
| 4101 | alc_remove_invalid_adc_nids(codec); |
| 4102 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4103 | |
| 4104 | if (!spec->no_analog && !spec->cap_mixer) |
| 4105 | set_capture_mixer(codec); |
| 4106 | |
| 4107 | if (!spec->no_analog) { |
| 4108 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4109 | if (err < 0) |
| 4110 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4111 | set_beep_amp(spec, 0x07, 0x05, HDA_INPUT); |
| 4112 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4113 | |
| 4114 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4115 | |
| 4116 | spec->vmaster_nid = 0x08; |
| 4117 | |
| 4118 | codec->patch_ops = alc_patch_ops; |
| 4119 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | 8452a98 | 2011-07-08 16:19:48 +0200 | [diff] [blame] | 4120 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4121 | spec->shutup = alc_eapd_shutup; |
| 4122 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4123 | if (!spec->loopback.amplist) |
| 4124 | spec->loopback.amplist = alc260_loopbacks; |
| 4125 | #endif |
| 4126 | |
| 4127 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4128 | |
| 4129 | error: |
| 4130 | alc_free(codec); |
| 4131 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4132 | } |
| 4133 | |
| 4134 | |
| 4135 | /* |
| 4136 | * ALC882/883/885/888/889 support |
| 4137 | * |
| 4138 | * ALC882 is almost identical with ALC880 but has cleaner and more flexible |
| 4139 | * configuration. Each pin widget can choose any input DACs and a mixer. |
| 4140 | * Each ADC is connected from a mixer of all inputs. This makes possible |
| 4141 | * 6-channel independent captures. |
| 4142 | * |
| 4143 | * In addition, an independent DAC for the multi-playback (not used in this |
| 4144 | * driver yet). |
| 4145 | */ |
| 4146 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4147 | #define alc882_loopbacks alc880_loopbacks |
| 4148 | #endif |
| 4149 | |
| 4150 | /* |
| 4151 | * Pin config fixes |
| 4152 | */ |
| 4153 | enum { |
| 4154 | PINFIX_ABIT_AW9D_MAX, |
| 4155 | PINFIX_LENOVO_Y530, |
| 4156 | PINFIX_PB_M5210, |
| 4157 | PINFIX_ACER_ASPIRE_7736, |
Takashi Iwai | 5cdf745 | 2011-10-26 23:04:08 +0200 | [diff] [blame] | 4158 | PINFIX_ASUS_W90V, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4159 | }; |
| 4160 | |
| 4161 | static const struct alc_fixup alc882_fixups[] = { |
| 4162 | [PINFIX_ABIT_AW9D_MAX] = { |
| 4163 | .type = ALC_FIXUP_PINS, |
| 4164 | .v.pins = (const struct alc_pincfg[]) { |
| 4165 | { 0x15, 0x01080104 }, /* side */ |
| 4166 | { 0x16, 0x01011012 }, /* rear */ |
| 4167 | { 0x17, 0x01016011 }, /* clfe */ |
| 4168 | { } |
| 4169 | } |
| 4170 | }, |
| 4171 | [PINFIX_LENOVO_Y530] = { |
| 4172 | .type = ALC_FIXUP_PINS, |
| 4173 | .v.pins = (const struct alc_pincfg[]) { |
| 4174 | { 0x15, 0x99130112 }, /* rear int speakers */ |
| 4175 | { 0x16, 0x99130111 }, /* subwoofer */ |
| 4176 | { } |
| 4177 | } |
| 4178 | }, |
| 4179 | [PINFIX_PB_M5210] = { |
| 4180 | .type = ALC_FIXUP_VERBS, |
| 4181 | .v.verbs = (const struct hda_verb[]) { |
| 4182 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, |
| 4183 | {} |
| 4184 | } |
| 4185 | }, |
| 4186 | [PINFIX_ACER_ASPIRE_7736] = { |
| 4187 | .type = ALC_FIXUP_SKU, |
| 4188 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
| 4189 | }, |
Takashi Iwai | 5cdf745 | 2011-10-26 23:04:08 +0200 | [diff] [blame] | 4190 | [PINFIX_ASUS_W90V] = { |
| 4191 | .type = ALC_FIXUP_PINS, |
| 4192 | .v.pins = (const struct alc_pincfg[]) { |
| 4193 | { 0x16, 0x99130110 }, /* fix sequence for CLFE */ |
| 4194 | { } |
| 4195 | } |
| 4196 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4197 | }; |
| 4198 | |
| 4199 | static const struct snd_pci_quirk alc882_fixup_tbl[] = { |
| 4200 | SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210), |
Takashi Iwai | 5cdf745 | 2011-10-26 23:04:08 +0200 | [diff] [blame] | 4201 | SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", PINFIX_ASUS_W90V), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4202 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530), |
| 4203 | SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX), |
| 4204 | SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736), |
| 4205 | {} |
| 4206 | }; |
| 4207 | |
| 4208 | /* |
| 4209 | * BIOS auto configuration |
| 4210 | */ |
| 4211 | /* almost identical with ALC880 parser... */ |
| 4212 | static int alc882_parse_auto_config(struct hda_codec *codec) |
| 4213 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4214 | static const hda_nid_t alc882_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4215 | static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 4216 | return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4217 | } |
| 4218 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4219 | /* |
| 4220 | */ |
| 4221 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4222 | #include "alc882_quirks.c" |
| 4223 | #endif |
| 4224 | |
| 4225 | static int patch_alc882(struct hda_codec *codec) |
| 4226 | { |
| 4227 | struct alc_spec *spec; |
| 4228 | int err, board_config; |
| 4229 | |
| 4230 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4231 | if (spec == NULL) |
| 4232 | return -ENOMEM; |
| 4233 | |
| 4234 | codec->spec = spec; |
| 4235 | |
| 4236 | spec->mixer_nid = 0x0b; |
| 4237 | |
| 4238 | switch (codec->vendor_id) { |
| 4239 | case 0x10ec0882: |
| 4240 | case 0x10ec0885: |
| 4241 | break; |
| 4242 | default: |
| 4243 | /* ALC883 and variants */ |
| 4244 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); |
| 4245 | break; |
| 4246 | } |
| 4247 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4248 | err = alc_codec_rename_from_preset(codec); |
| 4249 | if (err < 0) |
| 4250 | goto error; |
| 4251 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4252 | board_config = alc_board_config(codec, ALC882_MODEL_LAST, |
| 4253 | alc882_models, alc882_cfg_tbl); |
| 4254 | |
| 4255 | if (board_config < 0) |
| 4256 | board_config = alc_board_codec_sid_config(codec, |
| 4257 | ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl); |
| 4258 | |
| 4259 | if (board_config < 0) { |
| 4260 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 4261 | codec->chip_name); |
| 4262 | board_config = ALC_MODEL_AUTO; |
| 4263 | } |
| 4264 | |
| 4265 | if (board_config == ALC_MODEL_AUTO) { |
| 4266 | alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups); |
| 4267 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 4268 | } |
| 4269 | |
| 4270 | alc_auto_parse_customize_define(codec); |
| 4271 | |
| 4272 | if (board_config == ALC_MODEL_AUTO) { |
| 4273 | /* automatic parse from the BIOS config */ |
| 4274 | err = alc882_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4275 | if (err < 0) |
| 4276 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4277 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4278 | else if (!err) { |
| 4279 | printk(KERN_INFO |
| 4280 | "hda_codec: Cannot set up configuration " |
| 4281 | "from BIOS. Using base mode...\n"); |
| 4282 | board_config = ALC882_3ST_DIG; |
| 4283 | } |
| 4284 | #endif |
| 4285 | } |
| 4286 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4287 | if (board_config != ALC_MODEL_AUTO) |
| 4288 | setup_preset(codec, &alc882_presets[board_config]); |
| 4289 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4290 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4291 | alc_auto_fill_adc_caps(codec); |
| 4292 | alc_rebuild_imux_for_auto_mic(codec); |
| 4293 | alc_remove_invalid_adc_nids(codec); |
| 4294 | } |
| 4295 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4296 | if (!spec->no_analog && !spec->cap_mixer) |
| 4297 | set_capture_mixer(codec); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4298 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4299 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 4300 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4301 | if (err < 0) |
| 4302 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4303 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4304 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4305 | |
| 4306 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4307 | |
| 4308 | spec->vmaster_nid = 0x0c; |
| 4309 | |
| 4310 | codec->patch_ops = alc_patch_ops; |
| 4311 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 4312 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4313 | |
| 4314 | alc_init_jacks(codec); |
| 4315 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4316 | if (!spec->loopback.amplist) |
| 4317 | spec->loopback.amplist = alc882_loopbacks; |
| 4318 | #endif |
| 4319 | |
| 4320 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4321 | |
| 4322 | error: |
| 4323 | alc_free(codec); |
| 4324 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4325 | } |
| 4326 | |
| 4327 | |
| 4328 | /* |
| 4329 | * ALC262 support |
| 4330 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4331 | static int alc262_parse_auto_config(struct hda_codec *codec) |
| 4332 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4333 | static const hda_nid_t alc262_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4334 | static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 4335 | return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4336 | } |
| 4337 | |
| 4338 | /* |
| 4339 | * Pin config fixes |
| 4340 | */ |
| 4341 | enum { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4342 | ALC262_FIXUP_FSC_H270, |
| 4343 | ALC262_FIXUP_HP_Z200, |
| 4344 | ALC262_FIXUP_TYAN, |
Takashi Iwai | 12837c9 | 2011-11-07 12:45:24 +0100 | [diff] [blame] | 4345 | ALC262_FIXUP_TOSHIBA_RX1, |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 4346 | ALC262_FIXUP_LENOVO_3000, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame^] | 4347 | ALC262_FIXUP_BENQ, |
| 4348 | ALC262_FIXUP_BENQ_T31, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4349 | }; |
| 4350 | |
| 4351 | static const struct alc_fixup alc262_fixups[] = { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4352 | [ALC262_FIXUP_FSC_H270] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4353 | .type = ALC_FIXUP_PINS, |
| 4354 | .v.pins = (const struct alc_pincfg[]) { |
| 4355 | { 0x14, 0x99130110 }, /* speaker */ |
| 4356 | { 0x15, 0x0221142f }, /* front HP */ |
| 4357 | { 0x1b, 0x0121141f }, /* rear HP */ |
| 4358 | { } |
| 4359 | } |
| 4360 | }, |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4361 | [ALC262_FIXUP_HP_Z200] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4362 | .type = ALC_FIXUP_PINS, |
| 4363 | .v.pins = (const struct alc_pincfg[]) { |
| 4364 | { 0x16, 0x99130120 }, /* internal speaker */ |
| 4365 | { } |
| 4366 | } |
| 4367 | }, |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4368 | [ALC262_FIXUP_TYAN] = { |
| 4369 | .type = ALC_FIXUP_PINS, |
| 4370 | .v.pins = (const struct alc_pincfg[]) { |
| 4371 | { 0x14, 0x1993e1f0 }, /* int AUX */ |
| 4372 | { } |
| 4373 | } |
| 4374 | }, |
Takashi Iwai | 12837c9 | 2011-11-07 12:45:24 +0100 | [diff] [blame] | 4375 | [ALC262_FIXUP_TOSHIBA_RX1] = { |
| 4376 | .type = ALC_FIXUP_PINS, |
| 4377 | .v.pins = (const struct alc_pincfg[]) { |
| 4378 | { 0x14, 0x90170110 }, /* speaker */ |
| 4379 | { 0x15, 0x0421101f }, /* HP */ |
| 4380 | { 0x1a, 0x40f000f0 }, /* N/A */ |
| 4381 | { 0x1b, 0x40f000f0 }, /* N/A */ |
| 4382 | { 0x1e, 0x40f000f0 }, /* N/A */ |
| 4383 | } |
| 4384 | }, |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 4385 | [ALC262_FIXUP_LENOVO_3000] = { |
| 4386 | .type = ALC_FIXUP_VERBS, |
| 4387 | .v.verbs = (const struct hda_verb[]) { |
| 4388 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame^] | 4389 | {} |
| 4390 | }, |
| 4391 | .chained = true, |
| 4392 | .chain_id = ALC262_FIXUP_BENQ, |
| 4393 | }, |
| 4394 | [ALC262_FIXUP_BENQ] = { |
| 4395 | .type = ALC_FIXUP_VERBS, |
| 4396 | .v.verbs = (const struct hda_verb[]) { |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 4397 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4398 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, |
| 4399 | {} |
| 4400 | } |
| 4401 | }, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame^] | 4402 | [ALC262_FIXUP_BENQ_T31] = { |
| 4403 | .type = ALC_FIXUP_VERBS, |
| 4404 | .v.verbs = (const struct hda_verb[]) { |
| 4405 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4406 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, |
| 4407 | {} |
| 4408 | } |
| 4409 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4410 | }; |
| 4411 | |
| 4412 | static const struct snd_pci_quirk alc262_fixup_tbl[] = { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4413 | SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200), |
| 4414 | SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN), |
Takashi Iwai | 12837c9 | 2011-11-07 12:45:24 +0100 | [diff] [blame] | 4415 | SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1", |
| 4416 | ALC262_FIXUP_TOSHIBA_RX1), |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4417 | SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270), |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 4418 | SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000), |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame^] | 4419 | SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ), |
| 4420 | SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4421 | {} |
| 4422 | }; |
| 4423 | |
| 4424 | |
| 4425 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4426 | #define alc262_loopbacks alc880_loopbacks |
| 4427 | #endif |
| 4428 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4429 | /* |
| 4430 | */ |
| 4431 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4432 | #include "alc262_quirks.c" |
| 4433 | #endif |
| 4434 | |
| 4435 | static int patch_alc262(struct hda_codec *codec) |
| 4436 | { |
| 4437 | struct alc_spec *spec; |
| 4438 | int board_config; |
| 4439 | int err; |
| 4440 | |
| 4441 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4442 | if (spec == NULL) |
| 4443 | return -ENOMEM; |
| 4444 | |
| 4445 | codec->spec = spec; |
| 4446 | |
| 4447 | spec->mixer_nid = 0x0b; |
| 4448 | |
| 4449 | #if 0 |
| 4450 | /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is |
| 4451 | * under-run |
| 4452 | */ |
| 4453 | { |
| 4454 | int tmp; |
| 4455 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 4456 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 4457 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 4458 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80); |
| 4459 | } |
| 4460 | #endif |
| 4461 | alc_auto_parse_customize_define(codec); |
| 4462 | |
| 4463 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); |
| 4464 | |
| 4465 | board_config = alc_board_config(codec, ALC262_MODEL_LAST, |
| 4466 | alc262_models, alc262_cfg_tbl); |
| 4467 | |
| 4468 | if (board_config < 0) { |
| 4469 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 4470 | codec->chip_name); |
| 4471 | board_config = ALC_MODEL_AUTO; |
| 4472 | } |
| 4473 | |
| 4474 | if (board_config == ALC_MODEL_AUTO) { |
| 4475 | alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups); |
| 4476 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 4477 | } |
| 4478 | |
| 4479 | if (board_config == ALC_MODEL_AUTO) { |
| 4480 | /* automatic parse from the BIOS config */ |
| 4481 | err = alc262_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4482 | if (err < 0) |
| 4483 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4484 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4485 | else if (!err) { |
| 4486 | printk(KERN_INFO |
| 4487 | "hda_codec: Cannot set up configuration " |
| 4488 | "from BIOS. Using base mode...\n"); |
| 4489 | board_config = ALC262_BASIC; |
| 4490 | } |
| 4491 | #endif |
| 4492 | } |
| 4493 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4494 | if (board_config != ALC_MODEL_AUTO) |
| 4495 | setup_preset(codec, &alc262_presets[board_config]); |
| 4496 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4497 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4498 | alc_auto_fill_adc_caps(codec); |
| 4499 | alc_rebuild_imux_for_auto_mic(codec); |
| 4500 | alc_remove_invalid_adc_nids(codec); |
| 4501 | } |
| 4502 | |
| 4503 | if (!spec->no_analog && !spec->cap_mixer) |
| 4504 | set_capture_mixer(codec); |
| 4505 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4506 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 4507 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4508 | if (err < 0) |
| 4509 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4510 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4511 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4512 | |
| 4513 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4514 | |
| 4515 | spec->vmaster_nid = 0x0c; |
| 4516 | |
| 4517 | codec->patch_ops = alc_patch_ops; |
| 4518 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 4519 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4520 | spec->shutup = alc_eapd_shutup; |
| 4521 | |
| 4522 | alc_init_jacks(codec); |
| 4523 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4524 | if (!spec->loopback.amplist) |
| 4525 | spec->loopback.amplist = alc262_loopbacks; |
| 4526 | #endif |
| 4527 | |
| 4528 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4529 | |
| 4530 | error: |
| 4531 | alc_free(codec); |
| 4532 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | /* |
| 4536 | * ALC268 |
| 4537 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4538 | /* bind Beep switches of both NID 0x0f and 0x10 */ |
| 4539 | static const struct hda_bind_ctls alc268_bind_beep_sw = { |
| 4540 | .ops = &snd_hda_bind_sw, |
| 4541 | .values = { |
| 4542 | HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT), |
| 4543 | HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT), |
| 4544 | 0 |
| 4545 | }, |
| 4546 | }; |
| 4547 | |
| 4548 | static const struct snd_kcontrol_new alc268_beep_mixer[] = { |
| 4549 | HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT), |
| 4550 | HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw), |
| 4551 | { } |
| 4552 | }; |
| 4553 | |
| 4554 | /* set PCBEEP vol = 0, mute connections */ |
| 4555 | static const struct hda_verb alc268_beep_init_verbs[] = { |
| 4556 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4557 | {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4558 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4559 | { } |
| 4560 | }; |
| 4561 | |
| 4562 | /* |
| 4563 | * BIOS auto configuration |
| 4564 | */ |
| 4565 | static int alc268_parse_auto_config(struct hda_codec *codec) |
| 4566 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4567 | static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4568 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4569 | int err = alc_parse_auto_config(codec, NULL, alc268_ssids); |
| 4570 | if (err > 0) { |
| 4571 | if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { |
| 4572 | add_mixer(spec, alc268_beep_mixer); |
| 4573 | add_verb(spec, alc268_beep_init_verbs); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4574 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4575 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4576 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4577 | } |
| 4578 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4579 | /* |
| 4580 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4581 | static int patch_alc268(struct hda_codec *codec) |
| 4582 | { |
| 4583 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4584 | int i, has_beep, err; |
| 4585 | |
| 4586 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4587 | if (spec == NULL) |
| 4588 | return -ENOMEM; |
| 4589 | |
| 4590 | codec->spec = spec; |
| 4591 | |
| 4592 | /* ALC268 has no aa-loopback mixer */ |
| 4593 | |
Takashi Iwai | 6ebb805 | 2011-08-16 15:15:40 +0200 | [diff] [blame] | 4594 | /* automatic parse from the BIOS config */ |
| 4595 | err = alc268_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4596 | if (err < 0) |
| 4597 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4598 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4599 | has_beep = 0; |
| 4600 | for (i = 0; i < spec->num_mixers; i++) { |
| 4601 | if (spec->mixers[i] == alc268_beep_mixer) { |
| 4602 | has_beep = 1; |
| 4603 | break; |
| 4604 | } |
| 4605 | } |
| 4606 | |
| 4607 | if (has_beep) { |
| 4608 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4609 | if (err < 0) |
| 4610 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4611 | if (!query_amp_caps(codec, 0x1d, HDA_INPUT)) |
| 4612 | /* override the amp caps for beep generator */ |
| 4613 | snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT, |
| 4614 | (0x0c << AC_AMPCAP_OFFSET_SHIFT) | |
| 4615 | (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 4616 | (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 4617 | (0 << AC_AMPCAP_MUTE_SHIFT)); |
| 4618 | } |
| 4619 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4620 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4621 | alc_auto_fill_adc_caps(codec); |
| 4622 | alc_rebuild_imux_for_auto_mic(codec); |
| 4623 | alc_remove_invalid_adc_nids(codec); |
| 4624 | } |
| 4625 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4626 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4627 | set_capture_mixer(codec); |
| 4628 | |
| 4629 | spec->vmaster_nid = 0x02; |
| 4630 | |
| 4631 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 6ebb805 | 2011-08-16 15:15:40 +0200 | [diff] [blame] | 4632 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4633 | spec->shutup = alc_eapd_shutup; |
| 4634 | |
| 4635 | alc_init_jacks(codec); |
| 4636 | |
| 4637 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4638 | |
| 4639 | error: |
| 4640 | alc_free(codec); |
| 4641 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4642 | } |
| 4643 | |
| 4644 | /* |
| 4645 | * ALC269 |
| 4646 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4647 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4648 | #define alc269_loopbacks alc880_loopbacks |
| 4649 | #endif |
| 4650 | |
| 4651 | static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { |
| 4652 | .substreams = 1, |
| 4653 | .channels_min = 2, |
| 4654 | .channels_max = 8, |
| 4655 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
| 4656 | /* NID is set in alc_build_pcms */ |
| 4657 | .ops = { |
| 4658 | .open = alc_playback_pcm_open, |
| 4659 | .prepare = alc_playback_pcm_prepare, |
| 4660 | .cleanup = alc_playback_pcm_cleanup |
| 4661 | }, |
| 4662 | }; |
| 4663 | |
| 4664 | static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { |
| 4665 | .substreams = 1, |
| 4666 | .channels_min = 2, |
| 4667 | .channels_max = 2, |
| 4668 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
| 4669 | /* NID is set in alc_build_pcms */ |
| 4670 | }; |
| 4671 | |
| 4672 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4673 | static int alc269_mic2_for_mute_led(struct hda_codec *codec) |
| 4674 | { |
| 4675 | switch (codec->subsystem_id) { |
| 4676 | case 0x103c1586: |
| 4677 | return 1; |
| 4678 | } |
| 4679 | return 0; |
| 4680 | } |
| 4681 | |
| 4682 | static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid) |
| 4683 | { |
| 4684 | /* update mute-LED according to the speaker mute state */ |
| 4685 | if (nid == 0x01 || nid == 0x14) { |
| 4686 | int pinval; |
| 4687 | if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) & |
| 4688 | HDA_AMP_MUTE) |
| 4689 | pinval = 0x24; |
| 4690 | else |
| 4691 | pinval = 0x20; |
| 4692 | /* mic2 vref pin is used for mute LED control */ |
| 4693 | snd_hda_codec_update_cache(codec, 0x19, 0, |
| 4694 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 4695 | pinval); |
| 4696 | } |
| 4697 | return alc_check_power_status(codec, nid); |
| 4698 | } |
| 4699 | #endif /* CONFIG_SND_HDA_POWER_SAVE */ |
| 4700 | |
| 4701 | /* different alc269-variants */ |
| 4702 | enum { |
| 4703 | ALC269_TYPE_ALC269VA, |
| 4704 | ALC269_TYPE_ALC269VB, |
| 4705 | ALC269_TYPE_ALC269VC, |
| 4706 | }; |
| 4707 | |
| 4708 | /* |
| 4709 | * BIOS auto configuration |
| 4710 | */ |
| 4711 | static int alc269_parse_auto_config(struct hda_codec *codec) |
| 4712 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4713 | static const hda_nid_t alc269_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4714 | static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 }; |
| 4715 | static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 4716 | struct alc_spec *spec = codec->spec; |
| 4717 | const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ? |
| 4718 | alc269va_ssids : alc269_ssids; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4719 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4720 | return alc_parse_auto_config(codec, alc269_ignore, ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4721 | } |
| 4722 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4723 | static void alc269_toggle_power_output(struct hda_codec *codec, int power_up) |
| 4724 | { |
| 4725 | int val = alc_read_coef_idx(codec, 0x04); |
| 4726 | if (power_up) |
| 4727 | val |= 1 << 11; |
| 4728 | else |
| 4729 | val &= ~(1 << 11); |
| 4730 | alc_write_coef_idx(codec, 0x04, val); |
| 4731 | } |
| 4732 | |
| 4733 | static void alc269_shutup(struct hda_codec *codec) |
| 4734 | { |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 4735 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4736 | alc269_toggle_power_output(codec, 0); |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 4737 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4738 | alc269_toggle_power_output(codec, 0); |
| 4739 | msleep(150); |
| 4740 | } |
| 4741 | } |
| 4742 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 4743 | #ifdef CONFIG_PM |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4744 | static int alc269_resume(struct hda_codec *codec) |
| 4745 | { |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 4746 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4747 | alc269_toggle_power_output(codec, 0); |
| 4748 | msleep(150); |
| 4749 | } |
| 4750 | |
| 4751 | codec->patch_ops.init(codec); |
| 4752 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 4753 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4754 | alc269_toggle_power_output(codec, 1); |
| 4755 | msleep(200); |
| 4756 | } |
| 4757 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 4758 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4759 | alc269_toggle_power_output(codec, 1); |
| 4760 | |
| 4761 | snd_hda_codec_resume_amp(codec); |
| 4762 | snd_hda_codec_resume_cache(codec); |
| 4763 | hda_call_check_power_status(codec, 0x01); |
| 4764 | return 0; |
| 4765 | } |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 4766 | #endif /* CONFIG_PM */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4767 | |
| 4768 | static void alc269_fixup_hweq(struct hda_codec *codec, |
| 4769 | const struct alc_fixup *fix, int action) |
| 4770 | { |
| 4771 | int coef; |
| 4772 | |
| 4773 | if (action != ALC_FIXUP_ACT_INIT) |
| 4774 | return; |
| 4775 | coef = alc_read_coef_idx(codec, 0x1e); |
| 4776 | alc_write_coef_idx(codec, 0x1e, coef | 0x80); |
| 4777 | } |
| 4778 | |
| 4779 | static void alc271_fixup_dmic(struct hda_codec *codec, |
| 4780 | const struct alc_fixup *fix, int action) |
| 4781 | { |
| 4782 | static const struct hda_verb verbs[] = { |
| 4783 | {0x20, AC_VERB_SET_COEF_INDEX, 0x0d}, |
| 4784 | {0x20, AC_VERB_SET_PROC_COEF, 0x4000}, |
| 4785 | {} |
| 4786 | }; |
| 4787 | unsigned int cfg; |
| 4788 | |
| 4789 | if (strcmp(codec->chip_name, "ALC271X")) |
| 4790 | return; |
| 4791 | cfg = snd_hda_codec_get_pincfg(codec, 0x12); |
| 4792 | if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED) |
| 4793 | snd_hda_sequence_write(codec, verbs); |
| 4794 | } |
| 4795 | |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 4796 | static void alc269_fixup_pcm_44k(struct hda_codec *codec, |
| 4797 | const struct alc_fixup *fix, int action) |
| 4798 | { |
| 4799 | struct alc_spec *spec = codec->spec; |
| 4800 | |
| 4801 | if (action != ALC_FIXUP_ACT_PROBE) |
| 4802 | return; |
| 4803 | |
| 4804 | /* Due to a hardware problem on Lenovo Ideadpad, we need to |
| 4805 | * fix the sample rate of analog I/O to 44.1kHz |
| 4806 | */ |
| 4807 | spec->stream_analog_playback = &alc269_44k_pcm_analog_playback; |
| 4808 | spec->stream_analog_capture = &alc269_44k_pcm_analog_capture; |
| 4809 | } |
| 4810 | |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 4811 | static void alc269_fixup_stereo_dmic(struct hda_codec *codec, |
| 4812 | const struct alc_fixup *fix, int action) |
| 4813 | { |
| 4814 | int coef; |
| 4815 | |
| 4816 | if (action != ALC_FIXUP_ACT_INIT) |
| 4817 | return; |
| 4818 | /* The digital-mic unit sends PDM (differential signal) instead of |
| 4819 | * the standard PCM, thus you can't record a valid mono stream as is. |
| 4820 | * Below is a workaround specific to ALC269 to control the dmic |
| 4821 | * signal source as mono. |
| 4822 | */ |
| 4823 | coef = alc_read_coef_idx(codec, 0x07); |
| 4824 | alc_write_coef_idx(codec, 0x07, coef | 0x80); |
| 4825 | } |
| 4826 | |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 4827 | static void alc269_quanta_automute(struct hda_codec *codec) |
| 4828 | { |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 4829 | update_outputs(codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 4830 | |
| 4831 | snd_hda_codec_write(codec, 0x20, 0, |
| 4832 | AC_VERB_SET_COEF_INDEX, 0x0c); |
| 4833 | snd_hda_codec_write(codec, 0x20, 0, |
| 4834 | AC_VERB_SET_PROC_COEF, 0x680); |
| 4835 | |
| 4836 | snd_hda_codec_write(codec, 0x20, 0, |
| 4837 | AC_VERB_SET_COEF_INDEX, 0x0c); |
| 4838 | snd_hda_codec_write(codec, 0x20, 0, |
| 4839 | AC_VERB_SET_PROC_COEF, 0x480); |
| 4840 | } |
| 4841 | |
| 4842 | static void alc269_fixup_quanta_mute(struct hda_codec *codec, |
| 4843 | const struct alc_fixup *fix, int action) |
| 4844 | { |
| 4845 | struct alc_spec *spec = codec->spec; |
| 4846 | if (action != ALC_FIXUP_ACT_PROBE) |
| 4847 | return; |
| 4848 | spec->automute_hook = alc269_quanta_automute; |
| 4849 | } |
| 4850 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4851 | enum { |
| 4852 | ALC269_FIXUP_SONY_VAIO, |
| 4853 | ALC275_FIXUP_SONY_VAIO_GPIO2, |
| 4854 | ALC269_FIXUP_DELL_M101Z, |
| 4855 | ALC269_FIXUP_SKU_IGNORE, |
| 4856 | ALC269_FIXUP_ASUS_G73JW, |
| 4857 | ALC269_FIXUP_LENOVO_EAPD, |
| 4858 | ALC275_FIXUP_SONY_HWEQ, |
| 4859 | ALC271_FIXUP_DMIC, |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 4860 | ALC269_FIXUP_PCM_44K, |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 4861 | ALC269_FIXUP_STEREO_DMIC, |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 4862 | ALC269_FIXUP_QUANTA_MUTE, |
| 4863 | ALC269_FIXUP_LIFEBOOK, |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 4864 | ALC269_FIXUP_AMIC, |
| 4865 | ALC269_FIXUP_DMIC, |
| 4866 | ALC269VB_FIXUP_AMIC, |
| 4867 | ALC269VB_FIXUP_DMIC, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4868 | }; |
| 4869 | |
| 4870 | static const struct alc_fixup alc269_fixups[] = { |
| 4871 | [ALC269_FIXUP_SONY_VAIO] = { |
| 4872 | .type = ALC_FIXUP_VERBS, |
| 4873 | .v.verbs = (const struct hda_verb[]) { |
| 4874 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD}, |
| 4875 | {} |
| 4876 | } |
| 4877 | }, |
| 4878 | [ALC275_FIXUP_SONY_VAIO_GPIO2] = { |
| 4879 | .type = ALC_FIXUP_VERBS, |
| 4880 | .v.verbs = (const struct hda_verb[]) { |
| 4881 | {0x01, AC_VERB_SET_GPIO_MASK, 0x04}, |
| 4882 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04}, |
| 4883 | {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, |
| 4884 | { } |
| 4885 | }, |
| 4886 | .chained = true, |
| 4887 | .chain_id = ALC269_FIXUP_SONY_VAIO |
| 4888 | }, |
| 4889 | [ALC269_FIXUP_DELL_M101Z] = { |
| 4890 | .type = ALC_FIXUP_VERBS, |
| 4891 | .v.verbs = (const struct hda_verb[]) { |
| 4892 | /* Enables internal speaker */ |
| 4893 | {0x20, AC_VERB_SET_COEF_INDEX, 13}, |
| 4894 | {0x20, AC_VERB_SET_PROC_COEF, 0x4040}, |
| 4895 | {} |
| 4896 | } |
| 4897 | }, |
| 4898 | [ALC269_FIXUP_SKU_IGNORE] = { |
| 4899 | .type = ALC_FIXUP_SKU, |
| 4900 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
| 4901 | }, |
| 4902 | [ALC269_FIXUP_ASUS_G73JW] = { |
| 4903 | .type = ALC_FIXUP_PINS, |
| 4904 | .v.pins = (const struct alc_pincfg[]) { |
| 4905 | { 0x17, 0x99130111 }, /* subwoofer */ |
| 4906 | { } |
| 4907 | } |
| 4908 | }, |
| 4909 | [ALC269_FIXUP_LENOVO_EAPD] = { |
| 4910 | .type = ALC_FIXUP_VERBS, |
| 4911 | .v.verbs = (const struct hda_verb[]) { |
| 4912 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, |
| 4913 | {} |
| 4914 | } |
| 4915 | }, |
| 4916 | [ALC275_FIXUP_SONY_HWEQ] = { |
| 4917 | .type = ALC_FIXUP_FUNC, |
| 4918 | .v.func = alc269_fixup_hweq, |
| 4919 | .chained = true, |
| 4920 | .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2 |
| 4921 | }, |
| 4922 | [ALC271_FIXUP_DMIC] = { |
| 4923 | .type = ALC_FIXUP_FUNC, |
| 4924 | .v.func = alc271_fixup_dmic, |
| 4925 | }, |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 4926 | [ALC269_FIXUP_PCM_44K] = { |
| 4927 | .type = ALC_FIXUP_FUNC, |
| 4928 | .v.func = alc269_fixup_pcm_44k, |
| 4929 | }, |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 4930 | [ALC269_FIXUP_STEREO_DMIC] = { |
| 4931 | .type = ALC_FIXUP_FUNC, |
| 4932 | .v.func = alc269_fixup_stereo_dmic, |
| 4933 | }, |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 4934 | [ALC269_FIXUP_QUANTA_MUTE] = { |
| 4935 | .type = ALC_FIXUP_FUNC, |
| 4936 | .v.func = alc269_fixup_quanta_mute, |
| 4937 | }, |
| 4938 | [ALC269_FIXUP_LIFEBOOK] = { |
| 4939 | .type = ALC_FIXUP_PINS, |
| 4940 | .v.pins = (const struct alc_pincfg[]) { |
| 4941 | { 0x1a, 0x2101103f }, /* dock line-out */ |
| 4942 | { 0x1b, 0x23a11040 }, /* dock mic-in */ |
| 4943 | { } |
| 4944 | }, |
| 4945 | .chained = true, |
| 4946 | .chain_id = ALC269_FIXUP_QUANTA_MUTE |
| 4947 | }, |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 4948 | [ALC269_FIXUP_AMIC] = { |
| 4949 | .type = ALC_FIXUP_PINS, |
| 4950 | .v.pins = (const struct alc_pincfg[]) { |
| 4951 | { 0x14, 0x99130110 }, /* speaker */ |
| 4952 | { 0x15, 0x0121401f }, /* HP out */ |
| 4953 | { 0x18, 0x01a19c20 }, /* mic */ |
| 4954 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 4955 | { } |
| 4956 | }, |
| 4957 | }, |
| 4958 | [ALC269_FIXUP_DMIC] = { |
| 4959 | .type = ALC_FIXUP_PINS, |
| 4960 | .v.pins = (const struct alc_pincfg[]) { |
| 4961 | { 0x12, 0x99a3092f }, /* int-mic */ |
| 4962 | { 0x14, 0x99130110 }, /* speaker */ |
| 4963 | { 0x15, 0x0121401f }, /* HP out */ |
| 4964 | { 0x18, 0x01a19c20 }, /* mic */ |
| 4965 | { } |
| 4966 | }, |
| 4967 | }, |
| 4968 | [ALC269VB_FIXUP_AMIC] = { |
| 4969 | .type = ALC_FIXUP_PINS, |
| 4970 | .v.pins = (const struct alc_pincfg[]) { |
| 4971 | { 0x14, 0x99130110 }, /* speaker */ |
| 4972 | { 0x18, 0x01a19c20 }, /* mic */ |
| 4973 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 4974 | { 0x21, 0x0121401f }, /* HP out */ |
| 4975 | { } |
| 4976 | }, |
| 4977 | }, |
| 4978 | [ALC269_FIXUP_DMIC] = { |
| 4979 | .type = ALC_FIXUP_PINS, |
| 4980 | .v.pins = (const struct alc_pincfg[]) { |
| 4981 | { 0x12, 0x99a3092f }, /* int-mic */ |
| 4982 | { 0x14, 0x99130110 }, /* speaker */ |
| 4983 | { 0x18, 0x01a19c20 }, /* mic */ |
| 4984 | { 0x21, 0x0121401f }, /* HP out */ |
| 4985 | { } |
| 4986 | }, |
| 4987 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4988 | }; |
| 4989 | |
| 4990 | static const struct snd_pci_quirk alc269_fixup_tbl[] = { |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 4991 | SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW), |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 4992 | SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC), |
| 4993 | SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC), |
| 4994 | SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC), |
| 4995 | SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), |
| 4996 | SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4997 | SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2), |
| 4998 | SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), |
| 4999 | SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), |
| 5000 | SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO), |
| 5001 | SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z), |
| 5002 | SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC), |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5003 | SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5004 | SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE), |
| 5005 | SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE), |
| 5006 | SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE), |
| 5007 | SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE), |
| 5008 | SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE), |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5009 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE), |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 5010 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5011 | SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD), |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5012 | |
| 5013 | #if 1 |
| 5014 | /* Below is a quirk table taken from the old code. |
| 5015 | * Basically the device should work as is without the fixup table. |
| 5016 | * If BIOS doesn't give a proper info, enable the corresponding |
| 5017 | * fixup entry. |
| 5018 | */ |
| 5019 | SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A", |
| 5020 | ALC269_FIXUP_AMIC), |
| 5021 | SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC), |
| 5022 | SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC), |
| 5023 | SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC), |
| 5024 | SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC), |
| 5025 | SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC), |
| 5026 | SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC), |
| 5027 | SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC), |
| 5028 | SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC), |
| 5029 | SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC), |
| 5030 | SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC), |
| 5031 | SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC), |
| 5032 | SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC), |
| 5033 | SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC), |
| 5034 | SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC), |
| 5035 | SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC), |
| 5036 | SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC), |
| 5037 | SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC), |
| 5038 | SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC), |
| 5039 | SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC), |
| 5040 | SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC), |
| 5041 | SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC), |
| 5042 | SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC), |
| 5043 | SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC), |
| 5044 | SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC), |
| 5045 | SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC), |
| 5046 | SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC), |
| 5047 | SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC), |
| 5048 | SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC), |
| 5049 | SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC), |
| 5050 | SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC), |
| 5051 | SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC), |
| 5052 | SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC), |
| 5053 | SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC), |
| 5054 | SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC), |
| 5055 | SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC), |
| 5056 | SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC), |
| 5057 | SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC), |
| 5058 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC), |
| 5059 | SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC), |
| 5060 | SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC), |
| 5061 | #endif |
| 5062 | {} |
| 5063 | }; |
| 5064 | |
| 5065 | static const struct alc_model_fixup alc269_fixup_models[] = { |
| 5066 | {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"}, |
| 5067 | {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"}, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5068 | {} |
| 5069 | }; |
| 5070 | |
| 5071 | |
| 5072 | static int alc269_fill_coef(struct hda_codec *codec) |
| 5073 | { |
| 5074 | int val; |
| 5075 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5076 | if ((alc_get_coef0(codec) & 0x00ff) < 0x015) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5077 | alc_write_coef_idx(codec, 0xf, 0x960b); |
| 5078 | alc_write_coef_idx(codec, 0xe, 0x8817); |
| 5079 | } |
| 5080 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5081 | if ((alc_get_coef0(codec) & 0x00ff) == 0x016) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5082 | alc_write_coef_idx(codec, 0xf, 0x960b); |
| 5083 | alc_write_coef_idx(codec, 0xe, 0x8814); |
| 5084 | } |
| 5085 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5086 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5087 | val = alc_read_coef_idx(codec, 0x04); |
| 5088 | /* Power up output pin */ |
| 5089 | alc_write_coef_idx(codec, 0x04, val | (1<<11)); |
| 5090 | } |
| 5091 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5092 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5093 | val = alc_read_coef_idx(codec, 0xd); |
| 5094 | if ((val & 0x0c00) >> 10 != 0x1) { |
| 5095 | /* Capless ramp up clock control */ |
| 5096 | alc_write_coef_idx(codec, 0xd, val | (1<<10)); |
| 5097 | } |
| 5098 | val = alc_read_coef_idx(codec, 0x17); |
| 5099 | if ((val & 0x01c0) >> 6 != 0x4) { |
| 5100 | /* Class D power on reset */ |
| 5101 | alc_write_coef_idx(codec, 0x17, val | (1<<7)); |
| 5102 | } |
| 5103 | } |
| 5104 | |
| 5105 | val = alc_read_coef_idx(codec, 0xd); /* Class D */ |
| 5106 | alc_write_coef_idx(codec, 0xd, val | (1<<14)); |
| 5107 | |
| 5108 | val = alc_read_coef_idx(codec, 0x4); /* HP */ |
| 5109 | alc_write_coef_idx(codec, 0x4, val | (1<<11)); |
| 5110 | |
| 5111 | return 0; |
| 5112 | } |
| 5113 | |
| 5114 | /* |
| 5115 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5116 | static int patch_alc269(struct hda_codec *codec) |
| 5117 | { |
| 5118 | struct alc_spec *spec; |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5119 | int err = 0; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5120 | |
| 5121 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5122 | if (spec == NULL) |
| 5123 | return -ENOMEM; |
| 5124 | |
| 5125 | codec->spec = spec; |
| 5126 | |
| 5127 | spec->mixer_nid = 0x0b; |
| 5128 | |
| 5129 | alc_auto_parse_customize_define(codec); |
| 5130 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5131 | err = alc_codec_rename_from_preset(codec); |
| 5132 | if (err < 0) |
| 5133 | goto error; |
| 5134 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5135 | if (codec->vendor_id == 0x10ec0269) { |
| 5136 | spec->codec_variant = ALC269_TYPE_ALC269VA; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5137 | switch (alc_get_coef0(codec) & 0x00f0) { |
| 5138 | case 0x0010: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5139 | if (codec->bus->pci->subsystem_vendor == 0x1025 && |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5140 | spec->cdefine.platform_type == 1) |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5141 | err = alc_codec_rename(codec, "ALC271X"); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5142 | spec->codec_variant = ALC269_TYPE_ALC269VB; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5143 | break; |
| 5144 | case 0x0020: |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5145 | if (codec->bus->pci->subsystem_vendor == 0x17aa && |
| 5146 | codec->bus->pci->subsystem_device == 0x21f3) |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5147 | err = alc_codec_rename(codec, "ALC3202"); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5148 | spec->codec_variant = ALC269_TYPE_ALC269VC; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5149 | break; |
| 5150 | default: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5151 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5152 | } |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5153 | if (err < 0) |
| 5154 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5155 | alc269_fill_coef(codec); |
| 5156 | } |
| 5157 | |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5158 | alc_pick_fixup(codec, alc269_fixup_models, |
| 5159 | alc269_fixup_tbl, alc269_fixups); |
| 5160 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5161 | |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5162 | /* automatic parse from the BIOS config */ |
| 5163 | err = alc269_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5164 | if (err < 0) |
| 5165 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5166 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5167 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5168 | alc_auto_fill_adc_caps(codec); |
| 5169 | alc_rebuild_imux_for_auto_mic(codec); |
| 5170 | alc_remove_invalid_adc_nids(codec); |
| 5171 | } |
| 5172 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5173 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5174 | set_capture_mixer(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5175 | |
| 5176 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 5177 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5178 | if (err < 0) |
| 5179 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5180 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5181 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5182 | |
| 5183 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5184 | |
| 5185 | spec->vmaster_nid = 0x02; |
| 5186 | |
| 5187 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 5188 | #ifdef CONFIG_PM |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5189 | codec->patch_ops.resume = alc269_resume; |
| 5190 | #endif |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5191 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5192 | spec->shutup = alc269_shutup; |
| 5193 | |
| 5194 | alc_init_jacks(codec); |
| 5195 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5196 | if (!spec->loopback.amplist) |
| 5197 | spec->loopback.amplist = alc269_loopbacks; |
| 5198 | if (alc269_mic2_for_mute_led(codec)) |
| 5199 | codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps; |
| 5200 | #endif |
| 5201 | |
| 5202 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5203 | |
| 5204 | error: |
| 5205 | alc_free(codec); |
| 5206 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5207 | } |
| 5208 | |
| 5209 | /* |
| 5210 | * ALC861 |
| 5211 | */ |
| 5212 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5213 | static int alc861_parse_auto_config(struct hda_codec *codec) |
| 5214 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5215 | static const hda_nid_t alc861_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5216 | static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 }; |
| 5217 | return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5218 | } |
| 5219 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5220 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5221 | static const struct hda_amp_list alc861_loopbacks[] = { |
| 5222 | { 0x15, HDA_INPUT, 0 }, |
| 5223 | { 0x15, HDA_INPUT, 1 }, |
| 5224 | { 0x15, HDA_INPUT, 2 }, |
| 5225 | { 0x15, HDA_INPUT, 3 }, |
| 5226 | { } /* end */ |
| 5227 | }; |
| 5228 | #endif |
| 5229 | |
| 5230 | |
| 5231 | /* Pin config fixes */ |
| 5232 | enum { |
| 5233 | PINFIX_FSC_AMILO_PI1505, |
| 5234 | }; |
| 5235 | |
| 5236 | static const struct alc_fixup alc861_fixups[] = { |
| 5237 | [PINFIX_FSC_AMILO_PI1505] = { |
| 5238 | .type = ALC_FIXUP_PINS, |
| 5239 | .v.pins = (const struct alc_pincfg[]) { |
| 5240 | { 0x0b, 0x0221101f }, /* HP */ |
| 5241 | { 0x0f, 0x90170310 }, /* speaker */ |
| 5242 | { } |
| 5243 | } |
| 5244 | }, |
| 5245 | }; |
| 5246 | |
| 5247 | static const struct snd_pci_quirk alc861_fixup_tbl[] = { |
| 5248 | SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505), |
| 5249 | {} |
| 5250 | }; |
| 5251 | |
| 5252 | /* |
| 5253 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5254 | static int patch_alc861(struct hda_codec *codec) |
| 5255 | { |
| 5256 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5257 | int err; |
| 5258 | |
| 5259 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5260 | if (spec == NULL) |
| 5261 | return -ENOMEM; |
| 5262 | |
| 5263 | codec->spec = spec; |
| 5264 | |
| 5265 | spec->mixer_nid = 0x15; |
| 5266 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5267 | alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); |
| 5268 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5269 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5270 | /* automatic parse from the BIOS config */ |
| 5271 | err = alc861_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5272 | if (err < 0) |
| 5273 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5274 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5275 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5276 | alc_auto_fill_adc_caps(codec); |
| 5277 | alc_rebuild_imux_for_auto_mic(codec); |
| 5278 | alc_remove_invalid_adc_nids(codec); |
| 5279 | } |
| 5280 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5281 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5282 | set_capture_mixer(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5283 | |
| 5284 | if (!spec->no_analog) { |
| 5285 | err = snd_hda_attach_beep_device(codec, 0x23); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5286 | if (err < 0) |
| 5287 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5288 | set_beep_amp(spec, 0x23, 0, HDA_OUTPUT); |
| 5289 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5290 | |
| 5291 | spec->vmaster_nid = 0x03; |
| 5292 | |
| 5293 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5294 | |
| 5295 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5296 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5297 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5298 | spec->power_hook = alc_power_eapd; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5299 | if (!spec->loopback.amplist) |
| 5300 | spec->loopback.amplist = alc861_loopbacks; |
| 5301 | #endif |
| 5302 | |
| 5303 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5304 | |
| 5305 | error: |
| 5306 | alc_free(codec); |
| 5307 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5308 | } |
| 5309 | |
| 5310 | /* |
| 5311 | * ALC861-VD support |
| 5312 | * |
| 5313 | * Based on ALC882 |
| 5314 | * |
| 5315 | * In addition, an independent DAC |
| 5316 | */ |
| 5317 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5318 | #define alc861vd_loopbacks alc880_loopbacks |
| 5319 | #endif |
| 5320 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5321 | static int alc861vd_parse_auto_config(struct hda_codec *codec) |
| 5322 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5323 | static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5324 | static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5325 | return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5326 | } |
| 5327 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5328 | enum { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5329 | ALC660VD_FIX_ASUS_GPIO1, |
| 5330 | ALC861VD_FIX_DALLAS, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5331 | }; |
| 5332 | |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5333 | /* exclude VREF80 */ |
| 5334 | static void alc861vd_fixup_dallas(struct hda_codec *codec, |
| 5335 | const struct alc_fixup *fix, int action) |
| 5336 | { |
| 5337 | if (action == ALC_FIXUP_ACT_PRE_PROBE) { |
| 5338 | snd_hda_override_pin_caps(codec, 0x18, 0x00001714); |
| 5339 | snd_hda_override_pin_caps(codec, 0x19, 0x0000171c); |
| 5340 | } |
| 5341 | } |
| 5342 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5343 | static const struct alc_fixup alc861vd_fixups[] = { |
| 5344 | [ALC660VD_FIX_ASUS_GPIO1] = { |
| 5345 | .type = ALC_FIXUP_VERBS, |
| 5346 | .v.verbs = (const struct hda_verb[]) { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5347 | /* reset GPIO1 */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5348 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, |
| 5349 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, |
| 5350 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, |
| 5351 | { } |
| 5352 | } |
| 5353 | }, |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5354 | [ALC861VD_FIX_DALLAS] = { |
| 5355 | .type = ALC_FIXUP_FUNC, |
| 5356 | .v.func = alc861vd_fixup_dallas, |
| 5357 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5358 | }; |
| 5359 | |
| 5360 | static const struct snd_pci_quirk alc861vd_fixup_tbl[] = { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5361 | SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5362 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1), |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5363 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5364 | {} |
| 5365 | }; |
| 5366 | |
| 5367 | static const struct hda_verb alc660vd_eapd_verbs[] = { |
| 5368 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2}, |
| 5369 | {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2}, |
| 5370 | { } |
| 5371 | }; |
| 5372 | |
| 5373 | /* |
| 5374 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5375 | static int patch_alc861vd(struct hda_codec *codec) |
| 5376 | { |
| 5377 | struct alc_spec *spec; |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5378 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5379 | |
| 5380 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5381 | if (spec == NULL) |
| 5382 | return -ENOMEM; |
| 5383 | |
| 5384 | codec->spec = spec; |
| 5385 | |
| 5386 | spec->mixer_nid = 0x0b; |
| 5387 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5388 | alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); |
| 5389 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5390 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5391 | /* automatic parse from the BIOS config */ |
| 5392 | err = alc861vd_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5393 | if (err < 0) |
| 5394 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5395 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5396 | if (codec->vendor_id == 0x10ec0660) { |
| 5397 | /* always turn on EAPD */ |
| 5398 | add_verb(spec, alc660vd_eapd_verbs); |
| 5399 | } |
| 5400 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5401 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5402 | alc_auto_fill_adc_caps(codec); |
| 5403 | alc_rebuild_imux_for_auto_mic(codec); |
| 5404 | alc_remove_invalid_adc_nids(codec); |
| 5405 | } |
| 5406 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5407 | if (!spec->no_analog && !spec->cap_mixer) |
| 5408 | set_capture_mixer(codec); |
| 5409 | |
| 5410 | if (!spec->no_analog) { |
| 5411 | err = snd_hda_attach_beep_device(codec, 0x23); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5412 | if (err < 0) |
| 5413 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5414 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 5415 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5416 | |
| 5417 | spec->vmaster_nid = 0x02; |
| 5418 | |
| 5419 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5420 | |
| 5421 | codec->patch_ops = alc_patch_ops; |
| 5422 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5423 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5424 | spec->shutup = alc_eapd_shutup; |
| 5425 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5426 | if (!spec->loopback.amplist) |
| 5427 | spec->loopback.amplist = alc861vd_loopbacks; |
| 5428 | #endif |
| 5429 | |
| 5430 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5431 | |
| 5432 | error: |
| 5433 | alc_free(codec); |
| 5434 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5435 | } |
| 5436 | |
| 5437 | /* |
| 5438 | * ALC662 support |
| 5439 | * |
| 5440 | * ALC662 is almost identical with ALC880 but has cleaner and more flexible |
| 5441 | * configuration. Each pin widget can choose any input DACs and a mixer. |
| 5442 | * Each ADC is connected from a mixer of all inputs. This makes possible |
| 5443 | * 6-channel independent captures. |
| 5444 | * |
| 5445 | * In addition, an independent DAC for the multi-playback (not used in this |
| 5446 | * driver yet). |
| 5447 | */ |
| 5448 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5449 | #define alc662_loopbacks alc880_loopbacks |
| 5450 | #endif |
| 5451 | |
| 5452 | /* |
| 5453 | * BIOS auto configuration |
| 5454 | */ |
| 5455 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5456 | static int alc662_parse_auto_config(struct hda_codec *codec) |
| 5457 | { |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 5458 | static const hda_nid_t alc662_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5459 | static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 }; |
| 5460 | static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5461 | const hda_nid_t *ssids; |
Takashi Iwai | ee979a14 | 2008-09-02 15:42:20 +0200 | [diff] [blame] | 5462 | |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 5463 | if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 || |
| 5464 | codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670) |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5465 | ssids = alc663_ssids; |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 5466 | else |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5467 | ssids = alc662_ssids; |
| 5468 | return alc_parse_auto_config(codec, alc662_ignore, ssids); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5469 | } |
| 5470 | |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5471 | static void alc272_fixup_mario(struct hda_codec *codec, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5472 | const struct alc_fixup *fix, int action) |
Takashi Iwai | 6fc398c | 2011-01-13 14:36:37 +0100 | [diff] [blame] | 5473 | { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5474 | if (action != ALC_FIXUP_ACT_PROBE) |
Takashi Iwai | 6fc398c | 2011-01-13 14:36:37 +0100 | [diff] [blame] | 5475 | return; |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5476 | if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT, |
| 5477 | (0x3b << AC_AMPCAP_OFFSET_SHIFT) | |
| 5478 | (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 5479 | (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 5480 | (0 << AC_AMPCAP_MUTE_SHIFT))) |
| 5481 | printk(KERN_WARNING |
| 5482 | "hda_codec: failed to override amp caps for NID 0x2\n"); |
| 5483 | } |
| 5484 | |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5485 | enum { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5486 | ALC662_FIXUP_ASPIRE, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5487 | ALC662_FIXUP_IDEAPAD, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5488 | ALC272_FIXUP_MARIO, |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 5489 | ALC662_FIXUP_CZC_P10T, |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 5490 | ALC662_FIXUP_SKU_IGNORE, |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 5491 | ALC662_FIXUP_HP_RP5800, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5492 | ALC662_FIXUP_ASUS_MODE1, |
| 5493 | ALC662_FIXUP_ASUS_MODE2, |
| 5494 | ALC662_FIXUP_ASUS_MODE3, |
| 5495 | ALC662_FIXUP_ASUS_MODE4, |
| 5496 | ALC662_FIXUP_ASUS_MODE5, |
| 5497 | ALC662_FIXUP_ASUS_MODE6, |
| 5498 | ALC662_FIXUP_ASUS_MODE7, |
| 5499 | ALC662_FIXUP_ASUS_MODE8, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5500 | }; |
| 5501 | |
| 5502 | static const struct alc_fixup alc662_fixups[] = { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5503 | [ALC662_FIXUP_ASPIRE] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5504 | .type = ALC_FIXUP_PINS, |
| 5505 | .v.pins = (const struct alc_pincfg[]) { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5506 | { 0x15, 0x99130112 }, /* subwoofer */ |
| 5507 | { } |
| 5508 | } |
| 5509 | }, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5510 | [ALC662_FIXUP_IDEAPAD] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5511 | .type = ALC_FIXUP_PINS, |
| 5512 | .v.pins = (const struct alc_pincfg[]) { |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5513 | { 0x17, 0x99130112 }, /* subwoofer */ |
| 5514 | { } |
| 5515 | } |
| 5516 | }, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5517 | [ALC272_FIXUP_MARIO] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5518 | .type = ALC_FIXUP_FUNC, |
| 5519 | .v.func = alc272_fixup_mario, |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 5520 | }, |
| 5521 | [ALC662_FIXUP_CZC_P10T] = { |
| 5522 | .type = ALC_FIXUP_VERBS, |
| 5523 | .v.verbs = (const struct hda_verb[]) { |
| 5524 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, |
| 5525 | {} |
| 5526 | } |
| 5527 | }, |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 5528 | [ALC662_FIXUP_SKU_IGNORE] = { |
| 5529 | .type = ALC_FIXUP_SKU, |
| 5530 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
Takashi Iwai | c6b3587 | 2011-03-28 12:05:31 +0200 | [diff] [blame] | 5531 | }, |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 5532 | [ALC662_FIXUP_HP_RP5800] = { |
| 5533 | .type = ALC_FIXUP_PINS, |
| 5534 | .v.pins = (const struct alc_pincfg[]) { |
| 5535 | { 0x14, 0x0221201f }, /* HP out */ |
| 5536 | { } |
| 5537 | }, |
| 5538 | .chained = true, |
| 5539 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5540 | }, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5541 | [ALC662_FIXUP_ASUS_MODE1] = { |
| 5542 | .type = ALC_FIXUP_PINS, |
| 5543 | .v.pins = (const struct alc_pincfg[]) { |
| 5544 | { 0x14, 0x99130110 }, /* speaker */ |
| 5545 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5546 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 5547 | { 0x21, 0x0121401f }, /* HP out */ |
| 5548 | { } |
| 5549 | }, |
| 5550 | .chained = true, |
| 5551 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5552 | }, |
| 5553 | [ALC662_FIXUP_ASUS_MODE2] = { |
Takashi Iwai | 2996bdb | 2011-08-18 16:02:24 +0200 | [diff] [blame] | 5554 | .type = ALC_FIXUP_PINS, |
| 5555 | .v.pins = (const struct alc_pincfg[]) { |
| 5556 | { 0x14, 0x99130110 }, /* speaker */ |
| 5557 | { 0x18, 0x01a19820 }, /* mic */ |
| 5558 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 5559 | { 0x1b, 0x0121401f }, /* HP out */ |
| 5560 | { } |
| 5561 | }, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5562 | .chained = true, |
| 5563 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5564 | }, |
| 5565 | [ALC662_FIXUP_ASUS_MODE3] = { |
| 5566 | .type = ALC_FIXUP_PINS, |
| 5567 | .v.pins = (const struct alc_pincfg[]) { |
| 5568 | { 0x14, 0x99130110 }, /* speaker */ |
| 5569 | { 0x15, 0x0121441f }, /* HP */ |
| 5570 | { 0x18, 0x01a19840 }, /* mic */ |
| 5571 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5572 | { 0x21, 0x01211420 }, /* HP2 */ |
| 5573 | { } |
| 5574 | }, |
| 5575 | .chained = true, |
| 5576 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5577 | }, |
| 5578 | [ALC662_FIXUP_ASUS_MODE4] = { |
| 5579 | .type = ALC_FIXUP_PINS, |
| 5580 | .v.pins = (const struct alc_pincfg[]) { |
| 5581 | { 0x14, 0x99130110 }, /* speaker */ |
| 5582 | { 0x16, 0x99130111 }, /* speaker */ |
| 5583 | { 0x18, 0x01a19840 }, /* mic */ |
| 5584 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5585 | { 0x21, 0x0121441f }, /* HP */ |
| 5586 | { } |
| 5587 | }, |
| 5588 | .chained = true, |
| 5589 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5590 | }, |
| 5591 | [ALC662_FIXUP_ASUS_MODE5] = { |
| 5592 | .type = ALC_FIXUP_PINS, |
| 5593 | .v.pins = (const struct alc_pincfg[]) { |
| 5594 | { 0x14, 0x99130110 }, /* speaker */ |
| 5595 | { 0x15, 0x0121441f }, /* HP */ |
| 5596 | { 0x16, 0x99130111 }, /* speaker */ |
| 5597 | { 0x18, 0x01a19840 }, /* mic */ |
| 5598 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5599 | { } |
| 5600 | }, |
| 5601 | .chained = true, |
| 5602 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5603 | }, |
| 5604 | [ALC662_FIXUP_ASUS_MODE6] = { |
| 5605 | .type = ALC_FIXUP_PINS, |
| 5606 | .v.pins = (const struct alc_pincfg[]) { |
| 5607 | { 0x14, 0x99130110 }, /* speaker */ |
| 5608 | { 0x15, 0x01211420 }, /* HP2 */ |
| 5609 | { 0x18, 0x01a19840 }, /* mic */ |
| 5610 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5611 | { 0x1b, 0x0121441f }, /* HP */ |
| 5612 | { } |
| 5613 | }, |
| 5614 | .chained = true, |
| 5615 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5616 | }, |
| 5617 | [ALC662_FIXUP_ASUS_MODE7] = { |
| 5618 | .type = ALC_FIXUP_PINS, |
| 5619 | .v.pins = (const struct alc_pincfg[]) { |
| 5620 | { 0x14, 0x99130110 }, /* speaker */ |
| 5621 | { 0x17, 0x99130111 }, /* speaker */ |
| 5622 | { 0x18, 0x01a19840 }, /* mic */ |
| 5623 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5624 | { 0x1b, 0x01214020 }, /* HP */ |
| 5625 | { 0x21, 0x0121401f }, /* HP */ |
| 5626 | { } |
| 5627 | }, |
| 5628 | .chained = true, |
| 5629 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5630 | }, |
| 5631 | [ALC662_FIXUP_ASUS_MODE8] = { |
| 5632 | .type = ALC_FIXUP_PINS, |
| 5633 | .v.pins = (const struct alc_pincfg[]) { |
| 5634 | { 0x14, 0x99130110 }, /* speaker */ |
| 5635 | { 0x12, 0x99a30970 }, /* int-mic */ |
| 5636 | { 0x15, 0x01214020 }, /* HP */ |
| 5637 | { 0x17, 0x99130111 }, /* speaker */ |
| 5638 | { 0x18, 0x01a19840 }, /* mic */ |
| 5639 | { 0x21, 0x0121401f }, /* HP */ |
| 5640 | { } |
| 5641 | }, |
| 5642 | .chained = true, |
| 5643 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
Takashi Iwai | 2996bdb | 2011-08-18 16:02:24 +0200 | [diff] [blame] | 5644 | }, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5645 | }; |
| 5646 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 5647 | static const struct snd_pci_quirk alc662_fixup_tbl[] = { |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5648 | SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2), |
David Henningsson | a6c47a8 | 2011-02-10 15:39:19 +0100 | [diff] [blame] | 5649 | SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE), |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 5650 | SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE), |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5651 | SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE), |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 5652 | SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5653 | SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2), |
Daniel T Chen | a0e90ac | 2010-11-20 10:20:35 -0500 | [diff] [blame] | 5654 | SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD), |
Valentine Sinitsyn | d411858 | 2010-10-01 22:24:08 +0600 | [diff] [blame] | 5655 | SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD), |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5656 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD), |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 5657 | SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T), |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5658 | |
| 5659 | #if 0 |
| 5660 | /* Below is a quirk table taken from the old code. |
| 5661 | * Basically the device should work as is without the fixup table. |
| 5662 | * If BIOS doesn't give a proper info, enable the corresponding |
| 5663 | * fixup entry. |
| 5664 | */ |
| 5665 | SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1), |
| 5666 | SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3), |
| 5667 | SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1), |
| 5668 | SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3), |
| 5669 | SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 5670 | SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5671 | SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 5672 | SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1), |
| 5673 | SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1), |
| 5674 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5675 | SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7), |
| 5676 | SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7), |
| 5677 | SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8), |
| 5678 | SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3), |
| 5679 | SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1), |
| 5680 | SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5681 | SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2), |
| 5682 | SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1), |
| 5683 | SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5684 | SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 5685 | SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 5686 | SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5687 | SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1), |
| 5688 | SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3), |
| 5689 | SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2), |
| 5690 | SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5691 | SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5), |
| 5692 | SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 5693 | SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5694 | SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1), |
| 5695 | SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5696 | SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5697 | SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3), |
| 5698 | SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3), |
| 5699 | SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1), |
| 5700 | SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1), |
| 5701 | SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1), |
| 5702 | SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1), |
| 5703 | SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1), |
| 5704 | SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5705 | SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2), |
| 5706 | SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1), |
| 5707 | SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 5708 | SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3), |
| 5709 | SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1), |
| 5710 | SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1), |
| 5711 | SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1), |
| 5712 | SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2), |
| 5713 | SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 5714 | SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4), |
| 5715 | #endif |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5716 | {} |
| 5717 | }; |
| 5718 | |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5719 | static const struct alc_model_fixup alc662_fixup_models[] = { |
| 5720 | {.id = ALC272_FIXUP_MARIO, .name = "mario"}, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5721 | {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"}, |
| 5722 | {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"}, |
| 5723 | {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"}, |
| 5724 | {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"}, |
| 5725 | {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"}, |
| 5726 | {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"}, |
| 5727 | {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"}, |
| 5728 | {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"}, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5729 | {} |
| 5730 | }; |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5731 | |
| 5732 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5733 | /* |
| 5734 | */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5735 | static int patch_alc662(struct hda_codec *codec) |
| 5736 | { |
| 5737 | struct alc_spec *spec; |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5738 | int err = 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5739 | |
| 5740 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5741 | if (!spec) |
| 5742 | return -ENOMEM; |
| 5743 | |
| 5744 | codec->spec = spec; |
| 5745 | |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 5746 | spec->mixer_nid = 0x0b; |
| 5747 | |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5748 | /* handle multiple HPs as is */ |
| 5749 | spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; |
| 5750 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 5751 | alc_auto_parse_customize_define(codec); |
| 5752 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 5753 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
| 5754 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5755 | err = alc_codec_rename_from_preset(codec); |
| 5756 | if (err < 0) |
| 5757 | goto error; |
| 5758 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5759 | if ((alc_get_coef0(codec) & (1 << 14)) && |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5760 | codec->bus->pci->subsystem_vendor == 0x1025 && |
| 5761 | spec->cdefine.platform_type == 1) { |
| 5762 | if (alc_codec_rename(codec, "ALC272X") < 0) |
| 5763 | goto error; |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5764 | } |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 5765 | |
Takashi Iwai | b9c5106 | 2011-08-24 18:08:07 +0200 | [diff] [blame] | 5766 | alc_pick_fixup(codec, alc662_fixup_models, |
| 5767 | alc662_fixup_tbl, alc662_fixups); |
| 5768 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 5769 | /* automatic parse from the BIOS config */ |
| 5770 | err = alc662_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5771 | if (err < 0) |
| 5772 | goto error; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5773 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5774 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 5775 | alc_auto_fill_adc_caps(codec); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 5776 | alc_rebuild_imux_for_auto_mic(codec); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 5777 | alc_remove_invalid_adc_nids(codec); |
Takashi Iwai | dd70469 | 2009-08-11 08:45:11 +0200 | [diff] [blame] | 5778 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5779 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5780 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | b59bdf3 | 2009-08-11 09:47:30 +0200 | [diff] [blame] | 5781 | set_capture_mixer(codec); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 5782 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5783 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 5784 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5785 | if (err < 0) |
| 5786 | goto error; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 5787 | switch (codec->vendor_id) { |
| 5788 | case 0x10ec0662: |
| 5789 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 5790 | break; |
| 5791 | case 0x10ec0272: |
| 5792 | case 0x10ec0663: |
| 5793 | case 0x10ec0665: |
| 5794 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
| 5795 | break; |
| 5796 | case 0x10ec0273: |
| 5797 | set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT); |
| 5798 | break; |
| 5799 | } |
Kailang Yang | cec27c8 | 2010-02-04 14:18:18 +0100 | [diff] [blame] | 5800 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 5801 | spec->vmaster_nid = 0x02; |
| 5802 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5803 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5804 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5805 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | b9c5106 | 2011-08-24 18:08:07 +0200 | [diff] [blame] | 5806 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 5807 | spec->shutup = alc_eapd_shutup; |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5808 | |
Kailang Yang | bf1b022 | 2010-10-21 08:49:56 +0200 | [diff] [blame] | 5809 | alc_init_jacks(codec); |
| 5810 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 5811 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5812 | if (!spec->loopback.amplist) |
| 5813 | spec->loopback.amplist = alc662_loopbacks; |
| 5814 | #endif |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5815 | |
| 5816 | return 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5817 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5818 | error: |
| 5819 | alc_free(codec); |
| 5820 | return err; |
Kailang Yang | b478b99 | 2011-05-18 11:51:15 +0200 | [diff] [blame] | 5821 | } |
| 5822 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5823 | /* |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5824 | * ALC680 support |
| 5825 | */ |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5826 | |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5827 | static int alc680_parse_auto_config(struct hda_codec *codec) |
| 5828 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5829 | return alc_parse_auto_config(codec, NULL, NULL); |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5830 | } |
| 5831 | |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5832 | /* |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5833 | */ |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5834 | static int patch_alc680(struct hda_codec *codec) |
| 5835 | { |
| 5836 | struct alc_spec *spec; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5837 | int err; |
| 5838 | |
| 5839 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5840 | if (spec == NULL) |
| 5841 | return -ENOMEM; |
| 5842 | |
| 5843 | codec->spec = spec; |
| 5844 | |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 5845 | /* ALC680 has no aa-loopback mixer */ |
| 5846 | |
Takashi Iwai | 1ebec5f | 2011-08-15 13:21:48 +0200 | [diff] [blame] | 5847 | /* automatic parse from the BIOS config */ |
| 5848 | err = alc680_parse_auto_config(codec); |
| 5849 | if (err < 0) { |
| 5850 | alc_free(codec); |
| 5851 | return err; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5852 | } |
| 5853 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5854 | if (!spec->no_analog && !spec->cap_mixer) |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5855 | set_capture_mixer(codec); |
| 5856 | |
| 5857 | spec->vmaster_nid = 0x02; |
| 5858 | |
| 5859 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 1ebec5f | 2011-08-15 13:21:48 +0200 | [diff] [blame] | 5860 | spec->init_hook = alc_auto_init_std; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5861 | |
| 5862 | return 0; |
| 5863 | } |
| 5864 | |
| 5865 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5866 | * patch entries |
| 5867 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 5868 | static const struct hda_codec_preset snd_hda_preset_realtek[] = { |
Kailang Yang | 296f033 | 2011-05-18 11:52:36 +0200 | [diff] [blame] | 5869 | { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5870 | { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 }, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 5871 | { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 }, |
Kailang Yang | f6a9224 | 2007-12-13 16:52:54 +0100 | [diff] [blame] | 5872 | { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 }, |
Kailang Yang | a361d84 | 2007-06-05 12:30:55 +0200 | [diff] [blame] | 5873 | { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 }, |
Kailang Yang | f6a9224 | 2007-12-13 16:52:54 +0100 | [diff] [blame] | 5874 | { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 }, |
Kailang Yang | ebb83ee | 2009-12-17 12:23:00 +0100 | [diff] [blame] | 5875 | { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 }, |
Kailang Yang | 01afd41 | 2008-10-15 11:22:09 +0200 | [diff] [blame] | 5876 | { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 }, |
Kailang Yang | ebb83ee | 2009-12-17 12:23:00 +0100 | [diff] [blame] | 5877 | { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 }, |
Kailang Yang | 296f033 | 2011-05-18 11:52:36 +0200 | [diff] [blame] | 5878 | { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 5879 | { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660", |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5880 | .patch = patch_alc861 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 5881 | { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd }, |
| 5882 | { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 }, |
| 5883 | { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd }, |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5884 | { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5885 | .patch = patch_alc882 }, |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5886 | { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1", |
| 5887 | .patch = patch_alc662 }, |
David Henningsson | cc667a7 | 2011-10-18 14:07:51 +0200 | [diff] [blame] | 5888 | { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3", |
| 5889 | .patch = patch_alc662 }, |
Kailang Yang | 6dda9f4 | 2008-05-27 12:05:31 +0200 | [diff] [blame] | 5890 | { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 }, |
Kailang Yang | cec27c8 | 2010-02-04 14:18:18 +0100 | [diff] [blame] | 5891 | { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 }, |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 5892 | { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 }, |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5893 | { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 5894 | { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5895 | { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5896 | { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 }, |
Clive Messer | 669faba | 2008-09-30 15:49:13 +0200 | [diff] [blame] | 5897 | { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5898 | .patch = patch_alc882 }, |
Takashi Iwai | cb308f9 | 2008-04-16 14:13:29 +0200 | [diff] [blame] | 5899 | { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5900 | .patch = patch_alc882 }, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 5901 | { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5902 | { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 }, |
Kailang Yang | 4442608 | 2008-10-15 11:18:05 +0200 | [diff] [blame] | 5903 | { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5904 | .patch = patch_alc882 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5905 | { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 }, |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5906 | { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 }, |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 5907 | { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5908 | { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5909 | {} /* terminator */ |
| 5910 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 5911 | |
| 5912 | MODULE_ALIAS("snd-hda-codec-id:10ec*"); |
| 5913 | |
| 5914 | MODULE_LICENSE("GPL"); |
| 5915 | MODULE_DESCRIPTION("Realtek HD-audio codec"); |
| 5916 | |
| 5917 | static struct hda_codec_preset_list realtek_list = { |
| 5918 | .preset = snd_hda_preset_realtek, |
| 5919 | .owner = THIS_MODULE, |
| 5920 | }; |
| 5921 | |
| 5922 | static int __init patch_realtek_init(void) |
| 5923 | { |
| 5924 | return snd_hda_add_codec_preset(&realtek_list); |
| 5925 | } |
| 5926 | |
| 5927 | static void __exit patch_realtek_exit(void) |
| 5928 | { |
| 5929 | snd_hda_delete_codec_preset(&realtek_list); |
| 5930 | } |
| 5931 | |
| 5932 | module_init(patch_realtek_init) |
| 5933 | module_exit(patch_realtek_exit) |