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