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" |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 36 | #include "hda_jack.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 38 | /* unsol event tags */ |
| 39 | #define ALC_FRONT_EVENT 0x01 |
| 40 | #define ALC_DCVOL_EVENT 0x02 |
| 41 | #define ALC_HP_EVENT 0x04 |
| 42 | #define ALC_MIC_EVENT 0x08 |
Takashi Iwai | d4a86d8 | 2010-06-23 17:51:26 +0200 | [diff] [blame] | 43 | |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 44 | /* for GPIO Poll */ |
| 45 | #define GPIO_MASK 0x03 |
| 46 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 47 | /* extra amp-initialization sequence types */ |
| 48 | enum { |
| 49 | ALC_INIT_NONE, |
| 50 | ALC_INIT_DEFAULT, |
| 51 | ALC_INIT_GPIO1, |
| 52 | ALC_INIT_GPIO2, |
| 53 | ALC_INIT_GPIO3, |
| 54 | }; |
| 55 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 56 | struct alc_customize_define { |
| 57 | unsigned int sku_cfg; |
| 58 | unsigned char port_connectivity; |
| 59 | unsigned char check_sum; |
| 60 | unsigned char customization; |
| 61 | unsigned char external_amp; |
| 62 | unsigned int enable_pcbeep:1; |
| 63 | unsigned int platform_type:1; |
| 64 | unsigned int swap:1; |
| 65 | unsigned int override:1; |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 66 | 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] | 67 | }; |
| 68 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 69 | struct alc_fixup; |
| 70 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 71 | struct alc_multi_io { |
| 72 | hda_nid_t pin; /* multi-io widget pin NID */ |
| 73 | hda_nid_t dac; /* DAC to be connected */ |
| 74 | unsigned int ctl_in; /* cached input-pin control value */ |
| 75 | }; |
| 76 | |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 77 | enum { |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 78 | ALC_AUTOMUTE_PIN, /* change the pin control */ |
| 79 | ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */ |
| 80 | ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */ |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 81 | }; |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | struct alc_spec { |
| 84 | /* codec parameterization */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 85 | const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | unsigned int num_mixers; |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 87 | const struct snd_kcontrol_new *cap_mixer; /* capture mixer */ |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 88 | unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Takashi Iwai | 2d9c648 | 2009-10-13 08:06:55 +0200 | [diff] [blame] | 90 | const struct hda_verb *init_verbs[10]; /* initialization verbs |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 91 | * don't forget NULL |
| 92 | * termination! |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 93 | */ |
| 94 | unsigned int num_init_verbs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Takashi Iwai | aa563af | 2009-07-31 10:05:11 +0200 | [diff] [blame] | 96 | char stream_name_analog[32]; /* analog PCM stream */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 97 | const struct hda_pcm_stream *stream_analog_playback; |
| 98 | const struct hda_pcm_stream *stream_analog_capture; |
| 99 | const struct hda_pcm_stream *stream_analog_alt_playback; |
| 100 | const struct hda_pcm_stream *stream_analog_alt_capture; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Takashi Iwai | aa563af | 2009-07-31 10:05:11 +0200 | [diff] [blame] | 102 | char stream_name_digital[32]; /* digital PCM stream */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 103 | const struct hda_pcm_stream *stream_digital_playback; |
| 104 | const struct hda_pcm_stream *stream_digital_capture; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* playback */ |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 107 | struct hda_multi_out multiout; /* playback set-up |
| 108 | * max_channels, dacs must be set |
| 109 | * dig_out_nid and hp_nid are optional |
| 110 | */ |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 111 | hda_nid_t alt_dac_nid; |
Takashi Iwai | 6a05ac4 | 2009-02-13 11:19:09 +0100 | [diff] [blame] | 112 | hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */ |
Takashi Iwai | 8c44198 | 2009-01-20 18:30:20 +0100 | [diff] [blame] | 113 | int dig_out_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
| 115 | /* capture */ |
| 116 | unsigned int num_adc_nids; |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 117 | const hda_nid_t *adc_nids; |
| 118 | const hda_nid_t *capsrc_nids; |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 119 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 120 | hda_nid_t mixer_nid; /* analog-mixer NID */ |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 121 | DECLARE_BITMAP(vol_ctls, 0x20 << 1); |
| 122 | DECLARE_BITMAP(sw_ctls, 0x20 << 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 124 | /* capture setup for dynamic dual-adc switch */ |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 125 | hda_nid_t cur_adc; |
| 126 | unsigned int cur_adc_stream_tag; |
| 127 | unsigned int cur_adc_format; |
| 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | /* capture source */ |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 130 | unsigned int num_mux_defs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | const struct hda_input_mux *input_mux; |
| 132 | unsigned int cur_mux[3]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 133 | hda_nid_t ext_mic_pin; |
| 134 | hda_nid_t dock_mic_pin; |
| 135 | hda_nid_t int_mic_pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | /* channel model */ |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 138 | const struct hda_channel_mode *channel_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | int num_channel_mode; |
Takashi Iwai | 4e195a7 | 2006-07-28 14:47:34 +0200 | [diff] [blame] | 140 | int need_dac_fix; |
Hector Martin | 3b315d7 | 2009-06-02 10:54:19 +0200 | [diff] [blame] | 141 | int const_channel_count; |
| 142 | int ext_channel_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
| 144 | /* PCM information */ |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 145 | struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */ |
Takashi Iwai | 41e41f1 | 2005-06-08 14:48:49 +0200 | [diff] [blame] | 146 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 147 | /* dynamic controls, init_verbs and input_mux */ |
| 148 | struct auto_pin_cfg autocfg; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 149 | struct alc_customize_define cdefine; |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 150 | struct snd_array kctls; |
Herton Ronaldo Krzesinski | 61b9b9b | 2009-01-28 09:16:33 -0200 | [diff] [blame] | 151 | struct hda_input_mux private_imux[3]; |
Takashi Iwai | 41923e4 | 2007-10-22 17:20:10 +0200 | [diff] [blame] | 152 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 153 | hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS]; |
| 154 | hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 155 | hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS]; |
| 156 | unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS]; |
| 157 | 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] | 158 | |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 159 | /* hooks */ |
| 160 | void (*init_hook)(struct hda_codec *codec); |
| 161 | void (*unsol_event)(struct hda_codec *codec, unsigned int res); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 162 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 163 | void (*power_hook)(struct hda_codec *codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 164 | #endif |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 165 | void (*shutup)(struct hda_codec *codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 166 | void (*automute_hook)(struct hda_codec *codec); |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 167 | |
Takashi Iwai | 834be88 | 2006-03-01 14:16:17 +0100 | [diff] [blame] | 168 | /* for pin sensing */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 169 | unsigned int hp_jack_present:1; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 170 | unsigned int line_jack_present:1; |
Takashi Iwai | e942796 | 2011-04-28 15:46:07 +0200 | [diff] [blame] | 171 | unsigned int master_mute:1; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 172 | unsigned int auto_mic:1; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 173 | unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 174 | unsigned int automute_speaker:1; /* automute speaker outputs */ |
| 175 | unsigned int automute_lo:1; /* automute LO outputs */ |
| 176 | unsigned int detect_hp:1; /* Headphone detection enabled */ |
| 177 | unsigned int detect_lo:1; /* Line-out detection enabled */ |
| 178 | unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */ |
| 179 | unsigned int automute_lo_possible:1; /* there are line outs and HP */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 180 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 181 | /* other flags */ |
| 182 | unsigned int no_analog :1; /* digital I/O only */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 183 | unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */ |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 184 | unsigned int single_input_src:1; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 185 | 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] | 186 | unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */ |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 187 | unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */ |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 188 | |
| 189 | /* auto-mute control */ |
| 190 | int automute_mode; |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 191 | hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 192 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 193 | int init_amp; |
Takashi Iwai | d433a67 | 2010-09-20 15:11:54 +0200 | [diff] [blame] | 194 | int codec_variant; /* flag for other variants */ |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 195 | |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 196 | /* for virtual master */ |
| 197 | hda_nid_t vmaster_nid; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 198 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 199 | struct hda_loopback_check loopback; |
| 200 | #endif |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 201 | |
| 202 | /* for PLL fix */ |
| 203 | hda_nid_t pll_nid; |
| 204 | unsigned int pll_coef_idx, pll_coef_bit; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 205 | unsigned int coef0; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 206 | |
| 207 | /* fix-up list */ |
| 208 | int fixup_id; |
| 209 | const struct alc_fixup *fixup_list; |
| 210 | const char *fixup_name; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 211 | |
| 212 | /* multi-io */ |
| 213 | int multi_ios; |
| 214 | struct alc_multi_io multi_io[4]; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 215 | |
| 216 | /* bind volumes */ |
| 217 | struct snd_array bind_ctls; |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 218 | }; |
| 219 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 220 | #define ALC_MODEL_AUTO 0 /* common for all chips */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 222 | static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, |
| 223 | int dir, unsigned int bits) |
| 224 | { |
| 225 | if (!nid) |
| 226 | return false; |
| 227 | if (get_wcaps(codec, nid) & (1 << (dir + 1))) |
| 228 | if (query_amp_caps(codec, nid, dir) & bits) |
| 229 | return true; |
| 230 | return false; |
| 231 | } |
| 232 | |
| 233 | #define nid_has_mute(codec, nid, dir) \ |
| 234 | check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE) |
| 235 | #define nid_has_volume(codec, nid, dir) \ |
| 236 | check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS) |
| 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | /* |
| 239 | * input MUX handling |
| 240 | */ |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 241 | static int alc_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 242 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
| 244 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 245 | struct alc_spec *spec = codec->spec; |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 246 | unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id); |
| 247 | if (mux_idx >= spec->num_mux_defs) |
| 248 | mux_idx = 0; |
Takashi Iwai | 5311114 | 2010-03-08 12:13:07 +0100 | [diff] [blame] | 249 | if (!spec->input_mux[mux_idx].num_items && mux_idx > 0) |
| 250 | mux_idx = 0; |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 251 | return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 254 | static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 255 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
| 257 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 258 | struct alc_spec *spec = codec->spec; |
| 259 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 260 | |
| 261 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
| 262 | return 0; |
| 263 | } |
| 264 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 265 | 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] | 266 | { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 267 | struct alc_spec *spec = codec->spec; |
| 268 | hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]]; |
| 269 | |
| 270 | if (spec->cur_adc && spec->cur_adc != new_adc) { |
| 271 | /* stream is running, let's swap the current ADC */ |
| 272 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); |
| 273 | spec->cur_adc = new_adc; |
| 274 | snd_hda_codec_setup_stream(codec, new_adc, |
| 275 | spec->cur_adc_stream_tag, 0, |
| 276 | spec->cur_adc_format); |
| 277 | return true; |
| 278 | } |
| 279 | return false; |
| 280 | } |
| 281 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 282 | static void call_update_outputs(struct hda_codec *codec); |
| 283 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 284 | /* select the given imux item; either unmute exclusively or select the route */ |
| 285 | static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx, |
| 286 | unsigned int idx, bool force) |
| 287 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 289 | const struct hda_input_mux *imux; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 290 | unsigned int mux_idx; |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 291 | int i, type, num_conns; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 292 | hda_nid_t nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 294 | mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; |
| 295 | imux = &spec->input_mux[mux_idx]; |
Takashi Iwai | 5311114 | 2010-03-08 12:13:07 +0100 | [diff] [blame] | 296 | if (!imux->num_items && mux_idx > 0) |
| 297 | imux = &spec->input_mux[0]; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 298 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 299 | if (idx >= imux->num_items) |
| 300 | idx = imux->num_items - 1; |
| 301 | if (spec->cur_mux[adc_idx] == idx && !force) |
| 302 | return 0; |
| 303 | spec->cur_mux[adc_idx] = idx; |
| 304 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 305 | /* for shared I/O, change the pin-control accordingly */ |
| 306 | if (spec->shared_mic_hp) { |
| 307 | /* NOTE: this assumes that there are only two inputs, the |
| 308 | * first is the real internal mic and the second is HP jack. |
| 309 | */ |
| 310 | snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0, |
| 311 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 312 | spec->cur_mux[adc_idx] ? |
| 313 | PIN_VREF80 : PIN_HP); |
| 314 | spec->automute_speaker = !spec->cur_mux[adc_idx]; |
| 315 | call_update_outputs(codec); |
| 316 | } |
| 317 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 318 | if (spec->dyn_adc_switch) { |
| 319 | alc_dyn_adc_pcm_resetup(codec, idx); |
| 320 | adc_idx = spec->dyn_adc_idx[idx]; |
| 321 | } |
| 322 | |
| 323 | nid = spec->capsrc_nids ? |
| 324 | spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx]; |
| 325 | |
| 326 | /* no selection? */ |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 327 | num_conns = snd_hda_get_conn_list(codec, nid, NULL); |
| 328 | if (num_conns <= 1) |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 329 | return 1; |
| 330 | |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 331 | type = get_wcaps_type(get_wcaps(codec, nid)); |
Takashi Iwai | 0169b6b | 2009-06-22 10:50:19 +0200 | [diff] [blame] | 332 | if (type == AC_WID_AUD_MIX) { |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 333 | /* Matrix-mixer style (e.g. ALC882) */ |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 334 | int active = imux->items[idx].index; |
| 335 | for (i = 0; i < num_conns; i++) { |
| 336 | unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE; |
| 337 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i, |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 338 | HDA_AMP_MUTE, v); |
| 339 | } |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 340 | } else { |
| 341 | /* MUX style (e.g. ALC880) */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 342 | snd_hda_codec_write_cache(codec, nid, 0, |
| 343 | AC_VERB_SET_CONNECT_SEL, |
| 344 | imux->items[idx].index); |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 345 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 346 | return 1; |
| 347 | } |
| 348 | |
| 349 | static int alc_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 350 | struct snd_ctl_elem_value *ucontrol) |
| 351 | { |
| 352 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 353 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 354 | return alc_mux_select(codec, adc_idx, |
| 355 | ucontrol->value.enumerated.item[0], false); |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 356 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | /* |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 359 | * set up the input pin config (depending on the given auto-pin type) |
| 360 | */ |
| 361 | static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid, |
| 362 | int auto_pin_type) |
| 363 | { |
| 364 | unsigned int val = PIN_IN; |
| 365 | |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 366 | if (auto_pin_type == AUTO_PIN_MIC) { |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 367 | unsigned int pincap; |
Takashi Iwai | 954a29c | 2010-07-30 10:55:44 +0200 | [diff] [blame] | 368 | unsigned int oldval; |
| 369 | oldval = snd_hda_codec_read(codec, nid, 0, |
| 370 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
Takashi Iwai | 1327a32 | 2009-03-23 13:07:47 +0100 | [diff] [blame] | 371 | pincap = snd_hda_query_pin_caps(codec, nid); |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 372 | pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; |
Takashi Iwai | 954a29c | 2010-07-30 10:55:44 +0200 | [diff] [blame] | 373 | /* if the default pin setup is vref50, we give it priority */ |
| 374 | if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50) |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 375 | val = PIN_VREF80; |
Takashi Iwai | 461c6c3 | 2009-05-25 08:06:02 +0200 | [diff] [blame] | 376 | else if (pincap & AC_PINCAP_VREF_50) |
| 377 | val = PIN_VREF50; |
| 378 | else if (pincap & AC_PINCAP_VREF_100) |
| 379 | val = PIN_VREF100; |
| 380 | else if (pincap & AC_PINCAP_VREF_GRD) |
| 381 | val = PIN_VREFGRD; |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 382 | } |
| 383 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val); |
| 384 | } |
| 385 | |
| 386 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 387 | * Append the given mixer and verb elements for the later use |
| 388 | * The mixer array is referred in build_controls(), and init_verbs are |
| 389 | * called in init(). |
Takashi Iwai | d88897e | 2008-10-31 15:01:37 +0100 | [diff] [blame] | 390 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 391 | 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] | 392 | { |
| 393 | if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers))) |
| 394 | return; |
| 395 | spec->mixers[spec->num_mixers++] = mix; |
| 396 | } |
| 397 | |
| 398 | static void add_verb(struct alc_spec *spec, const struct hda_verb *verb) |
| 399 | { |
| 400 | if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs))) |
| 401 | return; |
| 402 | spec->init_verbs[spec->num_init_verbs++] = verb; |
| 403 | } |
| 404 | |
| 405 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 406 | * GPIO setup tables, used in initialization |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 407 | */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 408 | /* Enable GPIO mask and set output */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 409 | static const struct hda_verb alc_gpio1_init_verbs[] = { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 410 | {0x01, AC_VERB_SET_GPIO_MASK, 0x01}, |
| 411 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, |
| 412 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, |
| 413 | { } |
| 414 | }; |
| 415 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 416 | static const struct hda_verb alc_gpio2_init_verbs[] = { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 417 | {0x01, AC_VERB_SET_GPIO_MASK, 0x02}, |
| 418 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02}, |
| 419 | {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, |
| 420 | { } |
| 421 | }; |
| 422 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 423 | static const struct hda_verb alc_gpio3_init_verbs[] = { |
Kailang Yang | bdd148a | 2007-05-08 15:19:08 +0200 | [diff] [blame] | 424 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, |
| 425 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03}, |
| 426 | {0x01, AC_VERB_SET_GPIO_DATA, 0x03}, |
| 427 | { } |
| 428 | }; |
| 429 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 430 | /* |
| 431 | * Fix hardware PLL issue |
| 432 | * On some codecs, the analog PLL gating control must be off while |
| 433 | * the default value is 1. |
| 434 | */ |
| 435 | static void alc_fix_pll(struct hda_codec *codec) |
| 436 | { |
| 437 | struct alc_spec *spec = codec->spec; |
| 438 | unsigned int val; |
| 439 | |
| 440 | if (!spec->pll_nid) |
| 441 | return; |
| 442 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, |
| 443 | spec->pll_coef_idx); |
| 444 | val = snd_hda_codec_read(codec, spec->pll_nid, 0, |
| 445 | AC_VERB_GET_PROC_COEF, 0); |
| 446 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, |
| 447 | spec->pll_coef_idx); |
| 448 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF, |
| 449 | val & ~(1 << spec->pll_coef_bit)); |
| 450 | } |
| 451 | |
| 452 | static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid, |
| 453 | unsigned int coef_idx, unsigned int coef_bit) |
| 454 | { |
| 455 | struct alc_spec *spec = codec->spec; |
| 456 | spec->pll_nid = nid; |
| 457 | spec->pll_coef_idx = coef_idx; |
| 458 | spec->pll_coef_bit = coef_bit; |
| 459 | alc_fix_pll(codec); |
| 460 | } |
| 461 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 462 | /* |
| 463 | * Jack-reporting via input-jack layer |
| 464 | */ |
| 465 | |
| 466 | /* initialization of jacks; currently checks only a few known pins */ |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 467 | static int alc_init_jacks(struct hda_codec *codec) |
| 468 | { |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 469 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 470 | struct alc_spec *spec = codec->spec; |
| 471 | int err; |
| 472 | unsigned int hp_nid = spec->autocfg.hp_pins[0]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 473 | unsigned int mic_nid = spec->ext_mic_pin; |
| 474 | unsigned int dock_nid = spec->dock_mic_pin; |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 475 | |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 476 | if (hp_nid) { |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 477 | err = snd_hda_input_jack_add(codec, hp_nid, |
| 478 | SND_JACK_HEADPHONE, NULL); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 479 | if (err < 0) |
| 480 | return err; |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 481 | snd_hda_input_jack_report(codec, hp_nid); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 482 | } |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 483 | |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 484 | if (mic_nid) { |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 485 | err = snd_hda_input_jack_add(codec, mic_nid, |
| 486 | SND_JACK_MICROPHONE, NULL); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 487 | if (err < 0) |
| 488 | return err; |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 489 | snd_hda_input_jack_report(codec, mic_nid); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 490 | } |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 491 | if (dock_nid) { |
| 492 | err = snd_hda_input_jack_add(codec, dock_nid, |
| 493 | SND_JACK_MICROPHONE, NULL); |
| 494 | if (err < 0) |
| 495 | return err; |
| 496 | snd_hda_input_jack_report(codec, dock_nid); |
| 497 | } |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 498 | #endif /* CONFIG_SND_HDA_INPUT_JACK */ |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 499 | return 0; |
| 500 | } |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 501 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 502 | /* |
| 503 | * Jack detections for HP auto-mute and mic-switch |
| 504 | */ |
| 505 | |
| 506 | /* check each pin in the given array; returns true if any of them is plugged */ |
| 507 | 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] | 508 | { |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 509 | int i, present = 0; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 510 | |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 511 | for (i = 0; i < num_pins; i++) { |
| 512 | hda_nid_t nid = pins[i]; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 513 | if (!nid) |
| 514 | break; |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 515 | snd_hda_input_jack_report(codec, nid); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 516 | present |= snd_hda_jack_detect(codec, nid); |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 517 | } |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 518 | return present; |
| 519 | } |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 520 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 521 | /* standard HP/line-out auto-mute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 522 | 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] | 523 | bool mute, bool hp_out) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 524 | { |
| 525 | struct alc_spec *spec = codec->spec; |
| 526 | unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0; |
Takashi Iwai | e942796 | 2011-04-28 15:46:07 +0200 | [diff] [blame] | 527 | unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 528 | int i; |
| 529 | |
| 530 | for (i = 0; i < num_pins; i++) { |
| 531 | hda_nid_t nid = pins[i]; |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 532 | if (!nid) |
| 533 | break; |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 534 | switch (spec->automute_mode) { |
| 535 | case ALC_AUTOMUTE_PIN: |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 536 | snd_hda_codec_write(codec, nid, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 537 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 538 | pin_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 539 | break; |
| 540 | case ALC_AUTOMUTE_AMP: |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 541 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 542 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 543 | break; |
| 544 | case ALC_AUTOMUTE_MIXER: |
| 545 | nid = spec->automute_mixer_nid[i]; |
| 546 | if (!nid) |
| 547 | break; |
| 548 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 549 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 550 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 551 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 552 | break; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 553 | } |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 554 | } |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 555 | } |
| 556 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 557 | /* Toggle outputs muting */ |
| 558 | static void update_outputs(struct hda_codec *codec) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 559 | { |
| 560 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 561 | int on; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 562 | |
Takashi Iwai | c0a2026 | 2011-06-10 15:28:15 +0200 | [diff] [blame] | 563 | /* Control HP pins/amps depending on master_mute state; |
| 564 | * in general, HP pins/amps control should be enabled in all cases, |
| 565 | * but currently set only for master_mute, just to be safe |
| 566 | */ |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 567 | if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */ |
| 568 | do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins), |
Takashi Iwai | c0a2026 | 2011-06-10 15:28:15 +0200 | [diff] [blame] | 569 | spec->autocfg.hp_pins, spec->master_mute, true); |
| 570 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 571 | if (!spec->automute_speaker) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 572 | on = 0; |
| 573 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 574 | on = spec->hp_jack_present | spec->line_jack_present; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 575 | on |= spec->master_mute; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 576 | do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins), |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 577 | spec->autocfg.speaker_pins, on, false); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 578 | |
| 579 | /* toggle line-out mutes if needed, too */ |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 580 | /* if LO is a copy of either HP or Speaker, don't need to handle it */ |
| 581 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] || |
| 582 | spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0]) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 583 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 584 | if (!spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 585 | on = 0; |
| 586 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 587 | on = spec->hp_jack_present; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 588 | on |= spec->master_mute; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 589 | do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 590 | spec->autocfg.line_out_pins, on, false); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 591 | } |
| 592 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 593 | static void call_update_outputs(struct hda_codec *codec) |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 594 | { |
| 595 | struct alc_spec *spec = codec->spec; |
| 596 | if (spec->automute_hook) |
| 597 | spec->automute_hook(codec); |
| 598 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 599 | update_outputs(codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 600 | } |
| 601 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 602 | /* standard HP-automute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 603 | static void alc_hp_automute(struct hda_codec *codec) |
| 604 | { |
| 605 | struct alc_spec *spec = codec->spec; |
| 606 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 607 | spec->hp_jack_present = |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 608 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins), |
| 609 | spec->autocfg.hp_pins); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 610 | if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo)) |
Takashi Iwai | 3c715a9 | 2011-08-23 12:41:09 +0200 | [diff] [blame] | 611 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 612 | call_update_outputs(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 613 | } |
| 614 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 615 | /* standard line-out-automute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 616 | static void alc_line_automute(struct hda_codec *codec) |
| 617 | { |
| 618 | struct alc_spec *spec = codec->spec; |
| 619 | |
Takashi Iwai | e0d32e3 | 2011-09-26 15:19:55 +0200 | [diff] [blame] | 620 | /* check LO jack only when it's different from HP */ |
| 621 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0]) |
| 622 | return; |
| 623 | |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 624 | spec->line_jack_present = |
| 625 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
| 626 | spec->autocfg.line_out_pins); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 627 | if (!spec->automute_speaker || !spec->detect_lo) |
Takashi Iwai | 3c715a9 | 2011-08-23 12:41:09 +0200 | [diff] [blame] | 628 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 629 | call_update_outputs(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 630 | } |
| 631 | |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 632 | #define get_connection_index(codec, mux, nid) \ |
| 633 | snd_hda_get_conn_index(codec, mux, nid, 0) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 634 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 635 | /* standard mic auto-switch helper */ |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 636 | static void alc_mic_automute(struct hda_codec *codec) |
| 637 | { |
| 638 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 639 | hda_nid_t *pins = spec->imux_pins; |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 640 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 641 | if (!spec->auto_mic || !spec->auto_mic_valid_imux) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 642 | return; |
| 643 | if (snd_BUG_ON(!spec->adc_nids)) |
| 644 | return; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 645 | 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] | 646 | return; |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 647 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 648 | if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx])) |
| 649 | alc_mux_select(codec, 0, spec->ext_mic_idx, false); |
| 650 | else if (spec->dock_mic_idx >= 0 && |
| 651 | snd_hda_jack_detect(codec, pins[spec->dock_mic_idx])) |
| 652 | alc_mux_select(codec, 0, spec->dock_mic_idx, false); |
| 653 | else |
| 654 | alc_mux_select(codec, 0, spec->int_mic_idx, false); |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 655 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 656 | snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]); |
| 657 | if (spec->dock_mic_idx >= 0) |
| 658 | snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 659 | } |
| 660 | |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 661 | /* unsolicited event for HP jack sensing */ |
| 662 | static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res) |
| 663 | { |
| 664 | if (codec->vendor_id == 0x10ec0880) |
| 665 | res >>= 28; |
| 666 | else |
| 667 | res >>= 26; |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 668 | snd_hda_jack_set_dirty_all(codec); /* FIXME: to be more fine-grained */ |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 669 | switch (res) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 670 | case ALC_HP_EVENT: |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 671 | alc_hp_automute(codec); |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 672 | break; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 673 | case ALC_FRONT_EVENT: |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 674 | alc_line_automute(codec); |
| 675 | break; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 676 | case ALC_MIC_EVENT: |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 677 | alc_mic_automute(codec); |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 678 | break; |
| 679 | } |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame^] | 680 | snd_hda_jack_report_sync(codec); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 681 | } |
| 682 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 683 | /* call init functions of standard auto-mute helpers */ |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 684 | static void alc_inithook(struct hda_codec *codec) |
| 685 | { |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 686 | alc_hp_automute(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 687 | alc_line_automute(codec); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 688 | alc_mic_automute(codec); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 689 | } |
| 690 | |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 691 | /* additional initialization for ALC888 variants */ |
| 692 | static void alc888_coef_init(struct hda_codec *codec) |
| 693 | { |
| 694 | unsigned int tmp; |
| 695 | |
| 696 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0); |
| 697 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 698 | 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] | 699 | if ((tmp & 0xf0) == 0x20) |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 700 | /* alc888S-VC */ |
| 701 | snd_hda_codec_read(codec, 0x20, 0, |
| 702 | AC_VERB_SET_PROC_COEF, 0x830); |
| 703 | else |
| 704 | /* alc888-VB */ |
| 705 | snd_hda_codec_read(codec, 0x20, 0, |
| 706 | AC_VERB_SET_PROC_COEF, 0x3030); |
| 707 | } |
| 708 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 709 | /* additional initialization for ALC889 variants */ |
Jaroslav Kysela | 87a8c37 | 2009-07-23 10:58:29 +0200 | [diff] [blame] | 710 | static void alc889_coef_init(struct hda_codec *codec) |
| 711 | { |
| 712 | unsigned int tmp; |
| 713 | |
| 714 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 715 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 716 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 717 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010); |
| 718 | } |
| 719 | |
Takashi Iwai | 3fb4a50 | 2010-01-19 15:46:37 +0100 | [diff] [blame] | 720 | /* turn on/off EAPD control (only if available) */ |
| 721 | static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on) |
| 722 | { |
| 723 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) |
| 724 | return; |
| 725 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) |
| 726 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE, |
| 727 | on ? 2 : 0); |
| 728 | } |
| 729 | |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 730 | /* turn on/off EAPD controls of the codec */ |
| 731 | static void alc_auto_setup_eapd(struct hda_codec *codec, bool on) |
| 732 | { |
| 733 | /* We currently only handle front, HP */ |
Takashi Iwai | 39fa84e | 2011-06-27 15:28:57 +0200 | [diff] [blame] | 734 | static hda_nid_t pins[] = { |
| 735 | 0x0f, 0x10, 0x14, 0x15, 0 |
| 736 | }; |
| 737 | hda_nid_t *p; |
| 738 | for (p = pins; *p; p++) |
| 739 | set_eapd(codec, *p, on); |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 740 | } |
| 741 | |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 742 | /* generic shutup callback; |
| 743 | * just turning off EPAD and a little pause for avoiding pop-noise |
| 744 | */ |
| 745 | static void alc_eapd_shutup(struct hda_codec *codec) |
| 746 | { |
| 747 | alc_auto_setup_eapd(codec, false); |
| 748 | msleep(200); |
| 749 | } |
| 750 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 751 | /* generic EAPD initialization */ |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 752 | static void alc_auto_init_amp(struct hda_codec *codec, int type) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 753 | { |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 754 | unsigned int tmp; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 755 | |
Takashi Iwai | 39fa84e | 2011-06-27 15:28:57 +0200 | [diff] [blame] | 756 | alc_auto_setup_eapd(codec, true); |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 757 | switch (type) { |
| 758 | case ALC_INIT_GPIO1: |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 759 | snd_hda_sequence_write(codec, alc_gpio1_init_verbs); |
| 760 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 761 | case ALC_INIT_GPIO2: |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 762 | snd_hda_sequence_write(codec, alc_gpio2_init_verbs); |
| 763 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 764 | case ALC_INIT_GPIO3: |
Kailang Yang | bdd148a | 2007-05-08 15:19:08 +0200 | [diff] [blame] | 765 | snd_hda_sequence_write(codec, alc_gpio3_init_verbs); |
| 766 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 767 | case ALC_INIT_DEFAULT: |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 768 | switch (codec->vendor_id) { |
| 769 | case 0x10ec0260: |
| 770 | snd_hda_codec_write(codec, 0x1a, 0, |
| 771 | AC_VERB_SET_COEF_INDEX, 7); |
| 772 | tmp = snd_hda_codec_read(codec, 0x1a, 0, |
| 773 | AC_VERB_GET_PROC_COEF, 0); |
| 774 | snd_hda_codec_write(codec, 0x1a, 0, |
| 775 | AC_VERB_SET_COEF_INDEX, 7); |
| 776 | snd_hda_codec_write(codec, 0x1a, 0, |
| 777 | AC_VERB_SET_PROC_COEF, |
| 778 | tmp | 0x2010); |
| 779 | break; |
| 780 | case 0x10ec0262: |
| 781 | case 0x10ec0880: |
| 782 | case 0x10ec0882: |
| 783 | case 0x10ec0883: |
| 784 | case 0x10ec0885: |
Takashi Iwai | 4a5a4c5 | 2009-02-06 12:46:59 +0100 | [diff] [blame] | 785 | case 0x10ec0887: |
Takashi Iwai | 20b67dd | 2011-03-23 22:54:32 +0100 | [diff] [blame] | 786 | /*case 0x10ec0889:*/ /* this causes an SPDIF problem */ |
Jaroslav Kysela | 87a8c37 | 2009-07-23 10:58:29 +0200 | [diff] [blame] | 787 | alc889_coef_init(codec); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 788 | break; |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 789 | case 0x10ec0888: |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 790 | alc888_coef_init(codec); |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 791 | break; |
Takashi Iwai | 0aea778 | 2010-01-25 15:44:11 +0100 | [diff] [blame] | 792 | #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] | 793 | case 0x10ec0267: |
| 794 | case 0x10ec0268: |
| 795 | snd_hda_codec_write(codec, 0x20, 0, |
| 796 | AC_VERB_SET_COEF_INDEX, 7); |
| 797 | tmp = snd_hda_codec_read(codec, 0x20, 0, |
| 798 | AC_VERB_GET_PROC_COEF, 0); |
| 799 | snd_hda_codec_write(codec, 0x20, 0, |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 800 | AC_VERB_SET_COEF_INDEX, 7); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 801 | snd_hda_codec_write(codec, 0x20, 0, |
| 802 | AC_VERB_SET_PROC_COEF, |
| 803 | tmp | 0x3000); |
| 804 | break; |
Takashi Iwai | 0aea778 | 2010-01-25 15:44:11 +0100 | [diff] [blame] | 805 | #endif /* XXX */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 806 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 807 | break; |
| 808 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 809 | } |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 810 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 811 | /* |
| 812 | * Auto-Mute mode mixer enum support |
| 813 | */ |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 814 | static int alc_automute_mode_info(struct snd_kcontrol *kcontrol, |
| 815 | struct snd_ctl_elem_info *uinfo) |
| 816 | { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 817 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 818 | struct alc_spec *spec = codec->spec; |
| 819 | static const char * const texts2[] = { |
| 820 | "Disabled", "Enabled" |
| 821 | }; |
| 822 | static const char * const texts3[] = { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 823 | "Disabled", "Speaker Only", "Line-Out+Speaker" |
| 824 | }; |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 825 | const char * const *texts; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 826 | |
| 827 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 828 | uinfo->count = 1; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 829 | if (spec->automute_speaker_possible && spec->automute_lo_possible) { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 830 | uinfo->value.enumerated.items = 3; |
| 831 | texts = texts3; |
| 832 | } else { |
| 833 | uinfo->value.enumerated.items = 2; |
| 834 | texts = texts2; |
| 835 | } |
| 836 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 837 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 838 | strcpy(uinfo->value.enumerated.name, |
| 839 | texts[uinfo->value.enumerated.item]); |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | static int alc_automute_mode_get(struct snd_kcontrol *kcontrol, |
| 844 | struct snd_ctl_elem_value *ucontrol) |
| 845 | { |
| 846 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 847 | struct alc_spec *spec = codec->spec; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 848 | unsigned int val = 0; |
| 849 | if (spec->automute_speaker) |
| 850 | val++; |
| 851 | if (spec->automute_lo) |
| 852 | val++; |
| 853 | |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 854 | ucontrol->value.enumerated.item[0] = val; |
| 855 | return 0; |
| 856 | } |
| 857 | |
| 858 | static int alc_automute_mode_put(struct snd_kcontrol *kcontrol, |
| 859 | struct snd_ctl_elem_value *ucontrol) |
| 860 | { |
| 861 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 862 | struct alc_spec *spec = codec->spec; |
| 863 | |
| 864 | switch (ucontrol->value.enumerated.item[0]) { |
| 865 | case 0: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 866 | if (!spec->automute_speaker && !spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 867 | return 0; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 868 | spec->automute_speaker = 0; |
| 869 | spec->automute_lo = 0; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 870 | break; |
| 871 | case 1: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 872 | if (spec->automute_speaker_possible) { |
| 873 | if (!spec->automute_lo && spec->automute_speaker) |
| 874 | return 0; |
| 875 | spec->automute_speaker = 1; |
| 876 | spec->automute_lo = 0; |
| 877 | } else if (spec->automute_lo_possible) { |
| 878 | if (spec->automute_lo) |
| 879 | return 0; |
| 880 | spec->automute_lo = 1; |
| 881 | } else |
| 882 | return -EINVAL; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 883 | break; |
| 884 | case 2: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 885 | if (!spec->automute_lo_possible || !spec->automute_speaker_possible) |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 886 | return -EINVAL; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 887 | if (spec->automute_speaker && spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 888 | return 0; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 889 | spec->automute_speaker = 1; |
| 890 | spec->automute_lo = 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 891 | break; |
| 892 | default: |
| 893 | return -EINVAL; |
| 894 | } |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 895 | call_update_outputs(codec); |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 896 | return 1; |
| 897 | } |
| 898 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 899 | static const struct snd_kcontrol_new alc_automute_mode_enum = { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 900 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 901 | .name = "Auto-Mute Mode", |
| 902 | .info = alc_automute_mode_info, |
| 903 | .get = alc_automute_mode_get, |
| 904 | .put = alc_automute_mode_put, |
| 905 | }; |
| 906 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 907 | static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec) |
| 908 | { |
| 909 | snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32); |
| 910 | return snd_array_new(&spec->kctls); |
| 911 | } |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 912 | |
| 913 | static int alc_add_automute_mode_enum(struct hda_codec *codec) |
| 914 | { |
| 915 | struct alc_spec *spec = codec->spec; |
| 916 | struct snd_kcontrol_new *knew; |
| 917 | |
| 918 | knew = alc_kcontrol_new(spec); |
| 919 | if (!knew) |
| 920 | return -ENOMEM; |
| 921 | *knew = alc_automute_mode_enum; |
| 922 | knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL); |
| 923 | if (!knew->name) |
| 924 | return -ENOMEM; |
| 925 | return 0; |
| 926 | } |
| 927 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 928 | /* |
| 929 | * Check the availability of HP/line-out auto-mute; |
| 930 | * Set up appropriately if really supported |
| 931 | */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 932 | static void alc_init_automute(struct hda_codec *codec) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 933 | { |
| 934 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 935 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 1daf5f4 | 2011-04-28 17:57:46 +0200 | [diff] [blame] | 936 | int present = 0; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 937 | int i; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 938 | |
Takashi Iwai | 1daf5f4 | 2011-04-28 17:57:46 +0200 | [diff] [blame] | 939 | if (cfg->hp_pins[0]) |
| 940 | present++; |
| 941 | if (cfg->line_out_pins[0]) |
| 942 | present++; |
| 943 | if (cfg->speaker_pins[0]) |
| 944 | present++; |
| 945 | if (present < 2) /* need two different output types */ |
| 946 | return; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 947 | |
Takashi Iwai | c48a8fb | 2011-07-27 16:41:57 +0200 | [diff] [blame] | 948 | if (!cfg->speaker_pins[0] && |
| 949 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 950 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 951 | sizeof(cfg->speaker_pins)); |
| 952 | cfg->speaker_outs = cfg->line_outs; |
| 953 | } |
| 954 | |
Takashi Iwai | c48a8fb | 2011-07-27 16:41:57 +0200 | [diff] [blame] | 955 | if (!cfg->hp_pins[0] && |
| 956 | cfg->line_out_type == AUTO_PIN_HP_OUT) { |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 957 | memcpy(cfg->hp_pins, cfg->line_out_pins, |
| 958 | sizeof(cfg->hp_pins)); |
| 959 | cfg->hp_outs = cfg->line_outs; |
| 960 | } |
| 961 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 962 | spec->automute_mode = ALC_AUTOMUTE_PIN; |
| 963 | |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 964 | for (i = 0; i < cfg->hp_outs; i++) { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 965 | hda_nid_t nid = cfg->hp_pins[i]; |
Takashi Iwai | 06dec22 | 2011-05-17 10:00:16 +0200 | [diff] [blame] | 966 | if (!is_jack_detectable(codec, nid)) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 967 | continue; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 968 | snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n", |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 969 | nid); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 970 | snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 971 | spec->detect_hp = 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 972 | } |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 973 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 974 | if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) { |
| 975 | if (cfg->speaker_outs) |
| 976 | for (i = 0; i < cfg->line_outs; i++) { |
| 977 | hda_nid_t nid = cfg->line_out_pins[i]; |
| 978 | if (!is_jack_detectable(codec, nid)) |
| 979 | continue; |
| 980 | snd_printdd("realtek: Enable Line-Out " |
| 981 | "auto-muting on NID 0x%x\n", nid); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 982 | snd_hda_jack_detect_enable(codec, nid, |
| 983 | ALC_FRONT_EVENT); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 984 | spec->detect_lo = 1; |
| 985 | } |
| 986 | spec->automute_lo_possible = spec->detect_hp; |
| 987 | } |
| 988 | |
| 989 | spec->automute_speaker_possible = cfg->speaker_outs && |
| 990 | (spec->detect_hp || spec->detect_lo); |
| 991 | |
| 992 | spec->automute_lo = spec->automute_lo_possible; |
| 993 | spec->automute_speaker = spec->automute_speaker_possible; |
| 994 | |
| 995 | if (spec->automute_speaker_possible || spec->automute_lo_possible) { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 996 | /* create a control for automute mode */ |
| 997 | alc_add_automute_mode_enum(codec); |
| 998 | spec->unsol_event = alc_sku_unsol_event; |
| 999 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1000 | } |
| 1001 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1002 | /* 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] | 1003 | static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 1004 | { |
| 1005 | int i; |
| 1006 | for (i = 0; i < nums; i++) |
| 1007 | if (list[i] == nid) |
| 1008 | return i; |
| 1009 | return -1; |
| 1010 | } |
| 1011 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1012 | /* check whether dynamic ADC-switching is available */ |
| 1013 | static bool alc_check_dyn_adc_switch(struct hda_codec *codec) |
| 1014 | { |
| 1015 | struct alc_spec *spec = codec->spec; |
| 1016 | struct hda_input_mux *imux = &spec->private_imux[0]; |
| 1017 | int i, n, idx; |
| 1018 | hda_nid_t cap, pin; |
| 1019 | |
| 1020 | if (imux != spec->input_mux) /* no dynamic imux? */ |
| 1021 | return false; |
| 1022 | |
| 1023 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 1024 | cap = spec->private_capsrc_nids[n]; |
| 1025 | for (i = 0; i < imux->num_items; i++) { |
| 1026 | pin = spec->imux_pins[i]; |
| 1027 | if (!pin) |
| 1028 | return false; |
| 1029 | if (get_connection_index(codec, cap, pin) < 0) |
| 1030 | break; |
| 1031 | } |
| 1032 | if (i >= imux->num_items) |
Takashi Iwai | 268ff6f | 2011-07-08 14:37:35 +0200 | [diff] [blame] | 1033 | return true; /* no ADC-switch is needed */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | for (i = 0; i < imux->num_items; i++) { |
| 1037 | pin = spec->imux_pins[i]; |
| 1038 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 1039 | cap = spec->private_capsrc_nids[n]; |
| 1040 | idx = get_connection_index(codec, cap, pin); |
| 1041 | if (idx >= 0) { |
| 1042 | imux->items[i].index = idx; |
| 1043 | spec->dyn_adc_idx[i] = n; |
| 1044 | break; |
| 1045 | } |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | snd_printdd("realtek: enabling ADC switching\n"); |
| 1050 | spec->dyn_adc_switch = 1; |
| 1051 | return true; |
| 1052 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1053 | |
| 1054 | /* rebuild imux for matching with the given auto-mic pins (if not yet) */ |
| 1055 | static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec) |
| 1056 | { |
| 1057 | struct alc_spec *spec = codec->spec; |
| 1058 | struct hda_input_mux *imux; |
| 1059 | static char * const texts[3] = { |
| 1060 | "Mic", "Internal Mic", "Dock Mic" |
| 1061 | }; |
| 1062 | int i; |
| 1063 | |
| 1064 | if (!spec->auto_mic) |
| 1065 | return false; |
| 1066 | imux = &spec->private_imux[0]; |
| 1067 | if (spec->input_mux == imux) |
| 1068 | return true; |
| 1069 | spec->imux_pins[0] = spec->ext_mic_pin; |
| 1070 | spec->imux_pins[1] = spec->int_mic_pin; |
| 1071 | spec->imux_pins[2] = spec->dock_mic_pin; |
| 1072 | for (i = 0; i < 3; i++) { |
| 1073 | strcpy(imux->items[i].label, texts[i]); |
| 1074 | if (spec->imux_pins[i]) |
| 1075 | imux->num_items = i + 1; |
| 1076 | } |
| 1077 | spec->num_mux_defs = 1; |
| 1078 | spec->input_mux = imux; |
| 1079 | return true; |
| 1080 | } |
| 1081 | |
| 1082 | /* check whether all auto-mic pins are valid; setup indices if OK */ |
| 1083 | static bool alc_auto_mic_check_imux(struct hda_codec *codec) |
| 1084 | { |
| 1085 | struct alc_spec *spec = codec->spec; |
| 1086 | const struct hda_input_mux *imux; |
| 1087 | |
| 1088 | if (!spec->auto_mic) |
| 1089 | return false; |
| 1090 | if (spec->auto_mic_valid_imux) |
| 1091 | return true; /* already checked */ |
| 1092 | |
| 1093 | /* fill up imux indices */ |
| 1094 | if (!alc_check_dyn_adc_switch(codec)) { |
| 1095 | spec->auto_mic = 0; |
| 1096 | return false; |
| 1097 | } |
| 1098 | |
| 1099 | imux = spec->input_mux; |
| 1100 | spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin, |
| 1101 | spec->imux_pins, imux->num_items); |
| 1102 | spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin, |
| 1103 | spec->imux_pins, imux->num_items); |
| 1104 | spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin, |
| 1105 | spec->imux_pins, imux->num_items); |
| 1106 | if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) { |
| 1107 | spec->auto_mic = 0; |
| 1108 | return false; /* no corresponding imux */ |
| 1109 | } |
| 1110 | |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 1111 | snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1112 | if (spec->dock_mic_pin) |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 1113 | snd_hda_jack_detect_enable(codec, spec->dock_mic_pin, |
| 1114 | ALC_MIC_EVENT); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1115 | |
| 1116 | spec->auto_mic_valid_imux = 1; |
| 1117 | spec->auto_mic = 1; |
| 1118 | return true; |
| 1119 | } |
| 1120 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1121 | /* |
| 1122 | * Check the availability of auto-mic switch; |
| 1123 | * Set up if really supported |
| 1124 | */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1125 | static void alc_init_auto_mic(struct hda_codec *codec) |
| 1126 | { |
| 1127 | struct alc_spec *spec = codec->spec; |
| 1128 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1129 | hda_nid_t fixed, ext, dock; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1130 | int i; |
| 1131 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 1132 | if (spec->shared_mic_hp) |
| 1133 | return; /* no auto-mic for the shared I/O */ |
| 1134 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1135 | spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1; |
| 1136 | |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1137 | fixed = ext = dock = 0; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 1138 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1139 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1140 | unsigned int defcfg; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1141 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1142 | switch (snd_hda_get_input_pin_attr(defcfg)) { |
| 1143 | case INPUT_PIN_ATTR_INT: |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1144 | if (fixed) |
| 1145 | return; /* already occupied */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1146 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 1147 | return; /* invalid type */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1148 | fixed = nid; |
| 1149 | break; |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1150 | case INPUT_PIN_ATTR_UNUSED: |
| 1151 | return; /* invalid entry */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1152 | case INPUT_PIN_ATTR_DOCK: |
| 1153 | if (dock) |
| 1154 | return; /* already occupied */ |
| 1155 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) |
| 1156 | return; /* invalid type */ |
| 1157 | dock = nid; |
| 1158 | break; |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1159 | default: |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1160 | if (ext) |
| 1161 | return; /* already occupied */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1162 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 1163 | return; /* invalid type */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1164 | ext = nid; |
| 1165 | break; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1166 | } |
| 1167 | } |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1168 | if (!ext && dock) { |
| 1169 | ext = dock; |
| 1170 | dock = 0; |
| 1171 | } |
Takashi Iwai | eaa9b3a | 2010-01-17 13:09:33 +0100 | [diff] [blame] | 1172 | if (!ext || !fixed) |
| 1173 | return; |
Takashi Iwai | e35d9d6 | 2011-05-17 11:28:16 +0200 | [diff] [blame] | 1174 | if (!is_jack_detectable(codec, ext)) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1175 | return; /* no unsol support */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1176 | if (dock && !is_jack_detectable(codec, dock)) |
| 1177 | return; /* no unsol support */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1178 | |
| 1179 | /* check imux indices */ |
| 1180 | spec->ext_mic_pin = ext; |
| 1181 | spec->int_mic_pin = fixed; |
| 1182 | spec->dock_mic_pin = dock; |
| 1183 | |
| 1184 | spec->auto_mic = 1; |
| 1185 | if (!alc_auto_mic_check_imux(codec)) |
| 1186 | return; |
| 1187 | |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1188 | snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n", |
| 1189 | ext, fixed, dock); |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1190 | spec->unsol_event = alc_sku_unsol_event; |
| 1191 | } |
| 1192 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1193 | /* check the availabilities of auto-mute and auto-mic switches */ |
| 1194 | static void alc_auto_check_switches(struct hda_codec *codec) |
| 1195 | { |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 1196 | alc_init_automute(codec); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1197 | alc_init_auto_mic(codec); |
| 1198 | } |
| 1199 | |
| 1200 | /* |
| 1201 | * Realtek SSID verification |
| 1202 | */ |
| 1203 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1204 | /* Could be any non-zero and even value. When used as fixup, tells |
| 1205 | * the driver to ignore any present sku defines. |
| 1206 | */ |
| 1207 | #define ALC_FIXUP_SKU_IGNORE (2) |
| 1208 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1209 | static int alc_auto_parse_customize_define(struct hda_codec *codec) |
| 1210 | { |
| 1211 | unsigned int ass, tmp, i; |
Takashi Iwai | 7fb5622 | 2010-03-22 17:09:47 +0100 | [diff] [blame] | 1212 | unsigned nid = 0; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1213 | struct alc_spec *spec = codec->spec; |
| 1214 | |
Takashi Iwai | b6cbe51 | 2010-07-28 17:43:36 +0200 | [diff] [blame] | 1215 | spec->cdefine.enable_pcbeep = 1; /* assume always enabled */ |
| 1216 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1217 | if (spec->cdefine.fixup) { |
| 1218 | ass = spec->cdefine.sku_cfg; |
| 1219 | if (ass == ALC_FIXUP_SKU_IGNORE) |
| 1220 | return -1; |
| 1221 | goto do_sku; |
| 1222 | } |
| 1223 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1224 | ass = codec->subsystem_id & 0xffff; |
Takashi Iwai | b6cbe51 | 2010-07-28 17:43:36 +0200 | [diff] [blame] | 1225 | if (ass != codec->bus->pci->subsystem_device && (ass & 1)) |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1226 | goto do_sku; |
| 1227 | |
| 1228 | nid = 0x1d; |
| 1229 | if (codec->vendor_id == 0x10ec0260) |
| 1230 | nid = 0x17; |
| 1231 | ass = snd_hda_codec_get_pincfg(codec, nid); |
| 1232 | |
| 1233 | if (!(ass & 1)) { |
| 1234 | printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n", |
| 1235 | codec->chip_name, ass); |
| 1236 | return -1; |
| 1237 | } |
| 1238 | |
| 1239 | /* check sum */ |
| 1240 | tmp = 0; |
| 1241 | for (i = 1; i < 16; i++) { |
| 1242 | if ((ass >> i) & 1) |
| 1243 | tmp++; |
| 1244 | } |
| 1245 | if (((ass >> 16) & 0xf) != tmp) |
| 1246 | return -1; |
| 1247 | |
| 1248 | spec->cdefine.port_connectivity = ass >> 30; |
| 1249 | spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20; |
| 1250 | spec->cdefine.check_sum = (ass >> 16) & 0xf; |
| 1251 | spec->cdefine.customization = ass >> 8; |
| 1252 | do_sku: |
| 1253 | spec->cdefine.sku_cfg = ass; |
| 1254 | spec->cdefine.external_amp = (ass & 0x38) >> 3; |
| 1255 | spec->cdefine.platform_type = (ass & 0x4) >> 2; |
| 1256 | spec->cdefine.swap = (ass & 0x2) >> 1; |
| 1257 | spec->cdefine.override = ass & 0x1; |
| 1258 | |
| 1259 | snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n", |
| 1260 | nid, spec->cdefine.sku_cfg); |
| 1261 | snd_printd("SKU: port_connectivity=0x%x\n", |
| 1262 | spec->cdefine.port_connectivity); |
| 1263 | snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep); |
| 1264 | snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum); |
| 1265 | snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization); |
| 1266 | snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp); |
| 1267 | snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type); |
| 1268 | snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap); |
| 1269 | snd_printd("SKU: override=0x%x\n", spec->cdefine.override); |
| 1270 | |
| 1271 | return 0; |
| 1272 | } |
| 1273 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1274 | /* return true if the given NID is found in the list */ |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1275 | static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 1276 | { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1277 | return find_idx_in_nid_list(nid, list, nums) >= 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1278 | } |
| 1279 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1280 | /* check subsystem ID and set up device-specific initialization; |
| 1281 | * return 1 if initialized, 0 if invalid SSID |
| 1282 | */ |
| 1283 | /* 32-bit subsystem ID for BIOS loading in HD Audio codec. |
| 1284 | * 31 ~ 16 : Manufacture ID |
| 1285 | * 15 ~ 8 : SKU ID |
| 1286 | * 7 ~ 0 : Assembly ID |
| 1287 | * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36 |
| 1288 | */ |
| 1289 | static int alc_subsystem_id(struct hda_codec *codec, |
| 1290 | hda_nid_t porta, hda_nid_t porte, |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1291 | hda_nid_t portd, hda_nid_t porti) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1292 | { |
| 1293 | unsigned int ass, tmp, i; |
| 1294 | unsigned nid; |
| 1295 | struct alc_spec *spec = codec->spec; |
| 1296 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1297 | if (spec->cdefine.fixup) { |
| 1298 | ass = spec->cdefine.sku_cfg; |
| 1299 | if (ass == ALC_FIXUP_SKU_IGNORE) |
| 1300 | return 0; |
| 1301 | goto do_sku; |
| 1302 | } |
| 1303 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1304 | ass = codec->subsystem_id & 0xffff; |
| 1305 | if ((ass != codec->bus->pci->subsystem_device) && (ass & 1)) |
| 1306 | goto do_sku; |
| 1307 | |
| 1308 | /* invalid SSID, check the special NID pin defcfg instead */ |
| 1309 | /* |
Sasha Alexandr | def319f | 2009-06-16 16:00:15 -0400 | [diff] [blame] | 1310 | * 31~30 : port connectivity |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1311 | * 29~21 : reserve |
| 1312 | * 20 : PCBEEP input |
| 1313 | * 19~16 : Check sum (15:1) |
| 1314 | * 15~1 : Custom |
| 1315 | * 0 : override |
| 1316 | */ |
| 1317 | nid = 0x1d; |
| 1318 | if (codec->vendor_id == 0x10ec0260) |
| 1319 | nid = 0x17; |
| 1320 | ass = snd_hda_codec_get_pincfg(codec, nid); |
| 1321 | snd_printd("realtek: No valid SSID, " |
| 1322 | "checking pincfg 0x%08x for NID 0x%x\n", |
Takashi Iwai | cb6605c | 2009-04-28 13:03:19 +0200 | [diff] [blame] | 1323 | ass, nid); |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1324 | if (!(ass & 1)) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1325 | return 0; |
| 1326 | if ((ass >> 30) != 1) /* no physical connection */ |
| 1327 | return 0; |
| 1328 | |
| 1329 | /* check sum */ |
| 1330 | tmp = 0; |
| 1331 | for (i = 1; i < 16; i++) { |
| 1332 | if ((ass >> i) & 1) |
| 1333 | tmp++; |
| 1334 | } |
| 1335 | if (((ass >> 16) & 0xf) != tmp) |
| 1336 | return 0; |
| 1337 | do_sku: |
| 1338 | snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n", |
| 1339 | ass & 0xffff, codec->vendor_id); |
| 1340 | /* |
| 1341 | * 0 : override |
| 1342 | * 1 : Swap Jack |
| 1343 | * 2 : 0 --> Desktop, 1 --> Laptop |
| 1344 | * 3~5 : External Amplifier control |
| 1345 | * 7~6 : Reserved |
| 1346 | */ |
| 1347 | tmp = (ass & 0x38) >> 3; /* external Amp control */ |
| 1348 | switch (tmp) { |
| 1349 | case 1: |
| 1350 | spec->init_amp = ALC_INIT_GPIO1; |
| 1351 | break; |
| 1352 | case 3: |
| 1353 | spec->init_amp = ALC_INIT_GPIO2; |
| 1354 | break; |
| 1355 | case 7: |
| 1356 | spec->init_amp = ALC_INIT_GPIO3; |
| 1357 | break; |
| 1358 | case 5: |
Takashi Iwai | 5a8cfb4 | 2010-11-26 17:11:18 +0100 | [diff] [blame] | 1359 | default: |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1360 | spec->init_amp = ALC_INIT_DEFAULT; |
| 1361 | break; |
| 1362 | } |
| 1363 | |
| 1364 | /* is laptop or Desktop and enable the function "Mute internal speaker |
| 1365 | * when the external headphone out jack is plugged" |
| 1366 | */ |
| 1367 | if (!(ass & 0x8000)) |
| 1368 | return 1; |
| 1369 | /* |
| 1370 | * 10~8 : Jack location |
| 1371 | * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered |
| 1372 | * 14~13: Resvered |
| 1373 | * 15 : 1 --> enable the function "Mute internal speaker |
| 1374 | * when the external headphone out jack is plugged" |
| 1375 | */ |
Takashi Iwai | 5fe6e01 | 2011-09-26 10:41:21 +0200 | [diff] [blame] | 1376 | if (!spec->autocfg.hp_pins[0] && |
| 1377 | !(spec->autocfg.line_out_pins[0] && |
| 1378 | spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) { |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1379 | hda_nid_t nid; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1380 | tmp = (ass >> 11) & 0x3; /* HP to chassis */ |
| 1381 | if (tmp == 0) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1382 | nid = porta; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1383 | else if (tmp == 1) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1384 | nid = porte; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1385 | else if (tmp == 2) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1386 | nid = portd; |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1387 | else if (tmp == 3) |
| 1388 | nid = porti; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1389 | else |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1390 | return 1; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1391 | if (found_in_nid_list(nid, spec->autocfg.line_out_pins, |
| 1392 | spec->autocfg.line_outs)) |
| 1393 | return 1; |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1394 | spec->autocfg.hp_pins[0] = nid; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1395 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1396 | return 1; |
| 1397 | } |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 1398 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 1399 | /* Check the validity of ALC subsystem-id |
| 1400 | * ports contains an array of 4 pin NIDs for port-A, E, D and I */ |
| 1401 | 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] | 1402 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 1403 | 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] | 1404 | struct alc_spec *spec = codec->spec; |
| 1405 | snd_printd("realtek: " |
| 1406 | "Enable default setup for auto mode as fallback\n"); |
| 1407 | spec->init_amp = ALC_INIT_DEFAULT; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1408 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1409 | } |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 1410 | |
Takashi Iwai | 41e41f1 | 2005-06-08 14:48:49 +0200 | [diff] [blame] | 1411 | /* |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1412 | * Fix-up pin default configurations and add default verbs |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1413 | */ |
| 1414 | |
| 1415 | struct alc_pincfg { |
| 1416 | hda_nid_t nid; |
| 1417 | u32 val; |
| 1418 | }; |
| 1419 | |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1420 | struct alc_model_fixup { |
| 1421 | const int id; |
| 1422 | const char *name; |
| 1423 | }; |
| 1424 | |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1425 | struct alc_fixup { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1426 | int type; |
Takashi Iwai | 361fe6e | 2011-01-14 09:55:32 +0100 | [diff] [blame] | 1427 | bool chained; |
| 1428 | int chain_id; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1429 | union { |
| 1430 | unsigned int sku; |
| 1431 | const struct alc_pincfg *pins; |
| 1432 | const struct hda_verb *verbs; |
| 1433 | void (*func)(struct hda_codec *codec, |
| 1434 | const struct alc_fixup *fix, |
| 1435 | int action); |
| 1436 | } v; |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1437 | }; |
| 1438 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1439 | enum { |
| 1440 | ALC_FIXUP_INVALID, |
| 1441 | ALC_FIXUP_SKU, |
| 1442 | ALC_FIXUP_PINS, |
| 1443 | ALC_FIXUP_VERBS, |
| 1444 | ALC_FIXUP_FUNC, |
| 1445 | }; |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1446 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1447 | enum { |
| 1448 | ALC_FIXUP_ACT_PRE_PROBE, |
| 1449 | ALC_FIXUP_ACT_PROBE, |
Takashi Iwai | 5870112 | 2011-01-13 15:41:45 +0100 | [diff] [blame] | 1450 | ALC_FIXUP_ACT_INIT, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1451 | }; |
| 1452 | |
| 1453 | static void alc_apply_fixup(struct hda_codec *codec, int action) |
| 1454 | { |
| 1455 | struct alc_spec *spec = codec->spec; |
| 1456 | int id = spec->fixup_id; |
Takashi Iwai | aa1d0c5 | 2011-01-19 17:27:58 +0100 | [diff] [blame] | 1457 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1458 | const char *modelname = spec->fixup_name; |
Takashi Iwai | aa1d0c5 | 2011-01-19 17:27:58 +0100 | [diff] [blame] | 1459 | #endif |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1460 | int depth = 0; |
| 1461 | |
| 1462 | if (!spec->fixup_list) |
| 1463 | return; |
| 1464 | |
| 1465 | while (id >= 0) { |
| 1466 | const struct alc_fixup *fix = spec->fixup_list + id; |
| 1467 | const struct alc_pincfg *cfg; |
| 1468 | |
| 1469 | switch (fix->type) { |
| 1470 | case ALC_FIXUP_SKU: |
| 1471 | if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku) |
Jesper Juhl | e53de8f | 2011-11-13 23:11:50 +0100 | [diff] [blame] | 1472 | break; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1473 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1474 | "Apply sku override for %s\n", |
| 1475 | codec->chip_name, modelname); |
| 1476 | spec->cdefine.sku_cfg = fix->v.sku; |
| 1477 | spec->cdefine.fixup = 1; |
| 1478 | break; |
| 1479 | case ALC_FIXUP_PINS: |
| 1480 | cfg = fix->v.pins; |
| 1481 | if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg) |
| 1482 | break; |
| 1483 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1484 | "Apply pincfg for %s\n", |
| 1485 | codec->chip_name, modelname); |
| 1486 | for (; cfg->nid; cfg++) |
| 1487 | snd_hda_codec_set_pincfg(codec, cfg->nid, |
| 1488 | cfg->val); |
| 1489 | break; |
| 1490 | case ALC_FIXUP_VERBS: |
| 1491 | if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs) |
| 1492 | break; |
| 1493 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1494 | "Apply fix-verbs for %s\n", |
| 1495 | codec->chip_name, modelname); |
| 1496 | add_verb(codec->spec, fix->v.verbs); |
| 1497 | break; |
| 1498 | case ALC_FIXUP_FUNC: |
| 1499 | if (!fix->v.func) |
| 1500 | break; |
| 1501 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1502 | "Apply fix-func for %s\n", |
| 1503 | codec->chip_name, modelname); |
| 1504 | fix->v.func(codec, fix, action); |
| 1505 | break; |
| 1506 | default: |
| 1507 | snd_printk(KERN_ERR "hda_codec: %s: " |
| 1508 | "Invalid fixup type %d\n", |
| 1509 | codec->chip_name, fix->type); |
| 1510 | break; |
| 1511 | } |
Takashi Iwai | 24af2b1 | 2011-05-02 13:55:36 +0200 | [diff] [blame] | 1512 | if (!fix->chained) |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1513 | break; |
| 1514 | if (++depth > 10) |
| 1515 | break; |
Takashi Iwai | 24af2b1 | 2011-05-02 13:55:36 +0200 | [diff] [blame] | 1516 | id = fix->chain_id; |
Takashi Iwai | 9d57883 | 2010-11-22 13:29:19 +0100 | [diff] [blame] | 1517 | } |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1518 | } |
| 1519 | |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1520 | static void alc_pick_fixup(struct hda_codec *codec, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1521 | const struct alc_model_fixup *models, |
| 1522 | const struct snd_pci_quirk *quirk, |
| 1523 | const struct alc_fixup *fixlist) |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1524 | { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1525 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 596830e | 2011-11-09 15:06:45 +0100 | [diff] [blame] | 1526 | const struct snd_pci_quirk *q; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 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) { |
Takashi Iwai | 596830e | 2011-11-09 15:06:45 +0100 | [diff] [blame] | 1541 | q = snd_pci_quirk_lookup(codec->bus->pci, quirk); |
| 1542 | if (q) { |
| 1543 | id = q->value; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1544 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
Takashi Iwai | 596830e | 2011-11-09 15:06:45 +0100 | [diff] [blame] | 1545 | name = q->name; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1546 | #endif |
| 1547 | } |
| 1548 | } |
Takashi Iwai | 596830e | 2011-11-09 15:06:45 +0100 | [diff] [blame] | 1549 | if (id < 0) { |
| 1550 | for (q = quirk; q->subvendor; q++) { |
| 1551 | unsigned int vendorid = |
| 1552 | q->subdevice | (q->subvendor << 16); |
| 1553 | if (vendorid == codec->subsystem_id) { |
| 1554 | id = q->value; |
| 1555 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
| 1556 | name = q->name; |
| 1557 | #endif |
| 1558 | break; |
| 1559 | } |
| 1560 | } |
| 1561 | } |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1562 | |
| 1563 | spec->fixup_id = id; |
| 1564 | if (id >= 0) { |
| 1565 | spec->fixup_list = fixlist; |
| 1566 | spec->fixup_name = name; |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1567 | } |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1568 | } |
| 1569 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1570 | /* |
| 1571 | * COEF access helper functions |
| 1572 | */ |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 1573 | static int alc_read_coef_idx(struct hda_codec *codec, |
| 1574 | unsigned int coef_idx) |
| 1575 | { |
| 1576 | unsigned int val; |
| 1577 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, |
| 1578 | coef_idx); |
| 1579 | val = snd_hda_codec_read(codec, 0x20, 0, |
| 1580 | AC_VERB_GET_PROC_COEF, 0); |
| 1581 | return val; |
| 1582 | } |
| 1583 | |
Kailang Yang | 977ddd6 | 2010-09-15 10:02:29 +0200 | [diff] [blame] | 1584 | static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx, |
| 1585 | unsigned int coef_val) |
| 1586 | { |
| 1587 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, |
| 1588 | coef_idx); |
| 1589 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, |
| 1590 | coef_val); |
| 1591 | } |
| 1592 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 1593 | /* a special bypass for COEF 0; read the cached value at the second time */ |
| 1594 | static unsigned int alc_get_coef0(struct hda_codec *codec) |
| 1595 | { |
| 1596 | struct alc_spec *spec = codec->spec; |
| 1597 | if (!spec->coef0) |
| 1598 | spec->coef0 = alc_read_coef_idx(codec, 0); |
| 1599 | return spec->coef0; |
| 1600 | } |
| 1601 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1602 | /* |
| 1603 | * Digital I/O handling |
| 1604 | */ |
| 1605 | |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1606 | /* set right pin controls for digital I/O */ |
| 1607 | static void alc_auto_init_digital(struct hda_codec *codec) |
| 1608 | { |
| 1609 | struct alc_spec *spec = codec->spec; |
| 1610 | int i; |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 1611 | hda_nid_t pin, dac; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1612 | |
| 1613 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
| 1614 | pin = spec->autocfg.dig_out_pins[i]; |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 1615 | if (!pin) |
| 1616 | continue; |
| 1617 | snd_hda_codec_write(codec, pin, 0, |
| 1618 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); |
| 1619 | if (!i) |
| 1620 | dac = spec->multiout.dig_out_nid; |
| 1621 | else |
| 1622 | dac = spec->slave_dig_outs[i - 1]; |
| 1623 | if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP)) |
| 1624 | continue; |
| 1625 | snd_hda_codec_write(codec, dac, 0, |
| 1626 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 1627 | AMP_OUT_UNMUTE); |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1628 | } |
| 1629 | pin = spec->autocfg.dig_in_pin; |
| 1630 | if (pin) |
| 1631 | snd_hda_codec_write(codec, pin, 0, |
| 1632 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1633 | PIN_IN); |
| 1634 | } |
| 1635 | |
| 1636 | /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */ |
| 1637 | static void alc_auto_parse_digital(struct hda_codec *codec) |
| 1638 | { |
| 1639 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1640 | int i, err, nums; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1641 | hda_nid_t dig_nid; |
| 1642 | |
| 1643 | /* support multiple SPDIFs; the secondary is set up as a slave */ |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1644 | nums = 0; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1645 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1646 | hda_nid_t conn[4]; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1647 | err = snd_hda_get_connections(codec, |
| 1648 | spec->autocfg.dig_out_pins[i], |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1649 | conn, ARRAY_SIZE(conn)); |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1650 | if (err <= 0) |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1651 | continue; |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1652 | dig_nid = conn[0]; /* assume the first element is audio-out */ |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1653 | if (!nums) { |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1654 | spec->multiout.dig_out_nid = dig_nid; |
| 1655 | spec->dig_out_type = spec->autocfg.dig_out_type[0]; |
| 1656 | } else { |
| 1657 | spec->multiout.slave_dig_outs = spec->slave_dig_outs; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1658 | if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1) |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1659 | break; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1660 | spec->slave_dig_outs[nums - 1] = dig_nid; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1661 | } |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1662 | nums++; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | if (spec->autocfg.dig_in_pin) { |
Takashi Iwai | 01fdf18 | 2010-09-24 09:09:42 +0200 | [diff] [blame] | 1666 | dig_nid = codec->start_nid; |
| 1667 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { |
| 1668 | unsigned int wcaps = get_wcaps(codec, dig_nid); |
| 1669 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
| 1670 | continue; |
| 1671 | if (!(wcaps & AC_WCAP_DIGITAL)) |
| 1672 | continue; |
| 1673 | if (!(wcaps & AC_WCAP_CONN_LIST)) |
| 1674 | continue; |
| 1675 | err = get_connection_index(codec, dig_nid, |
| 1676 | spec->autocfg.dig_in_pin); |
| 1677 | if (err >= 0) { |
| 1678 | spec->dig_in_nid = dig_nid; |
| 1679 | break; |
| 1680 | } |
| 1681 | } |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1682 | } |
| 1683 | } |
| 1684 | |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1685 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1686 | * capture mixer elements |
Vincent Petry | ef8ef5f | 2008-11-23 11:31:41 +0800 | [diff] [blame] | 1687 | */ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1688 | static int alc_cap_vol_info(struct snd_kcontrol *kcontrol, |
| 1689 | struct snd_ctl_elem_info *uinfo) |
| 1690 | { |
| 1691 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1692 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1693 | unsigned long val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1694 | int err; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1695 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1696 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1697 | if (spec->vol_in_capsrc) |
| 1698 | val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT); |
| 1699 | else |
| 1700 | val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT); |
| 1701 | kcontrol->private_value = val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1702 | err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo); |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1703 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1704 | return err; |
| 1705 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1707 | static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, |
| 1708 | unsigned int size, unsigned int __user *tlv) |
| 1709 | { |
| 1710 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1711 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1712 | unsigned long val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1713 | int err; |
| 1714 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1715 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1716 | if (spec->vol_in_capsrc) |
| 1717 | val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT); |
| 1718 | else |
| 1719 | val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT); |
| 1720 | kcontrol->private_value = val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1721 | err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv); |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1722 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1723 | return err; |
| 1724 | } |
| 1725 | |
| 1726 | typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol, |
| 1727 | struct snd_ctl_elem_value *ucontrol); |
| 1728 | |
| 1729 | static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol, |
| 1730 | struct snd_ctl_elem_value *ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1731 | getput_call_t func, bool check_adc_switch) |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1732 | { |
| 1733 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1734 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1735 | int i, err = 0; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1736 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1737 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1738 | if (check_adc_switch && spec->dyn_adc_switch) { |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1739 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 1740 | kcontrol->private_value = |
| 1741 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], |
| 1742 | 3, 0, HDA_INPUT); |
| 1743 | err = func(kcontrol, ucontrol); |
| 1744 | if (err < 0) |
| 1745 | goto error; |
| 1746 | } |
| 1747 | } else { |
| 1748 | i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1749 | if (spec->vol_in_capsrc) |
| 1750 | kcontrol->private_value = |
| 1751 | HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i], |
| 1752 | 3, 0, HDA_OUTPUT); |
| 1753 | else |
| 1754 | kcontrol->private_value = |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1755 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], |
| 1756 | 3, 0, HDA_INPUT); |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1757 | err = func(kcontrol, ucontrol); |
| 1758 | } |
| 1759 | error: |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1760 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1761 | return err; |
| 1762 | } |
| 1763 | |
| 1764 | static int alc_cap_vol_get(struct snd_kcontrol *kcontrol, |
| 1765 | struct snd_ctl_elem_value *ucontrol) |
| 1766 | { |
| 1767 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1768 | snd_hda_mixer_amp_volume_get, false); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | static int alc_cap_vol_put(struct snd_kcontrol *kcontrol, |
| 1772 | struct snd_ctl_elem_value *ucontrol) |
| 1773 | { |
| 1774 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1775 | snd_hda_mixer_amp_volume_put, true); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | /* capture mixer elements */ |
| 1779 | #define alc_cap_sw_info snd_ctl_boolean_stereo_info |
| 1780 | |
| 1781 | static int alc_cap_sw_get(struct snd_kcontrol *kcontrol, |
| 1782 | struct snd_ctl_elem_value *ucontrol) |
| 1783 | { |
| 1784 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1785 | snd_hda_mixer_amp_switch_get, false); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | static int alc_cap_sw_put(struct snd_kcontrol *kcontrol, |
| 1789 | struct snd_ctl_elem_value *ucontrol) |
| 1790 | { |
| 1791 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1792 | snd_hda_mixer_amp_switch_put, true); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1793 | } |
| 1794 | |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1795 | #define _DEFINE_CAPMIX(num) \ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1796 | { \ |
| 1797 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1798 | .name = "Capture Switch", \ |
| 1799 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \ |
| 1800 | .count = num, \ |
| 1801 | .info = alc_cap_sw_info, \ |
| 1802 | .get = alc_cap_sw_get, \ |
| 1803 | .put = alc_cap_sw_put, \ |
| 1804 | }, \ |
| 1805 | { \ |
| 1806 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1807 | .name = "Capture Volume", \ |
| 1808 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \ |
| 1809 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ |
| 1810 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \ |
| 1811 | .count = num, \ |
| 1812 | .info = alc_cap_vol_info, \ |
| 1813 | .get = alc_cap_vol_get, \ |
| 1814 | .put = alc_cap_vol_put, \ |
| 1815 | .tlv = { .c = alc_cap_vol_tlv }, \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | #define _DEFINE_CAPSRC(num) \ |
Takashi Iwai | 3c3e989 | 2008-10-31 17:48:56 +0100 | [diff] [blame] | 1819 | { \ |
| 1820 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1821 | /* .name = "Capture Source", */ \ |
| 1822 | .name = "Input Source", \ |
| 1823 | .count = num, \ |
| 1824 | .info = alc_mux_enum_info, \ |
| 1825 | .get = alc_mux_enum_get, \ |
| 1826 | .put = alc_mux_enum_put, \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | #define DEFINE_CAPMIX(num) \ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1830 | static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1831 | _DEFINE_CAPMIX(num), \ |
| 1832 | _DEFINE_CAPSRC(num), \ |
| 1833 | { } /* end */ \ |
| 1834 | } |
| 1835 | |
| 1836 | #define DEFINE_CAPMIX_NOSRC(num) \ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1837 | static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1838 | _DEFINE_CAPMIX(num), \ |
| 1839 | { } /* end */ \ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | /* up to three ADCs */ |
| 1843 | DEFINE_CAPMIX(1); |
| 1844 | DEFINE_CAPMIX(2); |
| 1845 | DEFINE_CAPMIX(3); |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1846 | DEFINE_CAPMIX_NOSRC(1); |
| 1847 | DEFINE_CAPMIX_NOSRC(2); |
| 1848 | DEFINE_CAPMIX_NOSRC(3); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1849 | |
| 1850 | /* |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1851 | * virtual master controls |
| 1852 | */ |
| 1853 | |
| 1854 | /* |
| 1855 | * slave controls for virtual master |
| 1856 | */ |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1857 | static const char * const alc_slave_vols[] = { |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1858 | "Front Playback Volume", |
| 1859 | "Surround Playback Volume", |
| 1860 | "Center Playback Volume", |
| 1861 | "LFE Playback Volume", |
| 1862 | "Side Playback Volume", |
| 1863 | "Headphone Playback Volume", |
| 1864 | "Speaker Playback Volume", |
| 1865 | "Mono Playback Volume", |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1866 | "Line-Out Playback Volume", |
Takashi Iwai | 3fe45ae | 2011-08-18 15:13:17 +0200 | [diff] [blame] | 1867 | "PCM Playback Volume", |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1868 | NULL, |
| 1869 | }; |
| 1870 | |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1871 | static const char * const alc_slave_sws[] = { |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1872 | "Front Playback Switch", |
| 1873 | "Surround Playback Switch", |
| 1874 | "Center Playback Switch", |
| 1875 | "LFE Playback Switch", |
| 1876 | "Side Playback Switch", |
| 1877 | "Headphone Playback Switch", |
| 1878 | "Speaker Playback Switch", |
| 1879 | "Mono Playback Switch", |
Takashi Iwai | edb54a5 | 2008-01-29 12:47:02 +0100 | [diff] [blame] | 1880 | "IEC958 Playback Switch", |
Takashi Iwai | 23033b2 | 2009-12-08 12:36:52 +0100 | [diff] [blame] | 1881 | "Line-Out Playback Switch", |
Takashi Iwai | 3fe45ae | 2011-08-18 15:13:17 +0200 | [diff] [blame] | 1882 | "PCM Playback Switch", |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1883 | NULL, |
| 1884 | }; |
| 1885 | |
| 1886 | /* |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1887 | * build control elements |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | */ |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1889 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1890 | #define NID_MAPPING (-1) |
| 1891 | |
| 1892 | #define SUBDEV_SPEAKER_ (0 << 6) |
| 1893 | #define SUBDEV_HP_ (1 << 6) |
| 1894 | #define SUBDEV_LINE_ (2 << 6) |
| 1895 | #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f)) |
| 1896 | #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f)) |
| 1897 | #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f)) |
| 1898 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1899 | static void alc_free_kctls(struct hda_codec *codec); |
| 1900 | |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1901 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1902 | /* additional beep mixers; the actual parameters are overwritten at build */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1903 | static const struct snd_kcontrol_new alc_beep_mixer[] = { |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1904 | HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT), |
Jaroslav Kysela | 123c07a | 2009-10-21 14:48:23 +0200 | [diff] [blame] | 1905 | HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT), |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1906 | { } /* end */ |
| 1907 | }; |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1908 | #endif |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | static int alc_build_controls(struct hda_codec *codec) |
| 1911 | { |
| 1912 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2f44f84 | 2010-06-22 11:12:32 +0200 | [diff] [blame] | 1913 | struct snd_kcontrol *kctl = NULL; |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1914 | const struct snd_kcontrol_new *knew; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1915 | int i, j, err; |
| 1916 | unsigned int u; |
| 1917 | hda_nid_t nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | |
| 1919 | for (i = 0; i < spec->num_mixers; i++) { |
| 1920 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 1921 | if (err < 0) |
| 1922 | return err; |
| 1923 | } |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1924 | if (spec->cap_mixer) { |
| 1925 | err = snd_hda_add_new_ctls(codec, spec->cap_mixer); |
| 1926 | if (err < 0) |
| 1927 | return err; |
| 1928 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | if (spec->multiout.dig_out_nid) { |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 1930 | err = snd_hda_create_spdif_out_ctls(codec, |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 1931 | spec->multiout.dig_out_nid, |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 1932 | spec->multiout.dig_out_nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | if (err < 0) |
| 1934 | return err; |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1935 | if (!spec->no_analog) { |
| 1936 | err = snd_hda_create_spdif_share_sw(codec, |
| 1937 | &spec->multiout); |
| 1938 | if (err < 0) |
| 1939 | return err; |
| 1940 | spec->multiout.share_spdif = 1; |
| 1941 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | } |
| 1943 | if (spec->dig_in_nid) { |
| 1944 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); |
| 1945 | if (err < 0) |
| 1946 | return err; |
| 1947 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1948 | |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1949 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1950 | /* create beep controls if needed */ |
| 1951 | if (spec->beep_amp) { |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1952 | const struct snd_kcontrol_new *knew; |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1953 | for (knew = alc_beep_mixer; knew->name; knew++) { |
| 1954 | struct snd_kcontrol *kctl; |
| 1955 | kctl = snd_ctl_new1(knew, codec); |
| 1956 | if (!kctl) |
| 1957 | return -ENOMEM; |
| 1958 | kctl->private_value = spec->beep_amp; |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 1959 | err = snd_hda_ctl_add(codec, 0, kctl); |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1960 | if (err < 0) |
| 1961 | return err; |
| 1962 | } |
| 1963 | } |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1964 | #endif |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1965 | |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1966 | /* if we have no master control, let's create it */ |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1967 | if (!spec->no_analog && |
| 1968 | !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1969 | unsigned int vmaster_tlv[4]; |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1970 | snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1971 | HDA_OUTPUT, vmaster_tlv); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1972 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1973 | vmaster_tlv, alc_slave_vols); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1974 | if (err < 0) |
| 1975 | return err; |
| 1976 | } |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1977 | if (!spec->no_analog && |
| 1978 | !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1979 | err = snd_hda_add_vmaster(codec, "Master Playback Switch", |
| 1980 | NULL, alc_slave_sws); |
| 1981 | if (err < 0) |
| 1982 | return err; |
| 1983 | } |
| 1984 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1985 | /* assign Capture Source enums to NID */ |
Takashi Iwai | fbe618f | 2010-06-11 11:24:58 +0200 | [diff] [blame] | 1986 | if (spec->capsrc_nids || spec->adc_nids) { |
| 1987 | kctl = snd_hda_find_mixer_ctl(codec, "Capture Source"); |
| 1988 | if (!kctl) |
| 1989 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); |
| 1990 | for (i = 0; kctl && i < kctl->count; i++) { |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1991 | const hda_nid_t *nids = spec->capsrc_nids; |
Takashi Iwai | fbe618f | 2010-06-11 11:24:58 +0200 | [diff] [blame] | 1992 | if (!nids) |
| 1993 | nids = spec->adc_nids; |
| 1994 | err = snd_hda_add_nid(codec, kctl, i, nids[i]); |
| 1995 | if (err < 0) |
| 1996 | return err; |
| 1997 | } |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1998 | } |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 1999 | if (spec->cap_mixer && spec->adc_nids) { |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2000 | const char *kname = kctl ? kctl->id.name : NULL; |
| 2001 | for (knew = spec->cap_mixer; knew->name; knew++) { |
| 2002 | if (kname && strcmp(knew->name, kname) == 0) |
| 2003 | continue; |
| 2004 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 2005 | for (i = 0; kctl && i < kctl->count; i++) { |
| 2006 | err = snd_hda_add_nid(codec, kctl, i, |
| 2007 | spec->adc_nids[i]); |
| 2008 | if (err < 0) |
| 2009 | return err; |
| 2010 | } |
| 2011 | } |
| 2012 | } |
| 2013 | |
| 2014 | /* other nid->control mapping */ |
| 2015 | for (i = 0; i < spec->num_mixers; i++) { |
| 2016 | for (knew = spec->mixers[i]; knew->name; knew++) { |
| 2017 | if (knew->iface != NID_MAPPING) |
| 2018 | continue; |
| 2019 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 2020 | if (kctl == NULL) |
| 2021 | continue; |
| 2022 | u = knew->subdevice; |
| 2023 | for (j = 0; j < 4; j++, u >>= 8) { |
| 2024 | nid = u & 0x3f; |
| 2025 | if (nid == 0) |
| 2026 | continue; |
| 2027 | switch (u & 0xc0) { |
| 2028 | case SUBDEV_SPEAKER_: |
| 2029 | nid = spec->autocfg.speaker_pins[nid]; |
| 2030 | break; |
| 2031 | case SUBDEV_LINE_: |
| 2032 | nid = spec->autocfg.line_out_pins[nid]; |
| 2033 | break; |
| 2034 | case SUBDEV_HP_: |
| 2035 | nid = spec->autocfg.hp_pins[nid]; |
| 2036 | break; |
| 2037 | default: |
| 2038 | continue; |
| 2039 | } |
| 2040 | err = snd_hda_add_nid(codec, kctl, 0, nid); |
| 2041 | if (err < 0) |
| 2042 | return err; |
| 2043 | } |
| 2044 | u = knew->private_value; |
| 2045 | for (j = 0; j < 4; j++, u >>= 8) { |
| 2046 | nid = u & 0xff; |
| 2047 | if (nid == 0) |
| 2048 | continue; |
| 2049 | err = snd_hda_add_nid(codec, kctl, 0, nid); |
| 2050 | if (err < 0) |
| 2051 | return err; |
| 2052 | } |
| 2053 | } |
| 2054 | } |
Takashi Iwai | bae84e7 | 2010-03-22 08:30:20 +0100 | [diff] [blame] | 2055 | |
| 2056 | alc_free_kctls(codec); /* no longer needed */ |
| 2057 | |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame^] | 2058 | err = snd_hda_jack_add_kctls(codec, &spec->autocfg); |
| 2059 | if (err < 0) |
| 2060 | return err; |
| 2061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | return 0; |
| 2063 | } |
| 2064 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2065 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | /* |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2067 | * Common callbacks |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2068 | */ |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 2069 | |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 2070 | static void alc_init_special_input_src(struct hda_codec *codec); |
| 2071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | static int alc_init(struct hda_codec *codec) |
| 2073 | { |
| 2074 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2075 | unsigned int i; |
| 2076 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 2077 | alc_fix_pll(codec); |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 2078 | alc_auto_init_amp(codec, spec->init_amp); |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 2079 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2080 | for (i = 0; i < spec->num_init_verbs; i++) |
| 2081 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 2082 | alc_init_special_input_src(codec); |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2083 | |
| 2084 | if (spec->init_hook) |
| 2085 | spec->init_hook(codec); |
| 2086 | |
Takashi Iwai | 5870112 | 2011-01-13 15:41:45 +0100 | [diff] [blame] | 2087 | alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT); |
| 2088 | |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame^] | 2089 | snd_hda_jack_report_sync(codec); |
| 2090 | |
Takashi Iwai | 9e5341b | 2010-09-21 09:57:06 +0200 | [diff] [blame] | 2091 | hda_call_check_power_status(codec, 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | return 0; |
| 2093 | } |
| 2094 | |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2095 | static void alc_unsol_event(struct hda_codec *codec, unsigned int res) |
| 2096 | { |
| 2097 | struct alc_spec *spec = codec->spec; |
| 2098 | |
| 2099 | if (spec->unsol_event) |
| 2100 | spec->unsol_event(codec, res); |
| 2101 | } |
| 2102 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2103 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2104 | static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 2105 | { |
| 2106 | struct alc_spec *spec = codec->spec; |
| 2107 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); |
| 2108 | } |
| 2109 | #endif |
| 2110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | /* |
| 2112 | * Analog playback callbacks |
| 2113 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2114 | static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2116 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | { |
| 2118 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 2119 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 2120 | hinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | } |
| 2122 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2123 | static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | struct hda_codec *codec, |
| 2125 | unsigned int stream_tag, |
| 2126 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2127 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | { |
| 2129 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 2130 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, |
| 2131 | stream_tag, format, substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | } |
| 2133 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2134 | static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2136 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | { |
| 2138 | struct alc_spec *spec = codec->spec; |
| 2139 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
| 2140 | } |
| 2141 | |
| 2142 | /* |
| 2143 | * Digital out |
| 2144 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2145 | static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2147 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | { |
| 2149 | struct alc_spec *spec = codec->spec; |
| 2150 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 2151 | } |
| 2152 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2153 | static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 2154 | struct hda_codec *codec, |
| 2155 | unsigned int stream_tag, |
| 2156 | unsigned int format, |
| 2157 | struct snd_pcm_substream *substream) |
| 2158 | { |
| 2159 | struct alc_spec *spec = codec->spec; |
| 2160 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 2161 | stream_tag, format, substream); |
| 2162 | } |
| 2163 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2164 | static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 9b5f12e | 2009-02-13 11:47:37 +0100 | [diff] [blame] | 2165 | struct hda_codec *codec, |
| 2166 | struct snd_pcm_substream *substream) |
| 2167 | { |
| 2168 | struct alc_spec *spec = codec->spec; |
| 2169 | return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
| 2170 | } |
| 2171 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2172 | static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2174 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | { |
| 2176 | struct alc_spec *spec = codec->spec; |
| 2177 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 2178 | } |
| 2179 | |
| 2180 | /* |
| 2181 | * Analog capture |
| 2182 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2183 | static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | struct hda_codec *codec, |
| 2185 | unsigned int stream_tag, |
| 2186 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2187 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | { |
| 2189 | struct alc_spec *spec = codec->spec; |
| 2190 | |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2191 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | stream_tag, 0, format); |
| 2193 | return 0; |
| 2194 | } |
| 2195 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2196 | static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2198 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | { |
| 2200 | struct alc_spec *spec = codec->spec; |
| 2201 | |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 2202 | snd_hda_codec_cleanup_stream(codec, |
| 2203 | spec->adc_nids[substream->number + 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | return 0; |
| 2205 | } |
| 2206 | |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2207 | /* analog capture with dynamic dual-adc changes */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2208 | static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2209 | struct hda_codec *codec, |
| 2210 | unsigned int stream_tag, |
| 2211 | unsigned int format, |
| 2212 | struct snd_pcm_substream *substream) |
| 2213 | { |
| 2214 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2215 | 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] | 2216 | spec->cur_adc_stream_tag = stream_tag; |
| 2217 | spec->cur_adc_format = format; |
| 2218 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); |
| 2219 | return 0; |
| 2220 | } |
| 2221 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2222 | static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2223 | struct hda_codec *codec, |
| 2224 | struct snd_pcm_substream *substream) |
| 2225 | { |
| 2226 | struct alc_spec *spec = codec->spec; |
| 2227 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
| 2228 | spec->cur_adc = 0; |
| 2229 | return 0; |
| 2230 | } |
| 2231 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2232 | static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = { |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2233 | .substreams = 1, |
| 2234 | .channels_min = 2, |
| 2235 | .channels_max = 2, |
| 2236 | .nid = 0, /* fill later */ |
| 2237 | .ops = { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2238 | .prepare = dyn_adc_capture_pcm_prepare, |
| 2239 | .cleanup = dyn_adc_capture_pcm_cleanup |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2240 | }, |
| 2241 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | |
| 2243 | /* |
| 2244 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2245 | static const struct hda_pcm_stream alc_pcm_analog_playback = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | .substreams = 1, |
| 2247 | .channels_min = 2, |
| 2248 | .channels_max = 8, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2249 | /* NID is set in alc_build_pcms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2251 | .open = alc_playback_pcm_open, |
| 2252 | .prepare = alc_playback_pcm_prepare, |
| 2253 | .cleanup = alc_playback_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | }, |
| 2255 | }; |
| 2256 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2257 | static const struct hda_pcm_stream alc_pcm_analog_capture = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2258 | .substreams = 1, |
| 2259 | .channels_min = 2, |
| 2260 | .channels_max = 2, |
| 2261 | /* NID is set in alc_build_pcms */ |
| 2262 | }; |
| 2263 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2264 | static const struct hda_pcm_stream alc_pcm_analog_alt_playback = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2265 | .substreams = 1, |
| 2266 | .channels_min = 2, |
| 2267 | .channels_max = 2, |
| 2268 | /* NID is set in alc_build_pcms */ |
| 2269 | }; |
| 2270 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2271 | static const struct hda_pcm_stream alc_pcm_analog_alt_capture = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2272 | .substreams = 2, /* can be overridden */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | .channels_min = 2, |
| 2274 | .channels_max = 2, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2275 | /* NID is set in alc_build_pcms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2277 | .prepare = alc_alt_capture_pcm_prepare, |
| 2278 | .cleanup = alc_alt_capture_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | }, |
| 2280 | }; |
| 2281 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2282 | static const struct hda_pcm_stream alc_pcm_digital_playback = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | .substreams = 1, |
| 2284 | .channels_min = 2, |
| 2285 | .channels_max = 2, |
| 2286 | /* NID is set in alc_build_pcms */ |
| 2287 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2288 | .open = alc_dig_playback_pcm_open, |
| 2289 | .close = alc_dig_playback_pcm_close, |
| 2290 | .prepare = alc_dig_playback_pcm_prepare, |
| 2291 | .cleanup = alc_dig_playback_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | }, |
| 2293 | }; |
| 2294 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2295 | static const struct hda_pcm_stream alc_pcm_digital_capture = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | .substreams = 1, |
| 2297 | .channels_min = 2, |
| 2298 | .channels_max = 2, |
| 2299 | /* NID is set in alc_build_pcms */ |
| 2300 | }; |
| 2301 | |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 2302 | /* 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] | 2303 | static const struct hda_pcm_stream alc_pcm_null_stream = { |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 2304 | .substreams = 0, |
| 2305 | .channels_min = 0, |
| 2306 | .channels_max = 0, |
| 2307 | }; |
| 2308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | static int alc_build_pcms(struct hda_codec *codec) |
| 2310 | { |
| 2311 | struct alc_spec *spec = codec->spec; |
| 2312 | struct hda_pcm *info = spec->pcm_rec; |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2313 | const struct hda_pcm_stream *p; |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2314 | bool have_multi_adcs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | int i; |
| 2316 | |
| 2317 | codec->num_pcms = 1; |
| 2318 | codec->pcm_info = info; |
| 2319 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2320 | if (spec->no_analog) |
| 2321 | goto skip_analog; |
| 2322 | |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 2323 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), |
| 2324 | "%s Analog", codec->chip_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | info->name = spec->stream_name_analog; |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 2326 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2327 | if (spec->multiout.dac_nids > 0) { |
| 2328 | p = spec->stream_analog_playback; |
| 2329 | if (!p) |
| 2330 | p = &alc_pcm_analog_playback; |
| 2331 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2332 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; |
| 2333 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2334 | if (spec->adc_nids) { |
| 2335 | p = spec->stream_analog_capture; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2336 | if (!p) { |
| 2337 | if (spec->dyn_adc_switch) |
| 2338 | p = &dyn_adc_pcm_analog_capture; |
| 2339 | else |
| 2340 | p = &alc_pcm_analog_capture; |
| 2341 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2342 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2343 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 2344 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2346 | if (spec->channel_mode) { |
| 2347 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0; |
| 2348 | for (i = 0; i < spec->num_channel_mode; i++) { |
| 2349 | if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) { |
| 2350 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels; |
| 2351 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | } |
| 2353 | } |
| 2354 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2355 | skip_analog: |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2356 | /* SPDIF for stream index #1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 2358 | snprintf(spec->stream_name_digital, |
| 2359 | sizeof(spec->stream_name_digital), |
| 2360 | "%s Digital", codec->chip_name); |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2361 | codec->num_pcms = 2; |
Wu Fengguang | b25c9da | 2009-02-06 15:02:27 +0800 | [diff] [blame] | 2362 | codec->slave_dig_outs = spec->multiout.slave_dig_outs; |
Takashi Iwai | c06134d | 2006-10-11 18:49:13 +0200 | [diff] [blame] | 2363 | info = spec->pcm_rec + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | info->name = spec->stream_name_digital; |
Takashi Iwai | 8c44198 | 2009-01-20 18:30:20 +0100 | [diff] [blame] | 2365 | if (spec->dig_out_type) |
| 2366 | info->pcm_type = spec->dig_out_type; |
| 2367 | else |
| 2368 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2369 | if (spec->multiout.dig_out_nid) { |
| 2370 | p = spec->stream_digital_playback; |
| 2371 | if (!p) |
| 2372 | p = &alc_pcm_digital_playback; |
| 2373 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; |
| 2375 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2376 | if (spec->dig_in_nid) { |
| 2377 | p = spec->stream_digital_capture; |
| 2378 | if (!p) |
| 2379 | p = &alc_pcm_digital_capture; |
| 2380 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; |
| 2382 | } |
Takashi Iwai | 963f803 | 2008-08-11 10:04:40 +0200 | [diff] [blame] | 2383 | /* FIXME: do we need this for all Realtek codec models? */ |
| 2384 | codec->spdif_status_reset = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | } |
| 2386 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2387 | if (spec->no_analog) |
| 2388 | return 0; |
| 2389 | |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2390 | /* If the use of more than one ADC is requested for the current |
| 2391 | * model, configure a second analog capture-only PCM. |
| 2392 | */ |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2393 | have_multi_adcs = (spec->num_adc_nids > 1) && |
| 2394 | !spec->dyn_adc_switch && !spec->auto_mic && |
| 2395 | (!spec->input_mux || spec->input_mux->num_items > 1); |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2396 | /* Additional Analaog capture for index #2 */ |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2397 | if (spec->alt_dac_nid || have_multi_adcs) { |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2398 | codec->num_pcms = 3; |
Takashi Iwai | c06134d | 2006-10-11 18:49:13 +0200 | [diff] [blame] | 2399 | info = spec->pcm_rec + 2; |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2400 | info->name = spec->stream_name_analog; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2401 | if (spec->alt_dac_nid) { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2402 | p = spec->stream_analog_alt_playback; |
| 2403 | if (!p) |
| 2404 | p = &alc_pcm_analog_alt_playback; |
| 2405 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2406 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 2407 | spec->alt_dac_nid; |
| 2408 | } else { |
| 2409 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 2410 | alc_pcm_null_stream; |
| 2411 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0; |
| 2412 | } |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2413 | if (have_multi_adcs) { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2414 | p = spec->stream_analog_alt_capture; |
| 2415 | if (!p) |
| 2416 | p = &alc_pcm_analog_alt_capture; |
| 2417 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2418 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 2419 | spec->adc_nids[1]; |
| 2420 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = |
| 2421 | spec->num_adc_nids - 1; |
| 2422 | } else { |
| 2423 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 2424 | alc_pcm_null_stream; |
| 2425 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0; |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2426 | } |
| 2427 | } |
| 2428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | return 0; |
| 2430 | } |
| 2431 | |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2432 | static inline void alc_shutup(struct hda_codec *codec) |
| 2433 | { |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 2434 | struct alc_spec *spec = codec->spec; |
| 2435 | |
| 2436 | if (spec && spec->shutup) |
| 2437 | spec->shutup(codec); |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2438 | snd_hda_shutup_pins(codec); |
| 2439 | } |
| 2440 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2441 | static void alc_free_kctls(struct hda_codec *codec) |
| 2442 | { |
| 2443 | struct alc_spec *spec = codec->spec; |
| 2444 | |
| 2445 | if (spec->kctls.list) { |
| 2446 | struct snd_kcontrol_new *kctl = spec->kctls.list; |
| 2447 | int i; |
| 2448 | for (i = 0; i < spec->kctls.used; i++) |
| 2449 | kfree(kctl[i].name); |
| 2450 | } |
| 2451 | snd_array_free(&spec->kctls); |
| 2452 | } |
| 2453 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2454 | static void alc_free_bind_ctls(struct hda_codec *codec) |
| 2455 | { |
| 2456 | struct alc_spec *spec = codec->spec; |
| 2457 | if (spec->bind_ctls.list) { |
| 2458 | struct hda_bind_ctls **ctl = spec->bind_ctls.list; |
| 2459 | int i; |
| 2460 | for (i = 0; i < spec->bind_ctls.used; i++) |
| 2461 | kfree(ctl[i]); |
| 2462 | } |
| 2463 | snd_array_free(&spec->bind_ctls); |
| 2464 | } |
| 2465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | static void alc_free(struct hda_codec *codec) |
| 2467 | { |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2468 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2469 | |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2470 | if (!spec) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2471 | return; |
| 2472 | |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2473 | alc_shutup(codec); |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 2474 | snd_hda_input_jack_free(codec); |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2475 | alc_free_kctls(codec); |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2476 | alc_free_bind_ctls(codec); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2477 | kfree(spec); |
Kusanagi Kouichi | 680cd53 | 2009-02-05 00:00:58 +0900 | [diff] [blame] | 2478 | snd_hda_detach_beep_device(codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2481 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2482 | static void alc_power_eapd(struct hda_codec *codec) |
| 2483 | { |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 2484 | alc_auto_setup_eapd(codec, false); |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2485 | } |
| 2486 | |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2487 | static int alc_suspend(struct hda_codec *codec, pm_message_t state) |
| 2488 | { |
| 2489 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2490 | alc_shutup(codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2491 | if (spec && spec->power_hook) |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2492 | spec->power_hook(codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2493 | return 0; |
| 2494 | } |
| 2495 | #endif |
| 2496 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 2497 | #ifdef CONFIG_PM |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2498 | static int alc_resume(struct hda_codec *codec) |
| 2499 | { |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 2500 | msleep(150); /* to avoid pop noise */ |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2501 | codec->patch_ops.init(codec); |
| 2502 | snd_hda_codec_resume_amp(codec); |
| 2503 | snd_hda_codec_resume_cache(codec); |
Takashi Iwai | 9e5341b | 2010-09-21 09:57:06 +0200 | [diff] [blame] | 2504 | hda_call_check_power_status(codec, 0x01); |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2505 | return 0; |
| 2506 | } |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2507 | #endif |
| 2508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | /* |
| 2510 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 2511 | static const struct hda_codec_ops alc_patch_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | .build_controls = alc_build_controls, |
| 2513 | .build_pcms = alc_build_pcms, |
| 2514 | .init = alc_init, |
| 2515 | .free = alc_free, |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2516 | .unsol_event = alc_unsol_event, |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 2517 | #ifdef CONFIG_PM |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2518 | .resume = alc_resume, |
| 2519 | #endif |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2520 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2521 | .suspend = alc_suspend, |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2522 | .check_power_status = alc_check_power_status, |
| 2523 | #endif |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2524 | .reboot_notify = alc_shutup, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | }; |
| 2526 | |
Kailang Yang | c027ddc | 2010-03-19 11:33:06 +0100 | [diff] [blame] | 2527 | /* replace the codec chip_name with the given string */ |
| 2528 | static int alc_codec_rename(struct hda_codec *codec, const char *name) |
| 2529 | { |
| 2530 | kfree(codec->chip_name); |
| 2531 | codec->chip_name = kstrdup(name, GFP_KERNEL); |
| 2532 | if (!codec->chip_name) { |
| 2533 | alc_free(codec); |
| 2534 | return -ENOMEM; |
| 2535 | } |
| 2536 | return 0; |
| 2537 | } |
| 2538 | |
Takashi Iwai | 2fa522b | 2005-05-12 14:51:12 +0200 | [diff] [blame] | 2539 | /* |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2540 | * Rename codecs appropriately from COEF value |
| 2541 | */ |
| 2542 | struct alc_codec_rename_table { |
| 2543 | unsigned int vendor_id; |
| 2544 | unsigned short coef_mask; |
| 2545 | unsigned short coef_bits; |
| 2546 | const char *name; |
| 2547 | }; |
| 2548 | |
| 2549 | static struct alc_codec_rename_table rename_tbl[] = { |
| 2550 | { 0x10ec0269, 0xfff0, 0x3010, "ALC277" }, |
| 2551 | { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" }, |
| 2552 | { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" }, |
| 2553 | { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" }, |
| 2554 | { 0x10ec0269, 0xffff, 0xa023, "ALC259" }, |
| 2555 | { 0x10ec0269, 0xffff, 0x6023, "ALC281X" }, |
| 2556 | { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" }, |
| 2557 | { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" }, |
| 2558 | { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" }, |
| 2559 | { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" }, |
| 2560 | { 0x10ec0899, 0x2000, 0x2000, "ALC899" }, |
| 2561 | { 0x10ec0892, 0xffff, 0x8020, "ALC661" }, |
| 2562 | { 0x10ec0892, 0xffff, 0x8011, "ALC661" }, |
| 2563 | { 0x10ec0892, 0xffff, 0x4011, "ALC656" }, |
| 2564 | { } /* terminator */ |
| 2565 | }; |
| 2566 | |
| 2567 | static int alc_codec_rename_from_preset(struct hda_codec *codec) |
| 2568 | { |
| 2569 | const struct alc_codec_rename_table *p; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2570 | |
| 2571 | for (p = rename_tbl; p->vendor_id; p++) { |
| 2572 | if (p->vendor_id != codec->vendor_id) |
| 2573 | continue; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 2574 | if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits) |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2575 | return alc_codec_rename(codec, p->name); |
| 2576 | } |
| 2577 | return 0; |
| 2578 | } |
| 2579 | |
| 2580 | /* |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2581 | * Automatic parse of I/O pins from the BIOS configuration |
| 2582 | */ |
| 2583 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2584 | enum { |
| 2585 | ALC_CTL_WIDGET_VOL, |
| 2586 | ALC_CTL_WIDGET_MUTE, |
| 2587 | ALC_CTL_BIND_MUTE, |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2588 | ALC_CTL_BIND_VOL, |
| 2589 | ALC_CTL_BIND_SW, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2590 | }; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2591 | static const struct snd_kcontrol_new alc_control_templates[] = { |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2592 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
| 2593 | HDA_CODEC_MUTE(NULL, 0, 0, 0), |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2594 | HDA_BIND_MUTE(NULL, 0, 0, 0), |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2595 | HDA_BIND_VOL(NULL, 0), |
| 2596 | HDA_BIND_SW(NULL, 0), |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2597 | }; |
| 2598 | |
| 2599 | /* add dynamic controls */ |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2600 | 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] | 2601 | int cidx, unsigned long val) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2602 | { |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2603 | struct snd_kcontrol_new *knew; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2604 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2605 | knew = alc_kcontrol_new(spec); |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2606 | if (!knew) |
| 2607 | return -ENOMEM; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2608 | *knew = alc_control_templates[type]; |
Paulo Marques | 543537b | 2005-06-23 00:09:02 -0700 | [diff] [blame] | 2609 | knew->name = kstrdup(name, GFP_KERNEL); |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2610 | if (!knew->name) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2611 | return -ENOMEM; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2612 | knew->index = cidx; |
Jaroslav Kysela | 4d02d1b | 2009-11-12 10:15:48 +0100 | [diff] [blame] | 2613 | if (get_amp_nid_(val)) |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 2614 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2615 | knew->private_value = val; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2616 | return 0; |
| 2617 | } |
| 2618 | |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2619 | static int add_control_with_pfx(struct alc_spec *spec, int type, |
| 2620 | const char *pfx, const char *dir, |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2621 | const char *sfx, int cidx, unsigned long val) |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2622 | { |
| 2623 | char name[32]; |
| 2624 | snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx); |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2625 | return add_control(spec, type, name, cidx, val); |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2626 | } |
| 2627 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2628 | #define add_pb_vol_ctrl(spec, type, pfx, val) \ |
| 2629 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val) |
| 2630 | #define add_pb_sw_ctrl(spec, type, pfx, val) \ |
| 2631 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val) |
| 2632 | #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \ |
| 2633 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val) |
| 2634 | #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \ |
| 2635 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val) |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2636 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2637 | static const char * const channel_name[4] = { |
| 2638 | "Front", "Surround", "CLFE", "Side" |
| 2639 | }; |
| 2640 | |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2641 | static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch, |
| 2642 | bool can_be_master, int *index) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2643 | { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2644 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2645 | |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2646 | *index = 0; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2647 | if (cfg->line_outs == 1 && !spec->multi_ios && |
| 2648 | !cfg->hp_outs && !cfg->speaker_outs && can_be_master) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2649 | return "Master"; |
| 2650 | |
| 2651 | switch (cfg->line_out_type) { |
| 2652 | case AUTO_PIN_SPEAKER_OUT: |
David Henningsson | ebbeb3d | 2011-03-04 14:08:30 +0100 | [diff] [blame] | 2653 | if (cfg->line_outs == 1) |
| 2654 | return "Speaker"; |
| 2655 | break; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2656 | case AUTO_PIN_HP_OUT: |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2657 | /* for multi-io case, only the primary out */ |
| 2658 | if (ch && spec->multi_ios) |
| 2659 | break; |
| 2660 | *index = ch; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2661 | return "Headphone"; |
| 2662 | default: |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2663 | if (cfg->line_outs == 1 && !spec->multi_ios) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2664 | return "PCM"; |
| 2665 | break; |
| 2666 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2667 | if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name))) |
| 2668 | return "PCM"; |
| 2669 | |
| 2670 | return channel_name[ch]; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2671 | } |
| 2672 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2673 | /* create input playback/capture controls for the given pin */ |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2674 | 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] | 2675 | const char *ctlname, int ctlidx, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 2676 | int idx, hda_nid_t mix_nid) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2677 | { |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 2678 | int err; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2679 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2680 | err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2681 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 2682 | if (err < 0) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2683 | return err; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2684 | err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2685 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 2686 | if (err < 0) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2687 | return err; |
| 2688 | return 0; |
| 2689 | } |
| 2690 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2691 | 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] | 2692 | { |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2693 | unsigned int pincap = snd_hda_query_pin_caps(codec, nid); |
| 2694 | return (pincap & AC_PINCAP_IN) != 0; |
| 2695 | } |
| 2696 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2697 | /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */ |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2698 | static int alc_auto_fill_adc_caps(struct hda_codec *codec) |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2699 | { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2700 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2701 | hda_nid_t nid; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2702 | hda_nid_t *adc_nids = spec->private_adc_nids; |
| 2703 | hda_nid_t *cap_nids = spec->private_capsrc_nids; |
| 2704 | int max_nums = ARRAY_SIZE(spec->private_adc_nids); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2705 | int i, nums = 0; |
| 2706 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 2707 | if (spec->shared_mic_hp) |
| 2708 | max_nums = 1; /* no multi streams with the shared HP/mic */ |
| 2709 | |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2710 | nid = codec->start_nid; |
| 2711 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 2712 | hda_nid_t src; |
| 2713 | const hda_nid_t *list; |
| 2714 | unsigned int caps = get_wcaps(codec, nid); |
| 2715 | int type = get_wcaps_type(caps); |
| 2716 | |
| 2717 | if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL)) |
| 2718 | continue; |
| 2719 | adc_nids[nums] = nid; |
| 2720 | cap_nids[nums] = nid; |
| 2721 | src = nid; |
| 2722 | for (;;) { |
| 2723 | int n; |
| 2724 | type = get_wcaps_type(get_wcaps(codec, src)); |
| 2725 | if (type == AC_WID_PIN) |
| 2726 | break; |
| 2727 | if (type == AC_WID_AUD_SEL) { |
| 2728 | cap_nids[nums] = src; |
| 2729 | break; |
| 2730 | } |
| 2731 | n = snd_hda_get_conn_list(codec, src, &list); |
| 2732 | if (n > 1) { |
| 2733 | cap_nids[nums] = src; |
| 2734 | break; |
| 2735 | } else if (n != 1) |
| 2736 | break; |
| 2737 | src = *list; |
| 2738 | } |
| 2739 | if (++nums >= max_nums) |
| 2740 | break; |
| 2741 | } |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2742 | spec->adc_nids = spec->private_adc_nids; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2743 | spec->capsrc_nids = spec->private_capsrc_nids; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2744 | spec->num_adc_nids = nums; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2745 | return nums; |
| 2746 | } |
| 2747 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2748 | /* create playback/capture controls for input pins */ |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2749 | static int alc_auto_create_input_ctls(struct hda_codec *codec) |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2750 | { |
| 2751 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2752 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2753 | hda_nid_t mixer = spec->mixer_nid; |
Herton Ronaldo Krzesinski | 61b9b9b | 2009-01-28 09:16:33 -0200 | [diff] [blame] | 2754 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2755 | int num_adcs; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2756 | int i, c, err, idx, type_idx = 0; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2757 | const char *prev_label = NULL; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2758 | |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2759 | num_adcs = alc_auto_fill_adc_caps(codec); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2760 | if (num_adcs < 0) |
| 2761 | return 0; |
| 2762 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2763 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2764 | hda_nid_t pin; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2765 | const char *label; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2766 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2767 | pin = cfg->inputs[i].pin; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2768 | if (!alc_is_input_pin(codec, pin)) |
| 2769 | continue; |
| 2770 | |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2771 | label = hda_get_autocfg_input_label(codec, cfg, i); |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 2772 | if (spec->shared_mic_hp && !strcmp(label, "Misc")) |
| 2773 | label = "Headphone Mic"; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2774 | if (prev_label && !strcmp(label, prev_label)) |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2775 | type_idx++; |
| 2776 | else |
| 2777 | type_idx = 0; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2778 | prev_label = label; |
| 2779 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2780 | if (mixer) { |
| 2781 | idx = get_connection_index(codec, mixer, pin); |
| 2782 | if (idx >= 0) { |
| 2783 | err = new_analog_input(spec, pin, |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2784 | label, type_idx, |
| 2785 | idx, mixer); |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2786 | if (err < 0) |
| 2787 | return err; |
| 2788 | } |
| 2789 | } |
| 2790 | |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2791 | for (c = 0; c < num_adcs; c++) { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2792 | hda_nid_t cap = spec->capsrc_nids ? |
| 2793 | spec->capsrc_nids[c] : spec->adc_nids[c]; |
| 2794 | idx = get_connection_index(codec, cap, pin); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2795 | if (idx >= 0) { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2796 | spec->imux_pins[imux->num_items] = pin; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2797 | snd_hda_add_imux_item(imux, label, idx, NULL); |
| 2798 | break; |
| 2799 | } |
| 2800 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2801 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2802 | |
| 2803 | spec->num_mux_defs = 1; |
| 2804 | spec->input_mux = imux; |
| 2805 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2806 | return 0; |
| 2807 | } |
| 2808 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 2809 | /* create a shared input with the headphone out */ |
| 2810 | static int alc_auto_create_shared_input(struct hda_codec *codec) |
| 2811 | { |
| 2812 | struct alc_spec *spec = codec->spec; |
| 2813 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2814 | unsigned int defcfg; |
| 2815 | hda_nid_t nid; |
| 2816 | |
| 2817 | /* only one internal input pin? */ |
| 2818 | if (cfg->num_inputs != 1) |
| 2819 | return 0; |
| 2820 | defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin); |
| 2821 | if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT) |
| 2822 | return 0; |
| 2823 | |
| 2824 | if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) |
| 2825 | nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */ |
| 2826 | else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT) |
| 2827 | nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */ |
| 2828 | else |
| 2829 | return 0; /* both not available */ |
| 2830 | |
| 2831 | if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN)) |
| 2832 | return 0; /* no input */ |
| 2833 | |
| 2834 | cfg->inputs[1].pin = nid; |
| 2835 | cfg->inputs[1].type = AUTO_PIN_MIC; |
| 2836 | cfg->num_inputs = 2; |
| 2837 | spec->shared_mic_hp = 1; |
| 2838 | snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid); |
| 2839 | return 0; |
| 2840 | } |
| 2841 | |
Takashi Iwai | f6c7e54 | 2008-02-12 18:32:23 +0100 | [diff] [blame] | 2842 | static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid, |
| 2843 | unsigned int pin_type) |
| 2844 | { |
| 2845 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 2846 | pin_type); |
| 2847 | /* unmute pin */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 2848 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
| 2849 | 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] | 2850 | AMP_OUT_UNMUTE); |
Takashi Iwai | f6c7e54 | 2008-02-12 18:32:23 +0100 | [diff] [blame] | 2851 | } |
| 2852 | |
Takashi Iwai | baba8ee | 2007-04-23 17:17:48 +0200 | [diff] [blame] | 2853 | static int get_pin_type(int line_out_type) |
| 2854 | { |
| 2855 | if (line_out_type == AUTO_PIN_HP_OUT) |
| 2856 | return PIN_HP; |
| 2857 | else |
| 2858 | return PIN_OUT; |
| 2859 | } |
| 2860 | |
Takashi Iwai | 0a7f532 | 2011-07-06 15:15:12 +0200 | [diff] [blame] | 2861 | static void alc_auto_init_analog_input(struct hda_codec *codec) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2862 | { |
| 2863 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2864 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2865 | int i; |
| 2866 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2867 | for (i = 0; i < cfg->num_inputs; i++) { |
| 2868 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2869 | if (alc_is_input_pin(codec, nid)) { |
Takashi Iwai | 30ea098 | 2010-09-16 18:47:56 +0200 | [diff] [blame] | 2870 | alc_set_input_pin(codec, nid, cfg->inputs[i].type); |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 2871 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2872 | snd_hda_codec_write(codec, nid, 0, |
| 2873 | AC_VERB_SET_AMP_GAIN_MUTE, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2874 | AMP_OUT_MUTE); |
| 2875 | } |
| 2876 | } |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 2877 | |
| 2878 | /* mute all loopback inputs */ |
| 2879 | if (spec->mixer_nid) { |
| 2880 | int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL); |
| 2881 | for (i = 0; i < nums; i++) |
| 2882 | snd_hda_codec_write(codec, spec->mixer_nid, 0, |
| 2883 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 2884 | AMP_IN_MUTE(i)); |
| 2885 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2886 | } |
| 2887 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2888 | /* convert from MIX nid to DAC */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2889 | 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] | 2890 | { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2891 | hda_nid_t list[5]; |
Takashi Iwai | 1304ac8 | 2011-04-06 15:16:21 +0200 | [diff] [blame] | 2892 | int i, num; |
| 2893 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 2894 | if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT) |
| 2895 | return nid; |
Takashi Iwai | 1304ac8 | 2011-04-06 15:16:21 +0200 | [diff] [blame] | 2896 | num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list)); |
| 2897 | for (i = 0; i < num; i++) { |
| 2898 | if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT) |
| 2899 | return list[i]; |
| 2900 | } |
| 2901 | return 0; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2902 | } |
| 2903 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2904 | /* go down to the selector widget before the mixer */ |
| 2905 | static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin) |
| 2906 | { |
| 2907 | hda_nid_t srcs[5]; |
| 2908 | int num = snd_hda_get_connections(codec, pin, srcs, |
| 2909 | ARRAY_SIZE(srcs)); |
| 2910 | if (num != 1 || |
| 2911 | get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL) |
| 2912 | return pin; |
| 2913 | return srcs[0]; |
| 2914 | } |
| 2915 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2916 | /* get MIX nid connected to the given pin targeted to DAC */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2917 | 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] | 2918 | hda_nid_t dac) |
| 2919 | { |
David Henningsson | cc1c452 | 2010-11-24 14:17:47 +0100 | [diff] [blame] | 2920 | hda_nid_t mix[5]; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2921 | int i, num; |
| 2922 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2923 | pin = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2924 | num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); |
| 2925 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2926 | if (alc_auto_mix_to_dac(codec, mix[i]) == dac) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2927 | return mix[i]; |
| 2928 | } |
| 2929 | return 0; |
| 2930 | } |
| 2931 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2932 | /* select the connection from pin to DAC if needed */ |
| 2933 | static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin, |
| 2934 | hda_nid_t dac) |
| 2935 | { |
| 2936 | hda_nid_t mix[5]; |
| 2937 | int i, num; |
| 2938 | |
| 2939 | pin = alc_go_down_to_selector(codec, pin); |
| 2940 | num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); |
| 2941 | if (num < 2) |
| 2942 | return 0; |
| 2943 | for (i = 0; i < num; i++) { |
| 2944 | if (alc_auto_mix_to_dac(codec, mix[i]) == dac) { |
| 2945 | snd_hda_codec_update_cache(codec, pin, 0, |
| 2946 | AC_VERB_SET_CONNECT_SEL, i); |
| 2947 | return 0; |
| 2948 | } |
| 2949 | } |
| 2950 | return 0; |
| 2951 | } |
| 2952 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2953 | /* look for an empty DAC slot */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2954 | 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] | 2955 | { |
| 2956 | struct alc_spec *spec = codec->spec; |
| 2957 | hda_nid_t srcs[5]; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2958 | int i, num; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2959 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2960 | pin = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2961 | num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs)); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2962 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2963 | hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2964 | if (!nid) |
| 2965 | continue; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2966 | if (found_in_nid_list(nid, spec->multiout.dac_nids, |
| 2967 | spec->multiout.num_dacs)) |
| 2968 | continue; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 2969 | if (found_in_nid_list(nid, spec->multiout.hp_out_nid, |
| 2970 | ARRAY_SIZE(spec->multiout.hp_out_nid))) |
| 2971 | continue; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2972 | if (found_in_nid_list(nid, spec->multiout.extra_out_nid, |
| 2973 | ARRAY_SIZE(spec->multiout.extra_out_nid))) |
| 2974 | continue; |
| 2975 | return nid; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2976 | } |
| 2977 | return 0; |
| 2978 | } |
| 2979 | |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 2980 | /* check whether the DAC is reachable from the pin */ |
| 2981 | static bool alc_auto_is_dac_reachable(struct hda_codec *codec, |
| 2982 | hda_nid_t pin, hda_nid_t dac) |
| 2983 | { |
| 2984 | hda_nid_t srcs[5]; |
| 2985 | int i, num; |
| 2986 | |
| 2987 | pin = alc_go_down_to_selector(codec, pin); |
| 2988 | num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs)); |
| 2989 | for (i = 0; i < num; i++) { |
| 2990 | hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]); |
| 2991 | if (nid == dac) |
| 2992 | return true; |
| 2993 | } |
| 2994 | return false; |
| 2995 | } |
| 2996 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2997 | static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin) |
| 2998 | { |
| 2999 | hda_nid_t sel = alc_go_down_to_selector(codec, pin); |
| 3000 | if (snd_hda_get_conn_list(codec, sel, NULL) == 1) |
| 3001 | return alc_auto_look_for_dac(codec, pin); |
| 3002 | return 0; |
| 3003 | } |
| 3004 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3005 | static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs, |
| 3006 | const hda_nid_t *pins, hda_nid_t *dacs) |
| 3007 | { |
| 3008 | int i; |
| 3009 | |
| 3010 | if (num_outs && !dacs[0]) { |
| 3011 | dacs[0] = alc_auto_look_for_dac(codec, pins[0]); |
| 3012 | if (!dacs[0]) |
| 3013 | return 0; |
| 3014 | } |
| 3015 | |
| 3016 | for (i = 1; i < num_outs; i++) |
| 3017 | dacs[i] = get_dac_if_single(codec, pins[i]); |
| 3018 | for (i = 1; i < num_outs; i++) { |
| 3019 | if (!dacs[i]) |
| 3020 | dacs[i] = alc_auto_look_for_dac(codec, pins[i]); |
| 3021 | } |
| 3022 | return 0; |
| 3023 | } |
| 3024 | |
| 3025 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3026 | unsigned int location, int offset); |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3027 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3028 | /* fill in the dac_nids table from the parsed pin configuration */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3029 | static int alc_auto_fill_dac_nids(struct hda_codec *codec) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3030 | { |
| 3031 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | cb053a8 | 2011-06-27 11:32:07 +0200 | [diff] [blame] | 3032 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3033 | unsigned int location, defcfg; |
| 3034 | int num_pins; |
Takashi Iwai | 350434e | 2011-06-30 21:29:12 +0200 | [diff] [blame] | 3035 | bool redone = false; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3036 | int i; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3037 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3038 | again: |
Takashi Iwai | 8f398ae | 2011-07-23 18:57:11 +0200 | [diff] [blame] | 3039 | /* set num_dacs once to full for alc_auto_look_for_dac() */ |
| 3040 | spec->multiout.num_dacs = cfg->line_outs; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3041 | spec->multiout.hp_out_nid[0] = 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3042 | spec->multiout.extra_out_nid[0] = 0; |
| 3043 | memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids)); |
| 3044 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 3045 | |
| 3046 | /* fill hard-wired DACs first */ |
| 3047 | if (!redone) { |
| 3048 | for (i = 0; i < cfg->line_outs; i++) |
| 3049 | spec->private_dac_nids[i] = |
| 3050 | get_dac_if_single(codec, cfg->line_out_pins[i]); |
| 3051 | if (cfg->hp_outs) |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3052 | spec->multiout.hp_out_nid[0] = |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3053 | get_dac_if_single(codec, cfg->hp_pins[0]); |
| 3054 | if (cfg->speaker_outs) |
| 3055 | spec->multiout.extra_out_nid[0] = |
| 3056 | get_dac_if_single(codec, cfg->speaker_pins[0]); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3057 | } |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3058 | |
| 3059 | for (i = 0; i < cfg->line_outs; i++) { |
| 3060 | hda_nid_t pin = cfg->line_out_pins[i]; |
| 3061 | if (spec->private_dac_nids[i]) |
| 3062 | continue; |
| 3063 | spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin); |
| 3064 | if (!spec->private_dac_nids[i] && !redone) { |
| 3065 | /* if we can't find primary DACs, re-probe without |
| 3066 | * checking the hard-wired DACs |
| 3067 | */ |
| 3068 | redone = true; |
| 3069 | goto again; |
| 3070 | } |
| 3071 | } |
| 3072 | |
Takashi Iwai | 8f398ae | 2011-07-23 18:57:11 +0200 | [diff] [blame] | 3073 | /* re-count num_dacs and squash invalid entries */ |
| 3074 | spec->multiout.num_dacs = 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3075 | for (i = 0; i < cfg->line_outs; i++) { |
| 3076 | if (spec->private_dac_nids[i]) |
| 3077 | spec->multiout.num_dacs++; |
| 3078 | else |
| 3079 | memmove(spec->private_dac_nids + i, |
| 3080 | spec->private_dac_nids + i + 1, |
| 3081 | sizeof(hda_nid_t) * (cfg->line_outs - i - 1)); |
| 3082 | } |
| 3083 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3084 | if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
| 3085 | /* try to fill multi-io first */ |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3086 | defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]); |
| 3087 | location = get_defcfg_location(defcfg); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3088 | |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3089 | num_pins = alc_auto_fill_multi_ios(codec, location, 0); |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3090 | if (num_pins > 0) { |
| 3091 | spec->multi_ios = num_pins; |
| 3092 | spec->ext_channel_count = 2; |
| 3093 | spec->multiout.num_dacs = num_pins + 1; |
| 3094 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3095 | } |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3096 | |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3097 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) |
| 3098 | alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins, |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3099 | spec->multiout.hp_out_nid); |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3100 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) |
| 3101 | alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins, |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3102 | spec->multiout.extra_out_nid); |
| 3103 | |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3104 | if (!spec->multi_ios && |
| 3105 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && |
| 3106 | cfg->hp_outs) { |
| 3107 | /* try multi-ios with HP + inputs */ |
| 3108 | defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]); |
| 3109 | location = get_defcfg_location(defcfg); |
| 3110 | |
| 3111 | num_pins = alc_auto_fill_multi_ios(codec, location, 1); |
| 3112 | if (num_pins > 0) { |
| 3113 | spec->multi_ios = num_pins; |
| 3114 | spec->ext_channel_count = 2; |
| 3115 | spec->multiout.num_dacs = num_pins + 1; |
| 3116 | } |
| 3117 | } |
| 3118 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3119 | return 0; |
| 3120 | } |
| 3121 | |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3122 | static inline unsigned int get_ctl_pos(unsigned int data) |
| 3123 | { |
| 3124 | hda_nid_t nid = get_amp_nid_(data); |
| 3125 | unsigned int dir = get_amp_direction_(data); |
| 3126 | return (nid << 1) | dir; |
| 3127 | } |
| 3128 | |
| 3129 | #define is_ctl_used(bits, data) \ |
| 3130 | test_bit(get_ctl_pos(data), bits) |
| 3131 | #define mark_ctl_usage(bits, data) \ |
| 3132 | set_bit(get_ctl_pos(data), bits) |
| 3133 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3134 | static int alc_auto_add_vol_ctl(struct hda_codec *codec, |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3135 | const char *pfx, int cidx, |
| 3136 | hda_nid_t nid, unsigned int chs) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3137 | { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3138 | struct alc_spec *spec = codec->spec; |
| 3139 | unsigned int val; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3140 | if (!nid) |
| 3141 | return 0; |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3142 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); |
| 3143 | if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */ |
| 3144 | return 0; |
| 3145 | mark_ctl_usage(spec->vol_ctls, val); |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3146 | 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] | 3147 | val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3148 | } |
| 3149 | |
Takashi Iwai | e29d377 | 2011-11-14 17:13:23 +0100 | [diff] [blame] | 3150 | static int alc_auto_add_stereo_vol(struct hda_codec *codec, |
| 3151 | const char *pfx, int cidx, |
| 3152 | hda_nid_t nid) |
| 3153 | { |
| 3154 | int chs = 1; |
| 3155 | if (get_wcaps(codec, nid) & AC_WCAP_STEREO) |
| 3156 | chs = 3; |
| 3157 | return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs); |
| 3158 | } |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3159 | |
| 3160 | /* create a mute-switch for the given mixer widget; |
| 3161 | * if it has multiple sources (e.g. DAC and loopback), create a bind-mute |
| 3162 | */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3163 | static int alc_auto_add_sw_ctl(struct hda_codec *codec, |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3164 | const char *pfx, int cidx, |
| 3165 | hda_nid_t nid, unsigned int chs) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3166 | { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3167 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3168 | int wid_type; |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3169 | int type; |
| 3170 | unsigned long val; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3171 | if (!nid) |
| 3172 | return 0; |
| 3173 | wid_type = get_wcaps_type(get_wcaps(codec, nid)); |
| 3174 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) { |
| 3175 | type = ALC_CTL_WIDGET_MUTE; |
| 3176 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); |
| 3177 | } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) { |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3178 | type = ALC_CTL_WIDGET_MUTE; |
| 3179 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT); |
| 3180 | } else { |
| 3181 | type = ALC_CTL_BIND_MUTE; |
| 3182 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT); |
| 3183 | } |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3184 | if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */ |
| 3185 | return 0; |
| 3186 | mark_ctl_usage(spec->sw_ctls, val); |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3187 | return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3188 | } |
| 3189 | |
Takashi Iwai | e29d377 | 2011-11-14 17:13:23 +0100 | [diff] [blame] | 3190 | static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx, |
| 3191 | int cidx, hda_nid_t nid) |
| 3192 | { |
| 3193 | int chs = 1; |
| 3194 | if (get_wcaps(codec, nid) & AC_WCAP_STEREO) |
| 3195 | chs = 3; |
| 3196 | return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs); |
| 3197 | } |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3198 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3199 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, |
| 3200 | hda_nid_t pin, hda_nid_t dac) |
| 3201 | { |
| 3202 | hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac); |
| 3203 | if (nid_has_mute(codec, pin, HDA_OUTPUT)) |
| 3204 | return pin; |
| 3205 | else if (mix && nid_has_mute(codec, mix, HDA_INPUT)) |
| 3206 | return mix; |
| 3207 | else if (nid_has_mute(codec, dac, HDA_OUTPUT)) |
| 3208 | return dac; |
| 3209 | return 0; |
| 3210 | } |
| 3211 | |
| 3212 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, |
| 3213 | hda_nid_t pin, hda_nid_t dac) |
| 3214 | { |
| 3215 | hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac); |
| 3216 | if (nid_has_volume(codec, dac, HDA_OUTPUT)) |
| 3217 | return dac; |
| 3218 | else if (nid_has_volume(codec, mix, HDA_OUTPUT)) |
| 3219 | return mix; |
| 3220 | else if (nid_has_volume(codec, pin, HDA_OUTPUT)) |
| 3221 | return pin; |
| 3222 | return 0; |
| 3223 | } |
| 3224 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3225 | /* add playback controls from the parsed DAC table */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3226 | static int alc_auto_create_multi_out_ctls(struct hda_codec *codec, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3227 | const struct auto_pin_cfg *cfg) |
| 3228 | { |
| 3229 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3230 | int i, err, noutputs; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3231 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3232 | noutputs = cfg->line_outs; |
| 3233 | if (spec->multi_ios > 0) |
| 3234 | noutputs += spec->multi_ios; |
| 3235 | |
| 3236 | for (i = 0; i < noutputs; i++) { |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 3237 | const char *name; |
| 3238 | int index; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3239 | hda_nid_t dac, pin; |
| 3240 | hda_nid_t sw, vol; |
| 3241 | |
| 3242 | dac = spec->multiout.dac_nids[i]; |
| 3243 | if (!dac) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3244 | continue; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3245 | if (i >= cfg->line_outs) |
| 3246 | pin = spec->multi_io[i - 1].pin; |
| 3247 | else |
| 3248 | pin = cfg->line_out_pins[i]; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3249 | |
| 3250 | sw = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3251 | vol = alc_look_for_out_vol_nid(codec, pin, dac); |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 3252 | name = alc_get_line_out_pfx(spec, i, true, &index); |
Takashi Iwai | 9c4e84d | 2011-08-24 17:27:52 +0200 | [diff] [blame] | 3253 | if (!name || !strcmp(name, "CLFE")) { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3254 | /* Center/LFE */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3255 | err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3256 | if (err < 0) |
| 3257 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3258 | err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3259 | if (err < 0) |
| 3260 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3261 | err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3262 | if (err < 0) |
| 3263 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3264 | err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3265 | if (err < 0) |
| 3266 | return err; |
| 3267 | } else { |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3268 | err = alc_auto_add_stereo_vol(codec, name, index, vol); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3269 | if (err < 0) |
| 3270 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3271 | err = alc_auto_add_stereo_sw(codec, name, index, sw); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3272 | if (err < 0) |
| 3273 | return err; |
| 3274 | } |
| 3275 | } |
| 3276 | return 0; |
| 3277 | } |
| 3278 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3279 | static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin, |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3280 | hda_nid_t dac, const char *pfx) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3281 | { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3282 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3283 | hda_nid_t sw, vol; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3284 | int err; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3285 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3286 | if (!dac) { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3287 | unsigned int val; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3288 | /* the corresponding DAC is already occupied */ |
| 3289 | if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)) |
| 3290 | return 0; /* no way */ |
| 3291 | /* create a switch only */ |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3292 | val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT); |
| 3293 | if (is_ctl_used(spec->sw_ctls, val)) |
| 3294 | return 0; /* already created */ |
| 3295 | mark_ctl_usage(spec->sw_ctls, val); |
| 3296 | return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3297 | } |
| 3298 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3299 | sw = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3300 | vol = alc_look_for_out_vol_nid(codec, pin, dac); |
| 3301 | err = alc_auto_add_stereo_vol(codec, pfx, 0, vol); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3302 | if (err < 0) |
Takashi Iwai | 24fb917 | 2008-09-02 14:48:20 +0200 | [diff] [blame] | 3303 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3304 | err = alc_auto_add_stereo_sw(codec, pfx, 0, sw); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3305 | if (err < 0) |
| 3306 | return err; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3307 | return 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3308 | } |
| 3309 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3310 | static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec, |
| 3311 | unsigned int nums, |
| 3312 | struct hda_ctl_ops *ops) |
| 3313 | { |
| 3314 | struct alc_spec *spec = codec->spec; |
| 3315 | struct hda_bind_ctls **ctlp, *ctl; |
| 3316 | snd_array_init(&spec->bind_ctls, sizeof(ctl), 8); |
| 3317 | ctlp = snd_array_new(&spec->bind_ctls); |
| 3318 | if (!ctlp) |
| 3319 | return NULL; |
| 3320 | ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL); |
| 3321 | *ctlp = ctl; |
| 3322 | if (ctl) |
| 3323 | ctl->ops = ops; |
| 3324 | return ctl; |
| 3325 | } |
| 3326 | |
| 3327 | /* add playback controls for speaker and HP outputs */ |
| 3328 | static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins, |
| 3329 | const hda_nid_t *pins, |
| 3330 | const hda_nid_t *dacs, |
| 3331 | const char *pfx) |
| 3332 | { |
| 3333 | struct alc_spec *spec = codec->spec; |
| 3334 | struct hda_bind_ctls *ctl; |
| 3335 | char name[32]; |
| 3336 | int i, n, err; |
| 3337 | |
| 3338 | if (!num_pins || !pins[0]) |
| 3339 | return 0; |
| 3340 | |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3341 | if (num_pins == 1) { |
| 3342 | hda_nid_t dac = *dacs; |
| 3343 | if (!dac) |
| 3344 | dac = spec->multiout.dac_nids[0]; |
| 3345 | return alc_auto_create_extra_out(codec, *pins, dac, pfx); |
| 3346 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3347 | |
| 3348 | if (dacs[num_pins - 1]) { |
| 3349 | /* OK, we have a multi-output system with individual volumes */ |
| 3350 | for (i = 0; i < num_pins; i++) { |
| 3351 | snprintf(name, sizeof(name), "%s %s", |
| 3352 | pfx, channel_name[i]); |
| 3353 | err = alc_auto_create_extra_out(codec, pins[i], dacs[i], |
| 3354 | name); |
| 3355 | if (err < 0) |
| 3356 | return err; |
| 3357 | } |
| 3358 | return 0; |
| 3359 | } |
| 3360 | |
| 3361 | /* Let's create a bind-controls */ |
| 3362 | ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw); |
| 3363 | if (!ctl) |
| 3364 | return -ENOMEM; |
| 3365 | n = 0; |
| 3366 | for (i = 0; i < num_pins; i++) { |
| 3367 | if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP) |
| 3368 | ctl->values[n++] = |
| 3369 | HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT); |
| 3370 | } |
| 3371 | if (n) { |
| 3372 | snprintf(name, sizeof(name), "%s Playback Switch", pfx); |
| 3373 | err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl); |
| 3374 | if (err < 0) |
| 3375 | return err; |
| 3376 | } |
| 3377 | |
| 3378 | ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol); |
| 3379 | if (!ctl) |
| 3380 | return -ENOMEM; |
| 3381 | n = 0; |
| 3382 | for (i = 0; i < num_pins; i++) { |
| 3383 | hda_nid_t vol; |
| 3384 | if (!pins[i] || !dacs[i]) |
| 3385 | continue; |
| 3386 | vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]); |
| 3387 | if (vol) |
| 3388 | ctl->values[n++] = |
| 3389 | HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT); |
| 3390 | } |
| 3391 | if (n) { |
| 3392 | snprintf(name, sizeof(name), "%s Playback Volume", pfx); |
| 3393 | err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl); |
| 3394 | if (err < 0) |
| 3395 | return err; |
| 3396 | } |
| 3397 | return 0; |
| 3398 | } |
| 3399 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3400 | static int alc_auto_create_hp_out(struct hda_codec *codec) |
| 3401 | { |
| 3402 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3403 | return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs, |
| 3404 | spec->autocfg.hp_pins, |
| 3405 | spec->multiout.hp_out_nid, |
| 3406 | "Headphone"); |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | static int alc_auto_create_speaker_out(struct hda_codec *codec) |
| 3410 | { |
| 3411 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3412 | return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs, |
| 3413 | spec->autocfg.speaker_pins, |
| 3414 | spec->multiout.extra_out_nid, |
| 3415 | "Speaker"); |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3416 | } |
| 3417 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3418 | static void alc_auto_set_output_and_unmute(struct hda_codec *codec, |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3419 | hda_nid_t pin, int pin_type, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3420 | hda_nid_t dac) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3421 | { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3422 | int i, num; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3423 | hda_nid_t nid, mix = 0; |
Takashi Iwai | ce503f3 | 2010-07-30 10:37:29 +0200 | [diff] [blame] | 3424 | hda_nid_t srcs[HDA_MAX_CONNECTIONS]; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3425 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3426 | alc_set_pin_output(codec, pin, pin_type); |
| 3427 | nid = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3428 | num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs)); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3429 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 3430 | if (alc_auto_mix_to_dac(codec, srcs[i]) != dac) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3431 | continue; |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3432 | mix = srcs[i]; |
| 3433 | break; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3434 | } |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3435 | if (!mix) |
| 3436 | return; |
| 3437 | |
| 3438 | /* need the manual connection? */ |
| 3439 | if (num > 1) |
| 3440 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i); |
| 3441 | /* unmute mixer widget inputs */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3442 | if (nid_has_mute(codec, mix, HDA_INPUT)) { |
| 3443 | 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] | 3444 | AMP_IN_UNMUTE(0)); |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3445 | 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] | 3446 | AMP_IN_UNMUTE(1)); |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3447 | } |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3448 | /* initialize volume */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3449 | nid = alc_look_for_out_vol_nid(codec, pin, dac); |
| 3450 | if (nid) |
| 3451 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 3452 | AMP_OUT_ZERO); |
Takashi Iwai | 43dea22 | 2011-11-06 11:25:34 +0100 | [diff] [blame] | 3453 | |
| 3454 | /* unmute DAC if it's not assigned to a mixer */ |
| 3455 | nid = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3456 | if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT)) |
| 3457 | snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 3458 | AMP_OUT_ZERO); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3459 | } |
| 3460 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3461 | static void alc_auto_init_multi_out(struct hda_codec *codec) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3462 | { |
| 3463 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3464 | int pin_type = get_pin_type(spec->autocfg.line_out_type); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3465 | int i; |
| 3466 | |
| 3467 | for (i = 0; i <= HDA_SIDE; i++) { |
| 3468 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; |
| 3469 | if (nid) |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3470 | alc_auto_set_output_and_unmute(codec, nid, pin_type, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3471 | spec->multiout.dac_nids[i]); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3472 | } |
| 3473 | } |
| 3474 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3475 | static void alc_auto_init_extra_out(struct hda_codec *codec) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3476 | { |
| 3477 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3478 | int i; |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3479 | hda_nid_t pin, dac; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3480 | |
David Henningsson | 636030e | 2011-10-12 19:26:03 +0200 | [diff] [blame] | 3481 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3482 | if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT) |
| 3483 | break; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3484 | pin = spec->autocfg.hp_pins[i]; |
| 3485 | if (!pin) |
| 3486 | break; |
| 3487 | dac = spec->multiout.hp_out_nid[i]; |
| 3488 | if (!dac) { |
| 3489 | if (i > 0 && spec->multiout.hp_out_nid[0]) |
| 3490 | dac = spec->multiout.hp_out_nid[0]; |
| 3491 | else |
| 3492 | dac = spec->multiout.dac_nids[0]; |
| 3493 | } |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3494 | alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac); |
| 3495 | } |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3496 | for (i = 0; i < spec->autocfg.speaker_outs; i++) { |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3497 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) |
| 3498 | break; |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3499 | pin = spec->autocfg.speaker_pins[i]; |
| 3500 | if (!pin) |
| 3501 | break; |
| 3502 | dac = spec->multiout.extra_out_nid[i]; |
| 3503 | if (!dac) { |
| 3504 | if (i > 0 && spec->multiout.extra_out_nid[0]) |
| 3505 | dac = spec->multiout.extra_out_nid[0]; |
| 3506 | else |
| 3507 | dac = spec->multiout.dac_nids[0]; |
| 3508 | } |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3509 | alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac); |
| 3510 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3511 | } |
| 3512 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3513 | /* |
| 3514 | * multi-io helper |
| 3515 | */ |
| 3516 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3517 | unsigned int location, |
| 3518 | int offset) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3519 | { |
| 3520 | struct alc_spec *spec = codec->spec; |
| 3521 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3522 | hda_nid_t prime_dac = spec->private_dac_nids[0]; |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3523 | int type, i, dacs, num_pins = 0; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3524 | |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3525 | dacs = spec->multiout.num_dacs; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3526 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { |
| 3527 | for (i = 0; i < cfg->num_inputs; i++) { |
| 3528 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3529 | hda_nid_t dac = 0; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3530 | unsigned int defcfg, caps; |
| 3531 | if (cfg->inputs[i].type != type) |
| 3532 | continue; |
| 3533 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
| 3534 | if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX) |
| 3535 | continue; |
| 3536 | if (location && get_defcfg_location(defcfg) != location) |
| 3537 | continue; |
| 3538 | caps = snd_hda_query_pin_caps(codec, nid); |
| 3539 | if (!(caps & AC_PINCAP_OUT)) |
| 3540 | continue; |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3541 | if (offset && offset + num_pins < dacs) { |
| 3542 | dac = spec->private_dac_nids[offset + num_pins]; |
| 3543 | if (!alc_auto_is_dac_reachable(codec, nid, dac)) |
| 3544 | dac = 0; |
| 3545 | } |
| 3546 | if (!dac) |
| 3547 | dac = alc_auto_look_for_dac(codec, nid); |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3548 | if (!dac) |
| 3549 | continue; |
| 3550 | spec->multi_io[num_pins].pin = nid; |
| 3551 | spec->multi_io[num_pins].dac = dac; |
| 3552 | num_pins++; |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3553 | spec->private_dac_nids[spec->multiout.num_dacs++] = dac; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3554 | } |
| 3555 | } |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3556 | spec->multiout.num_dacs = dacs; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3557 | if (num_pins < 2) { |
| 3558 | /* clear up again */ |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3559 | memset(spec->private_dac_nids + dacs, 0, |
| 3560 | sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs)); |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3561 | spec->private_dac_nids[0] = prime_dac; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3562 | return 0; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3563 | } |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3564 | return num_pins; |
| 3565 | } |
| 3566 | |
| 3567 | static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol, |
| 3568 | struct snd_ctl_elem_info *uinfo) |
| 3569 | { |
| 3570 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3571 | struct alc_spec *spec = codec->spec; |
| 3572 | |
| 3573 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 3574 | uinfo->count = 1; |
| 3575 | uinfo->value.enumerated.items = spec->multi_ios + 1; |
| 3576 | if (uinfo->value.enumerated.item > spec->multi_ios) |
| 3577 | uinfo->value.enumerated.item = spec->multi_ios; |
| 3578 | sprintf(uinfo->value.enumerated.name, "%dch", |
| 3579 | (uinfo->value.enumerated.item + 1) * 2); |
| 3580 | return 0; |
| 3581 | } |
| 3582 | |
| 3583 | static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol, |
| 3584 | struct snd_ctl_elem_value *ucontrol) |
| 3585 | { |
| 3586 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3587 | struct alc_spec *spec = codec->spec; |
| 3588 | ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2; |
| 3589 | return 0; |
| 3590 | } |
| 3591 | |
| 3592 | static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output) |
| 3593 | { |
| 3594 | struct alc_spec *spec = codec->spec; |
| 3595 | hda_nid_t nid = spec->multi_io[idx].pin; |
| 3596 | |
| 3597 | if (!spec->multi_io[idx].ctl_in) |
| 3598 | spec->multi_io[idx].ctl_in = |
| 3599 | snd_hda_codec_read(codec, nid, 0, |
| 3600 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 3601 | if (output) { |
| 3602 | snd_hda_codec_update_cache(codec, nid, 0, |
| 3603 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 3604 | PIN_OUT); |
| 3605 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
| 3606 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
| 3607 | HDA_AMP_MUTE, 0); |
| 3608 | alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac); |
| 3609 | } else { |
| 3610 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
| 3611 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
| 3612 | HDA_AMP_MUTE, HDA_AMP_MUTE); |
| 3613 | snd_hda_codec_update_cache(codec, nid, 0, |
| 3614 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 3615 | spec->multi_io[idx].ctl_in); |
| 3616 | } |
| 3617 | return 0; |
| 3618 | } |
| 3619 | |
| 3620 | static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol, |
| 3621 | struct snd_ctl_elem_value *ucontrol) |
| 3622 | { |
| 3623 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3624 | struct alc_spec *spec = codec->spec; |
| 3625 | int i, ch; |
| 3626 | |
| 3627 | ch = ucontrol->value.enumerated.item[0]; |
| 3628 | if (ch < 0 || ch > spec->multi_ios) |
| 3629 | return -EINVAL; |
| 3630 | if (ch == (spec->ext_channel_count - 1) / 2) |
| 3631 | return 0; |
| 3632 | spec->ext_channel_count = (ch + 1) * 2; |
| 3633 | for (i = 0; i < spec->multi_ios; i++) |
| 3634 | alc_set_multi_io(codec, i, i < ch); |
| 3635 | spec->multiout.max_channels = spec->ext_channel_count; |
Takashi Iwai | 7b1655f | 2011-07-14 15:31:21 +0200 | [diff] [blame] | 3636 | if (spec->need_dac_fix && !spec->const_channel_count) |
| 3637 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3638 | return 1; |
| 3639 | } |
| 3640 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 3641 | static const struct snd_kcontrol_new alc_auto_channel_mode_enum = { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3642 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3643 | .name = "Channel Mode", |
| 3644 | .info = alc_auto_ch_mode_info, |
| 3645 | .get = alc_auto_ch_mode_get, |
| 3646 | .put = alc_auto_ch_mode_put, |
| 3647 | }; |
| 3648 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3649 | static int alc_auto_add_multi_channel_mode(struct hda_codec *codec) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3650 | { |
| 3651 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3652 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3653 | if (spec->multi_ios > 0) { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3654 | struct snd_kcontrol_new *knew; |
| 3655 | |
| 3656 | knew = alc_kcontrol_new(spec); |
| 3657 | if (!knew) |
| 3658 | return -ENOMEM; |
| 3659 | *knew = alc_auto_channel_mode_enum; |
| 3660 | knew->name = kstrdup("Channel Mode", GFP_KERNEL); |
| 3661 | if (!knew->name) |
| 3662 | return -ENOMEM; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3663 | } |
| 3664 | return 0; |
| 3665 | } |
| 3666 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3667 | /* filter out invalid adc_nids (and capsrc_nids) that don't give all |
| 3668 | * active input pins |
| 3669 | */ |
| 3670 | static void alc_remove_invalid_adc_nids(struct hda_codec *codec) |
| 3671 | { |
| 3672 | struct alc_spec *spec = codec->spec; |
| 3673 | const struct hda_input_mux *imux; |
| 3674 | hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)]; |
| 3675 | hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)]; |
| 3676 | int i, n, nums; |
| 3677 | |
| 3678 | imux = spec->input_mux; |
| 3679 | if (!imux) |
| 3680 | return; |
| 3681 | if (spec->dyn_adc_switch) |
| 3682 | return; |
| 3683 | |
| 3684 | nums = 0; |
| 3685 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 3686 | hda_nid_t cap = spec->private_capsrc_nids[n]; |
| 3687 | int num_conns = snd_hda_get_conn_list(codec, cap, NULL); |
| 3688 | for (i = 0; i < imux->num_items; i++) { |
| 3689 | hda_nid_t pin = spec->imux_pins[i]; |
| 3690 | if (pin) { |
| 3691 | if (get_connection_index(codec, cap, pin) < 0) |
| 3692 | break; |
| 3693 | } else if (num_conns <= imux->items[i].index) |
| 3694 | break; |
| 3695 | } |
| 3696 | if (i >= imux->num_items) { |
| 3697 | adc_nids[nums] = spec->private_adc_nids[n]; |
| 3698 | capsrc_nids[nums++] = cap; |
| 3699 | } |
| 3700 | } |
| 3701 | if (!nums) { |
| 3702 | /* check whether ADC-switch is possible */ |
| 3703 | if (!alc_check_dyn_adc_switch(codec)) { |
| 3704 | printk(KERN_WARNING "hda_codec: %s: no valid ADC found;" |
| 3705 | " using fallback 0x%x\n", |
| 3706 | codec->chip_name, spec->private_adc_nids[0]); |
| 3707 | spec->num_adc_nids = 1; |
| 3708 | spec->auto_mic = 0; |
| 3709 | return; |
| 3710 | } |
| 3711 | } else if (nums != spec->num_adc_nids) { |
| 3712 | memcpy(spec->private_adc_nids, adc_nids, |
| 3713 | nums * sizeof(hda_nid_t)); |
| 3714 | memcpy(spec->private_capsrc_nids, capsrc_nids, |
| 3715 | nums * sizeof(hda_nid_t)); |
| 3716 | spec->num_adc_nids = nums; |
| 3717 | } |
| 3718 | |
| 3719 | if (spec->auto_mic) |
| 3720 | alc_auto_mic_check_imux(codec); /* check auto-mic setups */ |
| 3721 | else if (spec->input_mux->num_items == 1) |
| 3722 | spec->num_adc_nids = 1; /* reduce to a single ADC */ |
| 3723 | } |
| 3724 | |
| 3725 | /* |
| 3726 | * initialize ADC paths |
| 3727 | */ |
| 3728 | static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx) |
| 3729 | { |
| 3730 | struct alc_spec *spec = codec->spec; |
| 3731 | hda_nid_t nid; |
| 3732 | |
| 3733 | nid = spec->adc_nids[adc_idx]; |
| 3734 | /* mute ADC */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3735 | if (nid_has_mute(codec, nid, HDA_INPUT)) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3736 | snd_hda_codec_write(codec, nid, 0, |
| 3737 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 3738 | AMP_IN_MUTE(0)); |
| 3739 | return; |
| 3740 | } |
| 3741 | if (!spec->capsrc_nids) |
| 3742 | return; |
| 3743 | nid = spec->capsrc_nids[adc_idx]; |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3744 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3745 | snd_hda_codec_write(codec, nid, 0, |
| 3746 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 3747 | AMP_OUT_MUTE); |
| 3748 | } |
| 3749 | |
| 3750 | static void alc_auto_init_input_src(struct hda_codec *codec) |
| 3751 | { |
| 3752 | struct alc_spec *spec = codec->spec; |
| 3753 | int c, nums; |
| 3754 | |
| 3755 | for (c = 0; c < spec->num_adc_nids; c++) |
| 3756 | alc_auto_init_adc(codec, c); |
| 3757 | if (spec->dyn_adc_switch) |
| 3758 | nums = 1; |
| 3759 | else |
| 3760 | nums = spec->num_adc_nids; |
| 3761 | for (c = 0; c < nums; c++) |
| 3762 | alc_mux_select(codec, 0, spec->cur_mux[c], true); |
| 3763 | } |
| 3764 | |
| 3765 | /* add mic boosts if needed */ |
| 3766 | static int alc_auto_add_mic_boost(struct hda_codec *codec) |
| 3767 | { |
| 3768 | struct alc_spec *spec = codec->spec; |
| 3769 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3770 | int i, err; |
| 3771 | int type_idx = 0; |
| 3772 | hda_nid_t nid; |
| 3773 | const char *prev_label = NULL; |
| 3774 | |
| 3775 | for (i = 0; i < cfg->num_inputs; i++) { |
| 3776 | if (cfg->inputs[i].type > AUTO_PIN_MIC) |
| 3777 | break; |
| 3778 | nid = cfg->inputs[i].pin; |
| 3779 | if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { |
| 3780 | const char *label; |
| 3781 | char boost_label[32]; |
| 3782 | |
| 3783 | label = hda_get_autocfg_input_label(codec, cfg, i); |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 3784 | if (spec->shared_mic_hp && !strcmp(label, "Misc")) |
| 3785 | label = "Headphone Mic"; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3786 | if (prev_label && !strcmp(label, prev_label)) |
| 3787 | type_idx++; |
| 3788 | else |
| 3789 | type_idx = 0; |
| 3790 | prev_label = label; |
| 3791 | |
| 3792 | snprintf(boost_label, sizeof(boost_label), |
| 3793 | "%s Boost Volume", label); |
| 3794 | err = add_control(spec, ALC_CTL_WIDGET_VOL, |
| 3795 | boost_label, type_idx, |
| 3796 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT)); |
| 3797 | if (err < 0) |
| 3798 | return err; |
| 3799 | } |
| 3800 | } |
| 3801 | return 0; |
| 3802 | } |
| 3803 | |
| 3804 | /* select or unmute the given capsrc route */ |
| 3805 | static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap, |
| 3806 | int idx) |
| 3807 | { |
| 3808 | if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) { |
| 3809 | snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx, |
| 3810 | HDA_AMP_MUTE, 0); |
| 3811 | } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) { |
| 3812 | snd_hda_codec_write_cache(codec, cap, 0, |
| 3813 | AC_VERB_SET_CONNECT_SEL, idx); |
| 3814 | } |
| 3815 | } |
| 3816 | |
| 3817 | /* set the default connection to that pin */ |
| 3818 | static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin) |
| 3819 | { |
| 3820 | struct alc_spec *spec = codec->spec; |
| 3821 | int i; |
| 3822 | |
| 3823 | if (!pin) |
| 3824 | return 0; |
| 3825 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 3826 | hda_nid_t cap = spec->capsrc_nids ? |
| 3827 | spec->capsrc_nids[i] : spec->adc_nids[i]; |
| 3828 | int idx; |
| 3829 | |
| 3830 | idx = get_connection_index(codec, cap, pin); |
| 3831 | if (idx < 0) |
| 3832 | continue; |
| 3833 | select_or_unmute_capsrc(codec, cap, idx); |
| 3834 | return i; /* return the found index */ |
| 3835 | } |
| 3836 | return -1; /* not found */ |
| 3837 | } |
| 3838 | |
| 3839 | /* initialize some special cases for input sources */ |
| 3840 | static void alc_init_special_input_src(struct hda_codec *codec) |
| 3841 | { |
| 3842 | struct alc_spec *spec = codec->spec; |
| 3843 | int i; |
| 3844 | |
| 3845 | for (i = 0; i < spec->autocfg.num_inputs; i++) |
| 3846 | init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin); |
| 3847 | } |
| 3848 | |
| 3849 | /* assign appropriate capture mixers */ |
| 3850 | static void set_capture_mixer(struct hda_codec *codec) |
| 3851 | { |
| 3852 | struct alc_spec *spec = codec->spec; |
| 3853 | static const struct snd_kcontrol_new *caps[2][3] = { |
| 3854 | { alc_capture_mixer_nosrc1, |
| 3855 | alc_capture_mixer_nosrc2, |
| 3856 | alc_capture_mixer_nosrc3 }, |
| 3857 | { alc_capture_mixer1, |
| 3858 | alc_capture_mixer2, |
| 3859 | alc_capture_mixer3 }, |
| 3860 | }; |
| 3861 | |
| 3862 | /* check whether either of ADC or MUX has a volume control */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3863 | if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3864 | if (!spec->capsrc_nids) |
| 3865 | return; /* no volume */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3866 | if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT)) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3867 | return; /* no volume in capsrc, too */ |
| 3868 | spec->vol_in_capsrc = 1; |
| 3869 | } |
| 3870 | |
| 3871 | if (spec->num_adc_nids > 0) { |
| 3872 | int mux = 0; |
| 3873 | int num_adcs = 0; |
| 3874 | |
| 3875 | if (spec->input_mux && spec->input_mux->num_items > 1) |
| 3876 | mux = 1; |
| 3877 | if (spec->auto_mic) { |
| 3878 | num_adcs = 1; |
| 3879 | mux = 0; |
| 3880 | } else if (spec->dyn_adc_switch) |
| 3881 | num_adcs = 1; |
| 3882 | if (!num_adcs) { |
| 3883 | if (spec->num_adc_nids > 3) |
| 3884 | spec->num_adc_nids = 3; |
| 3885 | else if (!spec->num_adc_nids) |
| 3886 | return; |
| 3887 | num_adcs = spec->num_adc_nids; |
| 3888 | } |
| 3889 | spec->cap_mixer = caps[mux][num_adcs - 1]; |
| 3890 | } |
| 3891 | } |
| 3892 | |
| 3893 | /* |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 3894 | * standard auto-parser initializations |
| 3895 | */ |
| 3896 | static void alc_auto_init_std(struct hda_codec *codec) |
| 3897 | { |
| 3898 | struct alc_spec *spec = codec->spec; |
| 3899 | alc_auto_init_multi_out(codec); |
| 3900 | alc_auto_init_extra_out(codec); |
| 3901 | alc_auto_init_analog_input(codec); |
| 3902 | alc_auto_init_input_src(codec); |
| 3903 | alc_auto_init_digital(codec); |
| 3904 | if (spec->unsol_event) |
| 3905 | alc_inithook(codec); |
| 3906 | } |
| 3907 | |
| 3908 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3909 | * Digital-beep handlers |
| 3910 | */ |
| 3911 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
| 3912 | #define set_beep_amp(spec, nid, idx, dir) \ |
| 3913 | ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir)) |
| 3914 | |
| 3915 | static const struct snd_pci_quirk beep_white_list[] = { |
| 3916 | SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1), |
| 3917 | SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1), |
| 3918 | SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1), |
| 3919 | SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1), |
| 3920 | SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1), |
| 3921 | {} |
| 3922 | }; |
| 3923 | |
| 3924 | static inline int has_cdefine_beep(struct hda_codec *codec) |
| 3925 | { |
| 3926 | struct alc_spec *spec = codec->spec; |
| 3927 | const struct snd_pci_quirk *q; |
| 3928 | q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list); |
| 3929 | if (q) |
| 3930 | return q->value; |
| 3931 | return spec->cdefine.enable_pcbeep; |
| 3932 | } |
| 3933 | #else |
| 3934 | #define set_beep_amp(spec, nid, idx, dir) /* NOP */ |
| 3935 | #define has_cdefine_beep(codec) 0 |
| 3936 | #endif |
| 3937 | |
| 3938 | /* parse the BIOS configuration and set up the alc_spec */ |
| 3939 | /* return 1 if successful, 0 if the proper config is not found, |
| 3940 | * or a negative error code |
| 3941 | */ |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3942 | static int alc_parse_auto_config(struct hda_codec *codec, |
| 3943 | const hda_nid_t *ignore_nids, |
| 3944 | const hda_nid_t *ssid_nids) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3945 | { |
| 3946 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3947 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3948 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3949 | |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 3950 | err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids, |
| 3951 | spec->parse_flags); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3952 | if (err < 0) |
| 3953 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3954 | if (!cfg->line_outs) { |
| 3955 | if (cfg->dig_outs || cfg->dig_in_pin) { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3956 | spec->multiout.max_channels = 2; |
| 3957 | spec->no_analog = 1; |
| 3958 | goto dig_only; |
| 3959 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3960 | return 0; /* can't find valid BIOS pin config */ |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3961 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3962 | |
Takashi Iwai | 0650367 | 2011-10-06 08:27:19 +0200 | [diff] [blame] | 3963 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && |
| 3964 | cfg->line_outs <= cfg->hp_outs) { |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3965 | /* use HP as primary out */ |
| 3966 | cfg->speaker_outs = cfg->line_outs; |
| 3967 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 3968 | sizeof(cfg->speaker_pins)); |
| 3969 | cfg->line_outs = cfg->hp_outs; |
| 3970 | memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins)); |
| 3971 | cfg->hp_outs = 0; |
| 3972 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); |
| 3973 | cfg->line_out_type = AUTO_PIN_HP_OUT; |
| 3974 | } |
| 3975 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3976 | err = alc_auto_fill_dac_nids(codec); |
| 3977 | if (err < 0) |
| 3978 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3979 | err = alc_auto_add_multi_channel_mode(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3980 | if (err < 0) |
| 3981 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3982 | err = alc_auto_create_multi_out_ctls(codec, cfg); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3983 | if (err < 0) |
| 3984 | return err; |
| 3985 | err = alc_auto_create_hp_out(codec); |
| 3986 | if (err < 0) |
| 3987 | return err; |
| 3988 | err = alc_auto_create_speaker_out(codec); |
| 3989 | if (err < 0) |
| 3990 | return err; |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 3991 | err = alc_auto_create_shared_input(codec); |
| 3992 | if (err < 0) |
| 3993 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3994 | err = alc_auto_create_input_ctls(codec); |
| 3995 | if (err < 0) |
| 3996 | return err; |
| 3997 | |
| 3998 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3999 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4000 | dig_only: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4001 | alc_auto_parse_digital(codec); |
| 4002 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4003 | if (!spec->no_analog) |
| 4004 | alc_remove_invalid_adc_nids(codec); |
| 4005 | |
| 4006 | if (ssid_nids) |
| 4007 | alc_ssid_check(codec, ssid_nids); |
| 4008 | |
| 4009 | if (!spec->no_analog) { |
| 4010 | alc_auto_check_switches(codec); |
| 4011 | err = alc_auto_add_mic_boost(codec); |
| 4012 | if (err < 0) |
| 4013 | return err; |
| 4014 | } |
| 4015 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4016 | if (spec->kctls.list) |
| 4017 | add_mixer(spec, spec->kctls.list); |
| 4018 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4019 | return 1; |
| 4020 | } |
| 4021 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4022 | static int alc880_parse_auto_config(struct hda_codec *codec) |
| 4023 | { |
| 4024 | static const hda_nid_t alc880_ignore[] = { 0x1d, 0 }; |
| 4025 | static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 4026 | return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids); |
| 4027 | } |
| 4028 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4029 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4030 | static const struct hda_amp_list alc880_loopbacks[] = { |
| 4031 | { 0x0b, HDA_INPUT, 0 }, |
| 4032 | { 0x0b, HDA_INPUT, 1 }, |
| 4033 | { 0x0b, HDA_INPUT, 2 }, |
| 4034 | { 0x0b, HDA_INPUT, 3 }, |
| 4035 | { 0x0b, HDA_INPUT, 4 }, |
| 4036 | { } /* end */ |
| 4037 | }; |
| 4038 | #endif |
| 4039 | |
| 4040 | /* |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4041 | * ALC880 fix-ups |
| 4042 | */ |
| 4043 | enum { |
| 4044 | ALC880_FIXUP_GPIO2, |
| 4045 | ALC880_FIXUP_MEDION_RIM, |
| 4046 | }; |
| 4047 | |
| 4048 | static const struct alc_fixup alc880_fixups[] = { |
| 4049 | [ALC880_FIXUP_GPIO2] = { |
| 4050 | .type = ALC_FIXUP_VERBS, |
| 4051 | .v.verbs = alc_gpio2_init_verbs, |
| 4052 | }, |
| 4053 | [ALC880_FIXUP_MEDION_RIM] = { |
| 4054 | .type = ALC_FIXUP_VERBS, |
| 4055 | .v.verbs = (const struct hda_verb[]) { |
| 4056 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4057 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 }, |
| 4058 | { } |
| 4059 | }, |
| 4060 | .chained = true, |
| 4061 | .chain_id = ALC880_FIXUP_GPIO2, |
| 4062 | }, |
| 4063 | }; |
| 4064 | |
| 4065 | static const struct snd_pci_quirk alc880_fixup_tbl[] = { |
| 4066 | SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM), |
| 4067 | {} |
| 4068 | }; |
| 4069 | |
| 4070 | |
| 4071 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4072 | * board setups |
| 4073 | */ |
| 4074 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4075 | #define alc_board_config \ |
| 4076 | snd_hda_check_board_config |
| 4077 | #define alc_board_codec_sid_config \ |
| 4078 | snd_hda_check_board_codec_sid_config |
| 4079 | #include "alc_quirks.c" |
| 4080 | #else |
| 4081 | #define alc_board_config(codec, nums, models, tbl) -1 |
| 4082 | #define alc_board_codec_sid_config(codec, nums, models, tbl) -1 |
| 4083 | #define setup_preset(codec, x) /* NOP */ |
| 4084 | #endif |
| 4085 | |
| 4086 | /* |
| 4087 | * OK, here we have finally the patch for ALC880 |
| 4088 | */ |
| 4089 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4090 | #include "alc880_quirks.c" |
| 4091 | #endif |
| 4092 | |
| 4093 | static int patch_alc880(struct hda_codec *codec) |
| 4094 | { |
| 4095 | struct alc_spec *spec; |
| 4096 | int board_config; |
| 4097 | int err; |
| 4098 | |
| 4099 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4100 | if (spec == NULL) |
| 4101 | return -ENOMEM; |
| 4102 | |
| 4103 | codec->spec = spec; |
| 4104 | |
| 4105 | spec->mixer_nid = 0x0b; |
Takashi Iwai | 7b1655f | 2011-07-14 15:31:21 +0200 | [diff] [blame] | 4106 | spec->need_dac_fix = 1; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4107 | |
| 4108 | board_config = alc_board_config(codec, ALC880_MODEL_LAST, |
| 4109 | alc880_models, alc880_cfg_tbl); |
| 4110 | if (board_config < 0) { |
| 4111 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 4112 | codec->chip_name); |
| 4113 | board_config = ALC_MODEL_AUTO; |
| 4114 | } |
| 4115 | |
| 4116 | if (board_config == ALC_MODEL_AUTO) { |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4117 | alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups); |
| 4118 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 4119 | } |
| 4120 | |
| 4121 | if (board_config == ALC_MODEL_AUTO) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4122 | /* automatic parse from the BIOS config */ |
| 4123 | err = alc880_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4124 | if (err < 0) |
| 4125 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4126 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4127 | else if (!err) { |
| 4128 | printk(KERN_INFO |
| 4129 | "hda_codec: Cannot set up configuration " |
| 4130 | "from BIOS. Using 3-stack mode...\n"); |
| 4131 | board_config = ALC880_3ST; |
| 4132 | } |
| 4133 | #endif |
| 4134 | } |
| 4135 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4136 | if (board_config != ALC_MODEL_AUTO) |
| 4137 | setup_preset(codec, &alc880_presets[board_config]); |
| 4138 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4139 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4140 | alc_auto_fill_adc_caps(codec); |
| 4141 | alc_rebuild_imux_for_auto_mic(codec); |
| 4142 | alc_remove_invalid_adc_nids(codec); |
| 4143 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4144 | |
| 4145 | if (!spec->no_analog && !spec->cap_mixer) |
| 4146 | set_capture_mixer(codec); |
| 4147 | |
| 4148 | if (!spec->no_analog) { |
| 4149 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4150 | if (err < 0) |
| 4151 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4152 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 4153 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4154 | |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4155 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4156 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4157 | spec->vmaster_nid = 0x0c; |
| 4158 | |
| 4159 | codec->patch_ops = alc_patch_ops; |
| 4160 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 4161 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4162 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4163 | if (!spec->loopback.amplist) |
| 4164 | spec->loopback.amplist = alc880_loopbacks; |
| 4165 | #endif |
| 4166 | |
| 4167 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4168 | |
| 4169 | error: |
| 4170 | alc_free(codec); |
| 4171 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | |
| 4175 | /* |
| 4176 | * ALC260 support |
| 4177 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4178 | static int alc260_parse_auto_config(struct hda_codec *codec) |
| 4179 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4180 | static const hda_nid_t alc260_ignore[] = { 0x17, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4181 | static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 }; |
| 4182 | return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4183 | } |
| 4184 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4185 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4186 | static const struct hda_amp_list alc260_loopbacks[] = { |
| 4187 | { 0x07, HDA_INPUT, 0 }, |
| 4188 | { 0x07, HDA_INPUT, 1 }, |
| 4189 | { 0x07, HDA_INPUT, 2 }, |
| 4190 | { 0x07, HDA_INPUT, 3 }, |
| 4191 | { 0x07, HDA_INPUT, 4 }, |
| 4192 | { } /* end */ |
| 4193 | }; |
| 4194 | #endif |
| 4195 | |
| 4196 | /* |
| 4197 | * Pin config fixes |
| 4198 | */ |
| 4199 | enum { |
| 4200 | PINFIX_HP_DC5750, |
| 4201 | }; |
| 4202 | |
| 4203 | static const struct alc_fixup alc260_fixups[] = { |
| 4204 | [PINFIX_HP_DC5750] = { |
| 4205 | .type = ALC_FIXUP_PINS, |
| 4206 | .v.pins = (const struct alc_pincfg[]) { |
| 4207 | { 0x11, 0x90130110 }, /* speaker */ |
| 4208 | { } |
| 4209 | } |
| 4210 | }, |
| 4211 | }; |
| 4212 | |
| 4213 | static const struct snd_pci_quirk alc260_fixup_tbl[] = { |
| 4214 | SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750), |
| 4215 | {} |
| 4216 | }; |
| 4217 | |
| 4218 | /* |
| 4219 | */ |
| 4220 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4221 | #include "alc260_quirks.c" |
| 4222 | #endif |
| 4223 | |
| 4224 | static int patch_alc260(struct hda_codec *codec) |
| 4225 | { |
| 4226 | struct alc_spec *spec; |
| 4227 | int err, board_config; |
| 4228 | |
| 4229 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4230 | if (spec == NULL) |
| 4231 | return -ENOMEM; |
| 4232 | |
| 4233 | codec->spec = spec; |
| 4234 | |
| 4235 | spec->mixer_nid = 0x07; |
| 4236 | |
| 4237 | board_config = alc_board_config(codec, ALC260_MODEL_LAST, |
| 4238 | alc260_models, alc260_cfg_tbl); |
| 4239 | if (board_config < 0) { |
| 4240 | snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 4241 | codec->chip_name); |
| 4242 | board_config = ALC_MODEL_AUTO; |
| 4243 | } |
| 4244 | |
| 4245 | if (board_config == ALC_MODEL_AUTO) { |
| 4246 | alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); |
| 4247 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 4248 | } |
| 4249 | |
| 4250 | if (board_config == ALC_MODEL_AUTO) { |
| 4251 | /* automatic parse from the BIOS config */ |
| 4252 | err = alc260_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4253 | if (err < 0) |
| 4254 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4255 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4256 | else if (!err) { |
| 4257 | printk(KERN_INFO |
| 4258 | "hda_codec: Cannot set up configuration " |
| 4259 | "from BIOS. Using base mode...\n"); |
| 4260 | board_config = ALC260_BASIC; |
| 4261 | } |
| 4262 | #endif |
| 4263 | } |
| 4264 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4265 | if (board_config != ALC_MODEL_AUTO) |
| 4266 | setup_preset(codec, &alc260_presets[board_config]); |
| 4267 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4268 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4269 | alc_auto_fill_adc_caps(codec); |
| 4270 | alc_rebuild_imux_for_auto_mic(codec); |
| 4271 | alc_remove_invalid_adc_nids(codec); |
| 4272 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4273 | |
| 4274 | if (!spec->no_analog && !spec->cap_mixer) |
| 4275 | set_capture_mixer(codec); |
| 4276 | |
| 4277 | if (!spec->no_analog) { |
| 4278 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4279 | if (err < 0) |
| 4280 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4281 | set_beep_amp(spec, 0x07, 0x05, HDA_INPUT); |
| 4282 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4283 | |
| 4284 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4285 | |
| 4286 | spec->vmaster_nid = 0x08; |
| 4287 | |
| 4288 | codec->patch_ops = alc_patch_ops; |
| 4289 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | 8452a98 | 2011-07-08 16:19:48 +0200 | [diff] [blame] | 4290 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4291 | spec->shutup = alc_eapd_shutup; |
| 4292 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4293 | if (!spec->loopback.amplist) |
| 4294 | spec->loopback.amplist = alc260_loopbacks; |
| 4295 | #endif |
| 4296 | |
| 4297 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4298 | |
| 4299 | error: |
| 4300 | alc_free(codec); |
| 4301 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | |
| 4305 | /* |
| 4306 | * ALC882/883/885/888/889 support |
| 4307 | * |
| 4308 | * ALC882 is almost identical with ALC880 but has cleaner and more flexible |
| 4309 | * configuration. Each pin widget can choose any input DACs and a mixer. |
| 4310 | * Each ADC is connected from a mixer of all inputs. This makes possible |
| 4311 | * 6-channel independent captures. |
| 4312 | * |
| 4313 | * In addition, an independent DAC for the multi-playback (not used in this |
| 4314 | * driver yet). |
| 4315 | */ |
| 4316 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4317 | #define alc882_loopbacks alc880_loopbacks |
| 4318 | #endif |
| 4319 | |
| 4320 | /* |
| 4321 | * Pin config fixes |
| 4322 | */ |
| 4323 | enum { |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4324 | ALC882_FIXUP_ABIT_AW9D_MAX, |
| 4325 | ALC882_FIXUP_LENOVO_Y530, |
| 4326 | ALC882_FIXUP_PB_M5210, |
| 4327 | ALC882_FIXUP_ACER_ASPIRE_7736, |
| 4328 | ALC882_FIXUP_ASUS_W90V, |
| 4329 | ALC889_FIXUP_VAIO_TT, |
Takashi Iwai | 0e7cc2e | 2011-11-09 12:42:48 +0100 | [diff] [blame] | 4330 | ALC888_FIXUP_EEE1601, |
Takashi Iwai | 177943a | 2011-11-09 12:55:18 +0100 | [diff] [blame] | 4331 | ALC882_FIXUP_EAPD, |
Takashi Iwai | 7a6069b | 2011-11-09 15:22:01 +0100 | [diff] [blame] | 4332 | ALC883_FIXUP_EAPD, |
Takashi Iwai | 8812c4f | 2011-11-09 17:39:15 +0100 | [diff] [blame] | 4333 | ALC883_FIXUP_ACER_EAPD, |
Takashi Iwai | eb844d5 | 2011-11-09 18:03:07 +0100 | [diff] [blame] | 4334 | ALC882_FIXUP_GPIO3, |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 4335 | ALC889_FIXUP_COEF, |
| 4336 | ALC882_FIXUP_ASUS_W2JC, |
Takashi Iwai | c3e837b | 2011-11-10 16:01:47 +0100 | [diff] [blame] | 4337 | ALC882_FIXUP_ACER_ASPIRE_4930G, |
| 4338 | ALC882_FIXUP_ACER_ASPIRE_8930G, |
| 4339 | ALC882_FIXUP_ASPIRE_8930G_VERBS, |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 4340 | ALC885_FIXUP_MACPRO_GPIO, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4341 | }; |
| 4342 | |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 4343 | static void alc889_fixup_coef(struct hda_codec *codec, |
| 4344 | const struct alc_fixup *fix, int action) |
| 4345 | { |
| 4346 | if (action != ALC_FIXUP_ACT_INIT) |
| 4347 | return; |
| 4348 | alc889_coef_init(codec); |
| 4349 | } |
| 4350 | |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 4351 | /* toggle speaker-output according to the hp-jack state */ |
| 4352 | static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted) |
| 4353 | { |
| 4354 | unsigned int gpiostate, gpiomask, gpiodir; |
| 4355 | |
| 4356 | gpiostate = snd_hda_codec_read(codec, codec->afg, 0, |
| 4357 | AC_VERB_GET_GPIO_DATA, 0); |
| 4358 | |
| 4359 | if (!muted) |
| 4360 | gpiostate |= (1 << pin); |
| 4361 | else |
| 4362 | gpiostate &= ~(1 << pin); |
| 4363 | |
| 4364 | gpiomask = snd_hda_codec_read(codec, codec->afg, 0, |
| 4365 | AC_VERB_GET_GPIO_MASK, 0); |
| 4366 | gpiomask |= (1 << pin); |
| 4367 | |
| 4368 | gpiodir = snd_hda_codec_read(codec, codec->afg, 0, |
| 4369 | AC_VERB_GET_GPIO_DIRECTION, 0); |
| 4370 | gpiodir |= (1 << pin); |
| 4371 | |
| 4372 | |
| 4373 | snd_hda_codec_write(codec, codec->afg, 0, |
| 4374 | AC_VERB_SET_GPIO_MASK, gpiomask); |
| 4375 | snd_hda_codec_write(codec, codec->afg, 0, |
| 4376 | AC_VERB_SET_GPIO_DIRECTION, gpiodir); |
| 4377 | |
| 4378 | msleep(1); |
| 4379 | |
| 4380 | snd_hda_codec_write(codec, codec->afg, 0, |
| 4381 | AC_VERB_SET_GPIO_DATA, gpiostate); |
| 4382 | } |
| 4383 | |
| 4384 | /* set up GPIO at initialization */ |
| 4385 | static void alc885_fixup_macpro_gpio(struct hda_codec *codec, |
| 4386 | const struct alc_fixup *fix, int action) |
| 4387 | { |
| 4388 | if (action != ALC_FIXUP_ACT_INIT) |
| 4389 | return; |
| 4390 | alc882_gpio_mute(codec, 0, 0); |
| 4391 | alc882_gpio_mute(codec, 1, 0); |
| 4392 | } |
| 4393 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4394 | static const struct alc_fixup alc882_fixups[] = { |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4395 | [ALC882_FIXUP_ABIT_AW9D_MAX] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4396 | .type = ALC_FIXUP_PINS, |
| 4397 | .v.pins = (const struct alc_pincfg[]) { |
| 4398 | { 0x15, 0x01080104 }, /* side */ |
| 4399 | { 0x16, 0x01011012 }, /* rear */ |
| 4400 | { 0x17, 0x01016011 }, /* clfe */ |
| 4401 | { } |
| 4402 | } |
| 4403 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4404 | [ALC882_FIXUP_LENOVO_Y530] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4405 | .type = ALC_FIXUP_PINS, |
| 4406 | .v.pins = (const struct alc_pincfg[]) { |
| 4407 | { 0x15, 0x99130112 }, /* rear int speakers */ |
| 4408 | { 0x16, 0x99130111 }, /* subwoofer */ |
| 4409 | { } |
| 4410 | } |
| 4411 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4412 | [ALC882_FIXUP_PB_M5210] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4413 | .type = ALC_FIXUP_VERBS, |
| 4414 | .v.verbs = (const struct hda_verb[]) { |
| 4415 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, |
| 4416 | {} |
| 4417 | } |
| 4418 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4419 | [ALC882_FIXUP_ACER_ASPIRE_7736] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4420 | .type = ALC_FIXUP_SKU, |
| 4421 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
| 4422 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4423 | [ALC882_FIXUP_ASUS_W90V] = { |
Takashi Iwai | 5cdf745 | 2011-10-26 23:04:08 +0200 | [diff] [blame] | 4424 | .type = ALC_FIXUP_PINS, |
| 4425 | .v.pins = (const struct alc_pincfg[]) { |
| 4426 | { 0x16, 0x99130110 }, /* fix sequence for CLFE */ |
| 4427 | { } |
| 4428 | } |
| 4429 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4430 | [ALC889_FIXUP_VAIO_TT] = { |
| 4431 | .type = ALC_FIXUP_PINS, |
| 4432 | .v.pins = (const struct alc_pincfg[]) { |
| 4433 | { 0x17, 0x90170111 }, /* hidden surround speaker */ |
| 4434 | { } |
| 4435 | } |
| 4436 | }, |
Takashi Iwai | 0e7cc2e | 2011-11-09 12:42:48 +0100 | [diff] [blame] | 4437 | [ALC888_FIXUP_EEE1601] = { |
| 4438 | .type = ALC_FIXUP_VERBS, |
| 4439 | .v.verbs = (const struct hda_verb[]) { |
| 4440 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b }, |
| 4441 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 }, |
| 4442 | { } |
| 4443 | } |
Takashi Iwai | 177943a | 2011-11-09 12:55:18 +0100 | [diff] [blame] | 4444 | }, |
| 4445 | [ALC882_FIXUP_EAPD] = { |
| 4446 | .type = ALC_FIXUP_VERBS, |
| 4447 | .v.verbs = (const struct hda_verb[]) { |
| 4448 | /* change to EAPD mode */ |
| 4449 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4450 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 }, |
| 4451 | { } |
| 4452 | } |
| 4453 | }, |
Takashi Iwai | 7a6069b | 2011-11-09 15:22:01 +0100 | [diff] [blame] | 4454 | [ALC883_FIXUP_EAPD] = { |
| 4455 | .type = ALC_FIXUP_VERBS, |
| 4456 | .v.verbs = (const struct hda_verb[]) { |
| 4457 | /* change to EAPD mode */ |
| 4458 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4459 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, |
| 4460 | { } |
| 4461 | } |
| 4462 | }, |
Takashi Iwai | 8812c4f | 2011-11-09 17:39:15 +0100 | [diff] [blame] | 4463 | [ALC883_FIXUP_ACER_EAPD] = { |
| 4464 | .type = ALC_FIXUP_VERBS, |
| 4465 | .v.verbs = (const struct hda_verb[]) { |
| 4466 | /* eanable EAPD on Acer laptops */ |
| 4467 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4468 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, |
| 4469 | { } |
| 4470 | } |
| 4471 | }, |
Takashi Iwai | eb844d5 | 2011-11-09 18:03:07 +0100 | [diff] [blame] | 4472 | [ALC882_FIXUP_GPIO3] = { |
| 4473 | .type = ALC_FIXUP_VERBS, |
| 4474 | .v.verbs = alc_gpio3_init_verbs, |
| 4475 | }, |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 4476 | [ALC882_FIXUP_ASUS_W2JC] = { |
| 4477 | .type = ALC_FIXUP_VERBS, |
| 4478 | .v.verbs = alc_gpio1_init_verbs, |
| 4479 | .chained = true, |
| 4480 | .chain_id = ALC882_FIXUP_EAPD, |
| 4481 | }, |
| 4482 | [ALC889_FIXUP_COEF] = { |
| 4483 | .type = ALC_FIXUP_FUNC, |
| 4484 | .v.func = alc889_fixup_coef, |
| 4485 | }, |
Takashi Iwai | c3e837b | 2011-11-10 16:01:47 +0100 | [diff] [blame] | 4486 | [ALC882_FIXUP_ACER_ASPIRE_4930G] = { |
| 4487 | .type = ALC_FIXUP_PINS, |
| 4488 | .v.pins = (const struct alc_pincfg[]) { |
| 4489 | { 0x16, 0x99130111 }, /* CLFE speaker */ |
| 4490 | { 0x17, 0x99130112 }, /* surround speaker */ |
| 4491 | { } |
| 4492 | } |
| 4493 | }, |
| 4494 | [ALC882_FIXUP_ACER_ASPIRE_8930G] = { |
| 4495 | .type = ALC_FIXUP_PINS, |
| 4496 | .v.pins = (const struct alc_pincfg[]) { |
| 4497 | { 0x16, 0x99130111 }, /* CLFE speaker */ |
| 4498 | { 0x1b, 0x99130112 }, /* surround speaker */ |
| 4499 | { } |
| 4500 | }, |
| 4501 | .chained = true, |
| 4502 | .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS, |
| 4503 | }, |
| 4504 | [ALC882_FIXUP_ASPIRE_8930G_VERBS] = { |
| 4505 | /* additional init verbs for Acer Aspire 8930G */ |
| 4506 | .type = ALC_FIXUP_VERBS, |
| 4507 | .v.verbs = (const struct hda_verb[]) { |
| 4508 | /* Enable all DACs */ |
| 4509 | /* DAC DISABLE/MUTE 1? */ |
| 4510 | /* setting bits 1-5 disables DAC nids 0x02-0x06 |
| 4511 | * apparently. Init=0x38 */ |
| 4512 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 }, |
| 4513 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 }, |
| 4514 | /* DAC DISABLE/MUTE 2? */ |
| 4515 | /* some bit here disables the other DACs. |
| 4516 | * Init=0x4900 */ |
| 4517 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 }, |
| 4518 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 }, |
| 4519 | /* DMIC fix |
| 4520 | * This laptop has a stereo digital microphone. |
| 4521 | * The mics are only 1cm apart which makes the stereo |
| 4522 | * useless. However, either the mic or the ALC889 |
| 4523 | * makes the signal become a difference/sum signal |
| 4524 | * instead of standard stereo, which is annoying. |
| 4525 | * So instead we flip this bit which makes the |
| 4526 | * codec replicate the sum signal to both channels, |
| 4527 | * turning it into a normal mono mic. |
| 4528 | */ |
| 4529 | /* DMIC_CONTROL? Init value = 0x0001 */ |
| 4530 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b }, |
| 4531 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 }, |
| 4532 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4533 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, |
| 4534 | { } |
| 4535 | } |
| 4536 | }, |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 4537 | [ALC885_FIXUP_MACPRO_GPIO] = { |
| 4538 | .type = ALC_FIXUP_FUNC, |
| 4539 | .v.func = alc885_fixup_macpro_gpio, |
| 4540 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4541 | }; |
| 4542 | |
| 4543 | static const struct snd_pci_quirk alc882_fixup_tbl[] = { |
Takashi Iwai | 8812c4f | 2011-11-09 17:39:15 +0100 | [diff] [blame] | 4544 | SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD), |
| 4545 | SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD), |
| 4546 | SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD), |
| 4547 | SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD), |
| 4548 | SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD), |
| 4549 | SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD), |
Takashi Iwai | c3e837b | 2011-11-10 16:01:47 +0100 | [diff] [blame] | 4550 | SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G", |
| 4551 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
| 4552 | SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G", |
| 4553 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
| 4554 | SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G", |
| 4555 | ALC882_FIXUP_ACER_ASPIRE_8930G), |
| 4556 | SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G", |
| 4557 | ALC882_FIXUP_ACER_ASPIRE_8930G), |
| 4558 | SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G", |
| 4559 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
| 4560 | SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G", |
| 4561 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
| 4562 | SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G", |
| 4563 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4564 | SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210), |
Takashi Iwai | ac9b1cd | 2011-11-09 17:45:55 +0100 | [diff] [blame] | 4565 | SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736), |
Takashi Iwai | 177943a | 2011-11-09 12:55:18 +0100 | [diff] [blame] | 4566 | SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD), |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4567 | SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V), |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 4568 | SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC), |
Takashi Iwai | 0e7cc2e | 2011-11-09 12:42:48 +0100 | [diff] [blame] | 4569 | SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601), |
Takashi Iwai | ac9b1cd | 2011-11-09 17:45:55 +0100 | [diff] [blame] | 4570 | SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT), |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 4571 | |
| 4572 | /* All Apple entries are in codec SSIDs */ |
| 4573 | SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO), |
| 4574 | SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO), |
| 4575 | SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO), |
| 4576 | SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD), |
| 4577 | SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO), |
| 4578 | |
Takashi Iwai | 7a6069b | 2011-11-09 15:22:01 +0100 | [diff] [blame] | 4579 | SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD), |
Takashi Iwai | eb844d5 | 2011-11-09 18:03:07 +0100 | [diff] [blame] | 4580 | SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3), |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4581 | SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX), |
Takashi Iwai | 7a6069b | 2011-11-09 15:22:01 +0100 | [diff] [blame] | 4582 | SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD), |
| 4583 | SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD), |
Takashi Iwai | ac9b1cd | 2011-11-09 17:45:55 +0100 | [diff] [blame] | 4584 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530), |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 4585 | SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4586 | {} |
| 4587 | }; |
| 4588 | |
| 4589 | /* |
| 4590 | * BIOS auto configuration |
| 4591 | */ |
| 4592 | /* almost identical with ALC880 parser... */ |
| 4593 | static int alc882_parse_auto_config(struct hda_codec *codec) |
| 4594 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4595 | static const hda_nid_t alc882_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4596 | static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 4597 | return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4598 | } |
| 4599 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4600 | /* |
| 4601 | */ |
| 4602 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4603 | #include "alc882_quirks.c" |
| 4604 | #endif |
| 4605 | |
| 4606 | static int patch_alc882(struct hda_codec *codec) |
| 4607 | { |
| 4608 | struct alc_spec *spec; |
| 4609 | int err, board_config; |
| 4610 | |
| 4611 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4612 | if (spec == NULL) |
| 4613 | return -ENOMEM; |
| 4614 | |
| 4615 | codec->spec = spec; |
| 4616 | |
| 4617 | spec->mixer_nid = 0x0b; |
| 4618 | |
| 4619 | switch (codec->vendor_id) { |
| 4620 | case 0x10ec0882: |
| 4621 | case 0x10ec0885: |
| 4622 | break; |
| 4623 | default: |
| 4624 | /* ALC883 and variants */ |
| 4625 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); |
| 4626 | break; |
| 4627 | } |
| 4628 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4629 | err = alc_codec_rename_from_preset(codec); |
| 4630 | if (err < 0) |
| 4631 | goto error; |
| 4632 | |
Takashi Iwai | b253969 | 2011-11-14 17:32:17 +0100 | [diff] [blame] | 4633 | board_config = alc_board_config(codec, ALC882_MODEL_LAST, |
| 4634 | alc882_models, NULL); |
| 4635 | if (board_config < 0) |
| 4636 | board_config = alc_board_codec_sid_config(codec, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4637 | ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl); |
| 4638 | |
| 4639 | if (board_config < 0) { |
| 4640 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 4641 | codec->chip_name); |
| 4642 | board_config = ALC_MODEL_AUTO; |
| 4643 | } |
| 4644 | |
| 4645 | if (board_config == ALC_MODEL_AUTO) { |
| 4646 | alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups); |
| 4647 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 4648 | } |
| 4649 | |
| 4650 | alc_auto_parse_customize_define(codec); |
| 4651 | |
| 4652 | if (board_config == ALC_MODEL_AUTO) { |
| 4653 | /* automatic parse from the BIOS config */ |
| 4654 | err = alc882_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4655 | if (err < 0) |
| 4656 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4657 | } |
| 4658 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4659 | if (board_config != ALC_MODEL_AUTO) |
| 4660 | setup_preset(codec, &alc882_presets[board_config]); |
| 4661 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4662 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4663 | alc_auto_fill_adc_caps(codec); |
| 4664 | alc_rebuild_imux_for_auto_mic(codec); |
| 4665 | alc_remove_invalid_adc_nids(codec); |
| 4666 | } |
| 4667 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4668 | if (!spec->no_analog && !spec->cap_mixer) |
| 4669 | set_capture_mixer(codec); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4670 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4671 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 4672 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4673 | if (err < 0) |
| 4674 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4675 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4676 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4677 | |
| 4678 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4679 | |
| 4680 | spec->vmaster_nid = 0x0c; |
| 4681 | |
| 4682 | codec->patch_ops = alc_patch_ops; |
| 4683 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 4684 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4685 | |
| 4686 | alc_init_jacks(codec); |
| 4687 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4688 | if (!spec->loopback.amplist) |
| 4689 | spec->loopback.amplist = alc882_loopbacks; |
| 4690 | #endif |
| 4691 | |
| 4692 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4693 | |
| 4694 | error: |
| 4695 | alc_free(codec); |
| 4696 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | |
| 4700 | /* |
| 4701 | * ALC262 support |
| 4702 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4703 | static int alc262_parse_auto_config(struct hda_codec *codec) |
| 4704 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4705 | static const hda_nid_t alc262_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4706 | static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 4707 | return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4708 | } |
| 4709 | |
| 4710 | /* |
| 4711 | * Pin config fixes |
| 4712 | */ |
| 4713 | enum { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4714 | ALC262_FIXUP_FSC_H270, |
| 4715 | ALC262_FIXUP_HP_Z200, |
| 4716 | ALC262_FIXUP_TYAN, |
Takashi Iwai | 12837c9 | 2011-11-07 12:45:24 +0100 | [diff] [blame] | 4717 | ALC262_FIXUP_TOSHIBA_RX1, |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 4718 | ALC262_FIXUP_LENOVO_3000, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 4719 | ALC262_FIXUP_BENQ, |
| 4720 | ALC262_FIXUP_BENQ_T31, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4721 | }; |
| 4722 | |
| 4723 | static const struct alc_fixup alc262_fixups[] = { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4724 | [ALC262_FIXUP_FSC_H270] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4725 | .type = ALC_FIXUP_PINS, |
| 4726 | .v.pins = (const struct alc_pincfg[]) { |
| 4727 | { 0x14, 0x99130110 }, /* speaker */ |
| 4728 | { 0x15, 0x0221142f }, /* front HP */ |
| 4729 | { 0x1b, 0x0121141f }, /* rear HP */ |
| 4730 | { } |
| 4731 | } |
| 4732 | }, |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4733 | [ALC262_FIXUP_HP_Z200] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4734 | .type = ALC_FIXUP_PINS, |
| 4735 | .v.pins = (const struct alc_pincfg[]) { |
| 4736 | { 0x16, 0x99130120 }, /* internal speaker */ |
| 4737 | { } |
| 4738 | } |
| 4739 | }, |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4740 | [ALC262_FIXUP_TYAN] = { |
| 4741 | .type = ALC_FIXUP_PINS, |
| 4742 | .v.pins = (const struct alc_pincfg[]) { |
| 4743 | { 0x14, 0x1993e1f0 }, /* int AUX */ |
| 4744 | { } |
| 4745 | } |
| 4746 | }, |
Takashi Iwai | 12837c9 | 2011-11-07 12:45:24 +0100 | [diff] [blame] | 4747 | [ALC262_FIXUP_TOSHIBA_RX1] = { |
| 4748 | .type = ALC_FIXUP_PINS, |
| 4749 | .v.pins = (const struct alc_pincfg[]) { |
| 4750 | { 0x14, 0x90170110 }, /* speaker */ |
| 4751 | { 0x15, 0x0421101f }, /* HP */ |
| 4752 | { 0x1a, 0x40f000f0 }, /* N/A */ |
| 4753 | { 0x1b, 0x40f000f0 }, /* N/A */ |
| 4754 | { 0x1e, 0x40f000f0 }, /* N/A */ |
| 4755 | } |
| 4756 | }, |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 4757 | [ALC262_FIXUP_LENOVO_3000] = { |
| 4758 | .type = ALC_FIXUP_VERBS, |
| 4759 | .v.verbs = (const struct hda_verb[]) { |
| 4760 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 4761 | {} |
| 4762 | }, |
| 4763 | .chained = true, |
| 4764 | .chain_id = ALC262_FIXUP_BENQ, |
| 4765 | }, |
| 4766 | [ALC262_FIXUP_BENQ] = { |
| 4767 | .type = ALC_FIXUP_VERBS, |
| 4768 | .v.verbs = (const struct hda_verb[]) { |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 4769 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4770 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, |
| 4771 | {} |
| 4772 | } |
| 4773 | }, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 4774 | [ALC262_FIXUP_BENQ_T31] = { |
| 4775 | .type = ALC_FIXUP_VERBS, |
| 4776 | .v.verbs = (const struct hda_verb[]) { |
| 4777 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4778 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, |
| 4779 | {} |
| 4780 | } |
| 4781 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4782 | }; |
| 4783 | |
| 4784 | static const struct snd_pci_quirk alc262_fixup_tbl[] = { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4785 | SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200), |
Takashi Iwai | 3dcd3be | 2011-11-07 14:59:40 +0100 | [diff] [blame] | 4786 | SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ), |
| 4787 | SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ), |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4788 | SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN), |
Takashi Iwai | 12837c9 | 2011-11-07 12:45:24 +0100 | [diff] [blame] | 4789 | SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1", |
| 4790 | ALC262_FIXUP_TOSHIBA_RX1), |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4791 | SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270), |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 4792 | SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000), |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 4793 | SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ), |
| 4794 | SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4795 | {} |
| 4796 | }; |
| 4797 | |
| 4798 | |
| 4799 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4800 | #define alc262_loopbacks alc880_loopbacks |
| 4801 | #endif |
| 4802 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4803 | /* |
| 4804 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4805 | static int patch_alc262(struct hda_codec *codec) |
| 4806 | { |
| 4807 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4808 | int err; |
| 4809 | |
| 4810 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4811 | if (spec == NULL) |
| 4812 | return -ENOMEM; |
| 4813 | |
| 4814 | codec->spec = spec; |
| 4815 | |
| 4816 | spec->mixer_nid = 0x0b; |
| 4817 | |
| 4818 | #if 0 |
| 4819 | /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is |
| 4820 | * under-run |
| 4821 | */ |
| 4822 | { |
| 4823 | int tmp; |
| 4824 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 4825 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 4826 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 4827 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80); |
| 4828 | } |
| 4829 | #endif |
| 4830 | alc_auto_parse_customize_define(codec); |
| 4831 | |
| 4832 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); |
| 4833 | |
Takashi Iwai | 42399f7 | 2011-11-07 17:18:44 +0100 | [diff] [blame] | 4834 | alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups); |
| 4835 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4836 | |
Takashi Iwai | 42399f7 | 2011-11-07 17:18:44 +0100 | [diff] [blame] | 4837 | /* automatic parse from the BIOS config */ |
| 4838 | err = alc262_parse_auto_config(codec); |
| 4839 | if (err < 0) |
| 4840 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4841 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4842 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4843 | alc_auto_fill_adc_caps(codec); |
| 4844 | alc_rebuild_imux_for_auto_mic(codec); |
| 4845 | alc_remove_invalid_adc_nids(codec); |
| 4846 | } |
| 4847 | |
| 4848 | if (!spec->no_analog && !spec->cap_mixer) |
| 4849 | set_capture_mixer(codec); |
| 4850 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4851 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 4852 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4853 | if (err < 0) |
| 4854 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4855 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4856 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4857 | |
| 4858 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4859 | |
| 4860 | spec->vmaster_nid = 0x0c; |
| 4861 | |
| 4862 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 42399f7 | 2011-11-07 17:18:44 +0100 | [diff] [blame] | 4863 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4864 | spec->shutup = alc_eapd_shutup; |
| 4865 | |
| 4866 | alc_init_jacks(codec); |
| 4867 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4868 | if (!spec->loopback.amplist) |
| 4869 | spec->loopback.amplist = alc262_loopbacks; |
| 4870 | #endif |
| 4871 | |
| 4872 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4873 | |
| 4874 | error: |
| 4875 | alc_free(codec); |
| 4876 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4877 | } |
| 4878 | |
| 4879 | /* |
| 4880 | * ALC268 |
| 4881 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4882 | /* bind Beep switches of both NID 0x0f and 0x10 */ |
| 4883 | static const struct hda_bind_ctls alc268_bind_beep_sw = { |
| 4884 | .ops = &snd_hda_bind_sw, |
| 4885 | .values = { |
| 4886 | HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT), |
| 4887 | HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT), |
| 4888 | 0 |
| 4889 | }, |
| 4890 | }; |
| 4891 | |
| 4892 | static const struct snd_kcontrol_new alc268_beep_mixer[] = { |
| 4893 | HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT), |
| 4894 | HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw), |
| 4895 | { } |
| 4896 | }; |
| 4897 | |
| 4898 | /* set PCBEEP vol = 0, mute connections */ |
| 4899 | static const struct hda_verb alc268_beep_init_verbs[] = { |
| 4900 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4901 | {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4902 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4903 | { } |
| 4904 | }; |
| 4905 | |
| 4906 | /* |
| 4907 | * BIOS auto configuration |
| 4908 | */ |
| 4909 | static int alc268_parse_auto_config(struct hda_codec *codec) |
| 4910 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4911 | static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4912 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4913 | int err = alc_parse_auto_config(codec, NULL, alc268_ssids); |
| 4914 | if (err > 0) { |
| 4915 | if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { |
| 4916 | add_mixer(spec, alc268_beep_mixer); |
| 4917 | add_verb(spec, alc268_beep_init_verbs); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4918 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4919 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4920 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4921 | } |
| 4922 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4923 | /* |
| 4924 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4925 | static int patch_alc268(struct hda_codec *codec) |
| 4926 | { |
| 4927 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4928 | int i, has_beep, err; |
| 4929 | |
| 4930 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4931 | if (spec == NULL) |
| 4932 | return -ENOMEM; |
| 4933 | |
| 4934 | codec->spec = spec; |
| 4935 | |
| 4936 | /* ALC268 has no aa-loopback mixer */ |
| 4937 | |
Takashi Iwai | 6ebb805 | 2011-08-16 15:15:40 +0200 | [diff] [blame] | 4938 | /* automatic parse from the BIOS config */ |
| 4939 | err = alc268_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4940 | if (err < 0) |
| 4941 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4942 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4943 | has_beep = 0; |
| 4944 | for (i = 0; i < spec->num_mixers; i++) { |
| 4945 | if (spec->mixers[i] == alc268_beep_mixer) { |
| 4946 | has_beep = 1; |
| 4947 | break; |
| 4948 | } |
| 4949 | } |
| 4950 | |
| 4951 | if (has_beep) { |
| 4952 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4953 | if (err < 0) |
| 4954 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4955 | if (!query_amp_caps(codec, 0x1d, HDA_INPUT)) |
| 4956 | /* override the amp caps for beep generator */ |
| 4957 | snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT, |
| 4958 | (0x0c << AC_AMPCAP_OFFSET_SHIFT) | |
| 4959 | (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 4960 | (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 4961 | (0 << AC_AMPCAP_MUTE_SHIFT)); |
| 4962 | } |
| 4963 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4964 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4965 | alc_auto_fill_adc_caps(codec); |
| 4966 | alc_rebuild_imux_for_auto_mic(codec); |
| 4967 | alc_remove_invalid_adc_nids(codec); |
| 4968 | } |
| 4969 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4970 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4971 | set_capture_mixer(codec); |
| 4972 | |
| 4973 | spec->vmaster_nid = 0x02; |
| 4974 | |
| 4975 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 6ebb805 | 2011-08-16 15:15:40 +0200 | [diff] [blame] | 4976 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4977 | spec->shutup = alc_eapd_shutup; |
| 4978 | |
| 4979 | alc_init_jacks(codec); |
| 4980 | |
| 4981 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4982 | |
| 4983 | error: |
| 4984 | alc_free(codec); |
| 4985 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | /* |
| 4989 | * ALC269 |
| 4990 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4991 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4992 | #define alc269_loopbacks alc880_loopbacks |
| 4993 | #endif |
| 4994 | |
| 4995 | static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { |
| 4996 | .substreams = 1, |
| 4997 | .channels_min = 2, |
| 4998 | .channels_max = 8, |
| 4999 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
| 5000 | /* NID is set in alc_build_pcms */ |
| 5001 | .ops = { |
| 5002 | .open = alc_playback_pcm_open, |
| 5003 | .prepare = alc_playback_pcm_prepare, |
| 5004 | .cleanup = alc_playback_pcm_cleanup |
| 5005 | }, |
| 5006 | }; |
| 5007 | |
| 5008 | static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { |
| 5009 | .substreams = 1, |
| 5010 | .channels_min = 2, |
| 5011 | .channels_max = 2, |
| 5012 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
| 5013 | /* NID is set in alc_build_pcms */ |
| 5014 | }; |
| 5015 | |
| 5016 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5017 | static int alc269_mic2_for_mute_led(struct hda_codec *codec) |
| 5018 | { |
| 5019 | switch (codec->subsystem_id) { |
| 5020 | case 0x103c1586: |
| 5021 | return 1; |
| 5022 | } |
| 5023 | return 0; |
| 5024 | } |
| 5025 | |
| 5026 | static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid) |
| 5027 | { |
| 5028 | /* update mute-LED according to the speaker mute state */ |
| 5029 | if (nid == 0x01 || nid == 0x14) { |
| 5030 | int pinval; |
| 5031 | if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) & |
| 5032 | HDA_AMP_MUTE) |
| 5033 | pinval = 0x24; |
| 5034 | else |
| 5035 | pinval = 0x20; |
| 5036 | /* mic2 vref pin is used for mute LED control */ |
| 5037 | snd_hda_codec_update_cache(codec, 0x19, 0, |
| 5038 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 5039 | pinval); |
| 5040 | } |
| 5041 | return alc_check_power_status(codec, nid); |
| 5042 | } |
| 5043 | #endif /* CONFIG_SND_HDA_POWER_SAVE */ |
| 5044 | |
| 5045 | /* different alc269-variants */ |
| 5046 | enum { |
| 5047 | ALC269_TYPE_ALC269VA, |
| 5048 | ALC269_TYPE_ALC269VB, |
| 5049 | ALC269_TYPE_ALC269VC, |
| 5050 | }; |
| 5051 | |
| 5052 | /* |
| 5053 | * BIOS auto configuration |
| 5054 | */ |
| 5055 | static int alc269_parse_auto_config(struct hda_codec *codec) |
| 5056 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5057 | static const hda_nid_t alc269_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5058 | static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 }; |
| 5059 | static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5060 | struct alc_spec *spec = codec->spec; |
| 5061 | const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ? |
| 5062 | alc269va_ssids : alc269_ssids; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5063 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5064 | return alc_parse_auto_config(codec, alc269_ignore, ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5065 | } |
| 5066 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5067 | static void alc269_toggle_power_output(struct hda_codec *codec, int power_up) |
| 5068 | { |
| 5069 | int val = alc_read_coef_idx(codec, 0x04); |
| 5070 | if (power_up) |
| 5071 | val |= 1 << 11; |
| 5072 | else |
| 5073 | val &= ~(1 << 11); |
| 5074 | alc_write_coef_idx(codec, 0x04, val); |
| 5075 | } |
| 5076 | |
| 5077 | static void alc269_shutup(struct hda_codec *codec) |
| 5078 | { |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5079 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5080 | alc269_toggle_power_output(codec, 0); |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5081 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5082 | alc269_toggle_power_output(codec, 0); |
| 5083 | msleep(150); |
| 5084 | } |
| 5085 | } |
| 5086 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 5087 | #ifdef CONFIG_PM |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5088 | static int alc269_resume(struct hda_codec *codec) |
| 5089 | { |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5090 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5091 | alc269_toggle_power_output(codec, 0); |
| 5092 | msleep(150); |
| 5093 | } |
| 5094 | |
| 5095 | codec->patch_ops.init(codec); |
| 5096 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5097 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5098 | alc269_toggle_power_output(codec, 1); |
| 5099 | msleep(200); |
| 5100 | } |
| 5101 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5102 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5103 | alc269_toggle_power_output(codec, 1); |
| 5104 | |
| 5105 | snd_hda_codec_resume_amp(codec); |
| 5106 | snd_hda_codec_resume_cache(codec); |
| 5107 | hda_call_check_power_status(codec, 0x01); |
| 5108 | return 0; |
| 5109 | } |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 5110 | #endif /* CONFIG_PM */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5111 | |
| 5112 | static void alc269_fixup_hweq(struct hda_codec *codec, |
| 5113 | const struct alc_fixup *fix, int action) |
| 5114 | { |
| 5115 | int coef; |
| 5116 | |
| 5117 | if (action != ALC_FIXUP_ACT_INIT) |
| 5118 | return; |
| 5119 | coef = alc_read_coef_idx(codec, 0x1e); |
| 5120 | alc_write_coef_idx(codec, 0x1e, coef | 0x80); |
| 5121 | } |
| 5122 | |
| 5123 | static void alc271_fixup_dmic(struct hda_codec *codec, |
| 5124 | const struct alc_fixup *fix, int action) |
| 5125 | { |
| 5126 | static const struct hda_verb verbs[] = { |
| 5127 | {0x20, AC_VERB_SET_COEF_INDEX, 0x0d}, |
| 5128 | {0x20, AC_VERB_SET_PROC_COEF, 0x4000}, |
| 5129 | {} |
| 5130 | }; |
| 5131 | unsigned int cfg; |
| 5132 | |
| 5133 | if (strcmp(codec->chip_name, "ALC271X")) |
| 5134 | return; |
| 5135 | cfg = snd_hda_codec_get_pincfg(codec, 0x12); |
| 5136 | if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED) |
| 5137 | snd_hda_sequence_write(codec, verbs); |
| 5138 | } |
| 5139 | |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 5140 | static void alc269_fixup_pcm_44k(struct hda_codec *codec, |
| 5141 | const struct alc_fixup *fix, int action) |
| 5142 | { |
| 5143 | struct alc_spec *spec = codec->spec; |
| 5144 | |
| 5145 | if (action != ALC_FIXUP_ACT_PROBE) |
| 5146 | return; |
| 5147 | |
| 5148 | /* Due to a hardware problem on Lenovo Ideadpad, we need to |
| 5149 | * fix the sample rate of analog I/O to 44.1kHz |
| 5150 | */ |
| 5151 | spec->stream_analog_playback = &alc269_44k_pcm_analog_playback; |
| 5152 | spec->stream_analog_capture = &alc269_44k_pcm_analog_capture; |
| 5153 | } |
| 5154 | |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 5155 | static void alc269_fixup_stereo_dmic(struct hda_codec *codec, |
| 5156 | const struct alc_fixup *fix, int action) |
| 5157 | { |
| 5158 | int coef; |
| 5159 | |
| 5160 | if (action != ALC_FIXUP_ACT_INIT) |
| 5161 | return; |
| 5162 | /* The digital-mic unit sends PDM (differential signal) instead of |
| 5163 | * the standard PCM, thus you can't record a valid mono stream as is. |
| 5164 | * Below is a workaround specific to ALC269 to control the dmic |
| 5165 | * signal source as mono. |
| 5166 | */ |
| 5167 | coef = alc_read_coef_idx(codec, 0x07); |
| 5168 | alc_write_coef_idx(codec, 0x07, coef | 0x80); |
| 5169 | } |
| 5170 | |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5171 | static void alc269_quanta_automute(struct hda_codec *codec) |
| 5172 | { |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 5173 | update_outputs(codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5174 | |
| 5175 | snd_hda_codec_write(codec, 0x20, 0, |
| 5176 | AC_VERB_SET_COEF_INDEX, 0x0c); |
| 5177 | snd_hda_codec_write(codec, 0x20, 0, |
| 5178 | AC_VERB_SET_PROC_COEF, 0x680); |
| 5179 | |
| 5180 | snd_hda_codec_write(codec, 0x20, 0, |
| 5181 | AC_VERB_SET_COEF_INDEX, 0x0c); |
| 5182 | snd_hda_codec_write(codec, 0x20, 0, |
| 5183 | AC_VERB_SET_PROC_COEF, 0x480); |
| 5184 | } |
| 5185 | |
| 5186 | static void alc269_fixup_quanta_mute(struct hda_codec *codec, |
| 5187 | const struct alc_fixup *fix, int action) |
| 5188 | { |
| 5189 | struct alc_spec *spec = codec->spec; |
| 5190 | if (action != ALC_FIXUP_ACT_PROBE) |
| 5191 | return; |
| 5192 | spec->automute_hook = alc269_quanta_automute; |
| 5193 | } |
| 5194 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5195 | enum { |
| 5196 | ALC269_FIXUP_SONY_VAIO, |
| 5197 | ALC275_FIXUP_SONY_VAIO_GPIO2, |
| 5198 | ALC269_FIXUP_DELL_M101Z, |
| 5199 | ALC269_FIXUP_SKU_IGNORE, |
| 5200 | ALC269_FIXUP_ASUS_G73JW, |
| 5201 | ALC269_FIXUP_LENOVO_EAPD, |
| 5202 | ALC275_FIXUP_SONY_HWEQ, |
| 5203 | ALC271_FIXUP_DMIC, |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 5204 | ALC269_FIXUP_PCM_44K, |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 5205 | ALC269_FIXUP_STEREO_DMIC, |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5206 | ALC269_FIXUP_QUANTA_MUTE, |
| 5207 | ALC269_FIXUP_LIFEBOOK, |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5208 | ALC269_FIXUP_AMIC, |
| 5209 | ALC269_FIXUP_DMIC, |
| 5210 | ALC269VB_FIXUP_AMIC, |
| 5211 | ALC269VB_FIXUP_DMIC, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5212 | }; |
| 5213 | |
| 5214 | static const struct alc_fixup alc269_fixups[] = { |
| 5215 | [ALC269_FIXUP_SONY_VAIO] = { |
| 5216 | .type = ALC_FIXUP_VERBS, |
| 5217 | .v.verbs = (const struct hda_verb[]) { |
| 5218 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD}, |
| 5219 | {} |
| 5220 | } |
| 5221 | }, |
| 5222 | [ALC275_FIXUP_SONY_VAIO_GPIO2] = { |
| 5223 | .type = ALC_FIXUP_VERBS, |
| 5224 | .v.verbs = (const struct hda_verb[]) { |
| 5225 | {0x01, AC_VERB_SET_GPIO_MASK, 0x04}, |
| 5226 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04}, |
| 5227 | {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, |
| 5228 | { } |
| 5229 | }, |
| 5230 | .chained = true, |
| 5231 | .chain_id = ALC269_FIXUP_SONY_VAIO |
| 5232 | }, |
| 5233 | [ALC269_FIXUP_DELL_M101Z] = { |
| 5234 | .type = ALC_FIXUP_VERBS, |
| 5235 | .v.verbs = (const struct hda_verb[]) { |
| 5236 | /* Enables internal speaker */ |
| 5237 | {0x20, AC_VERB_SET_COEF_INDEX, 13}, |
| 5238 | {0x20, AC_VERB_SET_PROC_COEF, 0x4040}, |
| 5239 | {} |
| 5240 | } |
| 5241 | }, |
| 5242 | [ALC269_FIXUP_SKU_IGNORE] = { |
| 5243 | .type = ALC_FIXUP_SKU, |
| 5244 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
| 5245 | }, |
| 5246 | [ALC269_FIXUP_ASUS_G73JW] = { |
| 5247 | .type = ALC_FIXUP_PINS, |
| 5248 | .v.pins = (const struct alc_pincfg[]) { |
| 5249 | { 0x17, 0x99130111 }, /* subwoofer */ |
| 5250 | { } |
| 5251 | } |
| 5252 | }, |
| 5253 | [ALC269_FIXUP_LENOVO_EAPD] = { |
| 5254 | .type = ALC_FIXUP_VERBS, |
| 5255 | .v.verbs = (const struct hda_verb[]) { |
| 5256 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, |
| 5257 | {} |
| 5258 | } |
| 5259 | }, |
| 5260 | [ALC275_FIXUP_SONY_HWEQ] = { |
| 5261 | .type = ALC_FIXUP_FUNC, |
| 5262 | .v.func = alc269_fixup_hweq, |
| 5263 | .chained = true, |
| 5264 | .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2 |
| 5265 | }, |
| 5266 | [ALC271_FIXUP_DMIC] = { |
| 5267 | .type = ALC_FIXUP_FUNC, |
| 5268 | .v.func = alc271_fixup_dmic, |
| 5269 | }, |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 5270 | [ALC269_FIXUP_PCM_44K] = { |
| 5271 | .type = ALC_FIXUP_FUNC, |
| 5272 | .v.func = alc269_fixup_pcm_44k, |
| 5273 | }, |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 5274 | [ALC269_FIXUP_STEREO_DMIC] = { |
| 5275 | .type = ALC_FIXUP_FUNC, |
| 5276 | .v.func = alc269_fixup_stereo_dmic, |
| 5277 | }, |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5278 | [ALC269_FIXUP_QUANTA_MUTE] = { |
| 5279 | .type = ALC_FIXUP_FUNC, |
| 5280 | .v.func = alc269_fixup_quanta_mute, |
| 5281 | }, |
| 5282 | [ALC269_FIXUP_LIFEBOOK] = { |
| 5283 | .type = ALC_FIXUP_PINS, |
| 5284 | .v.pins = (const struct alc_pincfg[]) { |
| 5285 | { 0x1a, 0x2101103f }, /* dock line-out */ |
| 5286 | { 0x1b, 0x23a11040 }, /* dock mic-in */ |
| 5287 | { } |
| 5288 | }, |
| 5289 | .chained = true, |
| 5290 | .chain_id = ALC269_FIXUP_QUANTA_MUTE |
| 5291 | }, |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5292 | [ALC269_FIXUP_AMIC] = { |
| 5293 | .type = ALC_FIXUP_PINS, |
| 5294 | .v.pins = (const struct alc_pincfg[]) { |
| 5295 | { 0x14, 0x99130110 }, /* speaker */ |
| 5296 | { 0x15, 0x0121401f }, /* HP out */ |
| 5297 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5298 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 5299 | { } |
| 5300 | }, |
| 5301 | }, |
| 5302 | [ALC269_FIXUP_DMIC] = { |
| 5303 | .type = ALC_FIXUP_PINS, |
| 5304 | .v.pins = (const struct alc_pincfg[]) { |
| 5305 | { 0x12, 0x99a3092f }, /* int-mic */ |
| 5306 | { 0x14, 0x99130110 }, /* speaker */ |
| 5307 | { 0x15, 0x0121401f }, /* HP out */ |
| 5308 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5309 | { } |
| 5310 | }, |
| 5311 | }, |
| 5312 | [ALC269VB_FIXUP_AMIC] = { |
| 5313 | .type = ALC_FIXUP_PINS, |
| 5314 | .v.pins = (const struct alc_pincfg[]) { |
| 5315 | { 0x14, 0x99130110 }, /* speaker */ |
| 5316 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5317 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 5318 | { 0x21, 0x0121401f }, /* HP out */ |
| 5319 | { } |
| 5320 | }, |
| 5321 | }, |
| 5322 | [ALC269_FIXUP_DMIC] = { |
| 5323 | .type = ALC_FIXUP_PINS, |
| 5324 | .v.pins = (const struct alc_pincfg[]) { |
| 5325 | { 0x12, 0x99a3092f }, /* int-mic */ |
| 5326 | { 0x14, 0x99130110 }, /* speaker */ |
| 5327 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5328 | { 0x21, 0x0121401f }, /* HP out */ |
| 5329 | { } |
| 5330 | }, |
| 5331 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5332 | }; |
| 5333 | |
| 5334 | static const struct snd_pci_quirk alc269_fixup_tbl[] = { |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 5335 | SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW), |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 5336 | SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC), |
| 5337 | SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC), |
| 5338 | SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC), |
| 5339 | SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), |
| 5340 | SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5341 | SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2), |
| 5342 | SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), |
| 5343 | SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), |
| 5344 | SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO), |
| 5345 | SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z), |
| 5346 | SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC), |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5347 | SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5348 | SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE), |
| 5349 | SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE), |
| 5350 | SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE), |
| 5351 | SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE), |
| 5352 | SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE), |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5353 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE), |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 5354 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5355 | SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD), |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5356 | |
| 5357 | #if 1 |
| 5358 | /* Below is a quirk table taken from the old code. |
| 5359 | * Basically the device should work as is without the fixup table. |
| 5360 | * If BIOS doesn't give a proper info, enable the corresponding |
| 5361 | * fixup entry. |
| 5362 | */ |
| 5363 | SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A", |
| 5364 | ALC269_FIXUP_AMIC), |
| 5365 | SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC), |
| 5366 | SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC), |
| 5367 | SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC), |
| 5368 | SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC), |
| 5369 | SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC), |
| 5370 | SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC), |
| 5371 | SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC), |
| 5372 | SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC), |
| 5373 | SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC), |
| 5374 | SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC), |
| 5375 | SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC), |
| 5376 | SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC), |
| 5377 | SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC), |
| 5378 | SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC), |
| 5379 | SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC), |
| 5380 | SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC), |
| 5381 | SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC), |
| 5382 | SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC), |
| 5383 | SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC), |
| 5384 | SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC), |
| 5385 | SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC), |
| 5386 | SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC), |
| 5387 | SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC), |
| 5388 | SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC), |
| 5389 | SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC), |
| 5390 | SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC), |
| 5391 | SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC), |
| 5392 | SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC), |
| 5393 | SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC), |
| 5394 | SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC), |
| 5395 | SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC), |
| 5396 | SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC), |
| 5397 | SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC), |
| 5398 | SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC), |
| 5399 | SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC), |
| 5400 | SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC), |
| 5401 | SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC), |
| 5402 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC), |
| 5403 | SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC), |
| 5404 | SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC), |
| 5405 | #endif |
| 5406 | {} |
| 5407 | }; |
| 5408 | |
| 5409 | static const struct alc_model_fixup alc269_fixup_models[] = { |
| 5410 | {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"}, |
| 5411 | {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"}, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5412 | {} |
| 5413 | }; |
| 5414 | |
| 5415 | |
| 5416 | static int alc269_fill_coef(struct hda_codec *codec) |
| 5417 | { |
| 5418 | int val; |
| 5419 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5420 | if ((alc_get_coef0(codec) & 0x00ff) < 0x015) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5421 | alc_write_coef_idx(codec, 0xf, 0x960b); |
| 5422 | alc_write_coef_idx(codec, 0xe, 0x8817); |
| 5423 | } |
| 5424 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5425 | if ((alc_get_coef0(codec) & 0x00ff) == 0x016) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5426 | alc_write_coef_idx(codec, 0xf, 0x960b); |
| 5427 | alc_write_coef_idx(codec, 0xe, 0x8814); |
| 5428 | } |
| 5429 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5430 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5431 | val = alc_read_coef_idx(codec, 0x04); |
| 5432 | /* Power up output pin */ |
| 5433 | alc_write_coef_idx(codec, 0x04, val | (1<<11)); |
| 5434 | } |
| 5435 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5436 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5437 | val = alc_read_coef_idx(codec, 0xd); |
| 5438 | if ((val & 0x0c00) >> 10 != 0x1) { |
| 5439 | /* Capless ramp up clock control */ |
| 5440 | alc_write_coef_idx(codec, 0xd, val | (1<<10)); |
| 5441 | } |
| 5442 | val = alc_read_coef_idx(codec, 0x17); |
| 5443 | if ((val & 0x01c0) >> 6 != 0x4) { |
| 5444 | /* Class D power on reset */ |
| 5445 | alc_write_coef_idx(codec, 0x17, val | (1<<7)); |
| 5446 | } |
| 5447 | } |
| 5448 | |
| 5449 | val = alc_read_coef_idx(codec, 0xd); /* Class D */ |
| 5450 | alc_write_coef_idx(codec, 0xd, val | (1<<14)); |
| 5451 | |
| 5452 | val = alc_read_coef_idx(codec, 0x4); /* HP */ |
| 5453 | alc_write_coef_idx(codec, 0x4, val | (1<<11)); |
| 5454 | |
| 5455 | return 0; |
| 5456 | } |
| 5457 | |
| 5458 | /* |
| 5459 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5460 | static int patch_alc269(struct hda_codec *codec) |
| 5461 | { |
| 5462 | struct alc_spec *spec; |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5463 | int err = 0; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5464 | |
| 5465 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5466 | if (spec == NULL) |
| 5467 | return -ENOMEM; |
| 5468 | |
| 5469 | codec->spec = spec; |
| 5470 | |
| 5471 | spec->mixer_nid = 0x0b; |
| 5472 | |
| 5473 | alc_auto_parse_customize_define(codec); |
| 5474 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5475 | err = alc_codec_rename_from_preset(codec); |
| 5476 | if (err < 0) |
| 5477 | goto error; |
| 5478 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5479 | if (codec->vendor_id == 0x10ec0269) { |
| 5480 | spec->codec_variant = ALC269_TYPE_ALC269VA; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5481 | switch (alc_get_coef0(codec) & 0x00f0) { |
| 5482 | case 0x0010: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5483 | if (codec->bus->pci->subsystem_vendor == 0x1025 && |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5484 | spec->cdefine.platform_type == 1) |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5485 | err = alc_codec_rename(codec, "ALC271X"); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5486 | spec->codec_variant = ALC269_TYPE_ALC269VB; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5487 | break; |
| 5488 | case 0x0020: |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5489 | if (codec->bus->pci->subsystem_vendor == 0x17aa && |
| 5490 | codec->bus->pci->subsystem_device == 0x21f3) |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5491 | err = alc_codec_rename(codec, "ALC3202"); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5492 | spec->codec_variant = ALC269_TYPE_ALC269VC; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5493 | break; |
| 5494 | default: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5495 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5496 | } |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5497 | if (err < 0) |
| 5498 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5499 | alc269_fill_coef(codec); |
| 5500 | } |
| 5501 | |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5502 | alc_pick_fixup(codec, alc269_fixup_models, |
| 5503 | alc269_fixup_tbl, alc269_fixups); |
| 5504 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5505 | |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5506 | /* automatic parse from the BIOS config */ |
| 5507 | err = alc269_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5508 | if (err < 0) |
| 5509 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5510 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5511 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5512 | alc_auto_fill_adc_caps(codec); |
| 5513 | alc_rebuild_imux_for_auto_mic(codec); |
| 5514 | alc_remove_invalid_adc_nids(codec); |
| 5515 | } |
| 5516 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5517 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5518 | set_capture_mixer(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5519 | |
| 5520 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 5521 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5522 | if (err < 0) |
| 5523 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5524 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5525 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5526 | |
| 5527 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5528 | |
| 5529 | spec->vmaster_nid = 0x02; |
| 5530 | |
| 5531 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 5532 | #ifdef CONFIG_PM |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5533 | codec->patch_ops.resume = alc269_resume; |
| 5534 | #endif |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5535 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5536 | spec->shutup = alc269_shutup; |
| 5537 | |
| 5538 | alc_init_jacks(codec); |
| 5539 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5540 | if (!spec->loopback.amplist) |
| 5541 | spec->loopback.amplist = alc269_loopbacks; |
| 5542 | if (alc269_mic2_for_mute_led(codec)) |
| 5543 | codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps; |
| 5544 | #endif |
| 5545 | |
| 5546 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5547 | |
| 5548 | error: |
| 5549 | alc_free(codec); |
| 5550 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5551 | } |
| 5552 | |
| 5553 | /* |
| 5554 | * ALC861 |
| 5555 | */ |
| 5556 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5557 | static int alc861_parse_auto_config(struct hda_codec *codec) |
| 5558 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5559 | static const hda_nid_t alc861_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5560 | static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 }; |
| 5561 | return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5562 | } |
| 5563 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5564 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5565 | static const struct hda_amp_list alc861_loopbacks[] = { |
| 5566 | { 0x15, HDA_INPUT, 0 }, |
| 5567 | { 0x15, HDA_INPUT, 1 }, |
| 5568 | { 0x15, HDA_INPUT, 2 }, |
| 5569 | { 0x15, HDA_INPUT, 3 }, |
| 5570 | { } /* end */ |
| 5571 | }; |
| 5572 | #endif |
| 5573 | |
| 5574 | |
| 5575 | /* Pin config fixes */ |
| 5576 | enum { |
| 5577 | PINFIX_FSC_AMILO_PI1505, |
| 5578 | }; |
| 5579 | |
| 5580 | static const struct alc_fixup alc861_fixups[] = { |
| 5581 | [PINFIX_FSC_AMILO_PI1505] = { |
| 5582 | .type = ALC_FIXUP_PINS, |
| 5583 | .v.pins = (const struct alc_pincfg[]) { |
| 5584 | { 0x0b, 0x0221101f }, /* HP */ |
| 5585 | { 0x0f, 0x90170310 }, /* speaker */ |
| 5586 | { } |
| 5587 | } |
| 5588 | }, |
| 5589 | }; |
| 5590 | |
| 5591 | static const struct snd_pci_quirk alc861_fixup_tbl[] = { |
| 5592 | SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505), |
| 5593 | {} |
| 5594 | }; |
| 5595 | |
| 5596 | /* |
| 5597 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5598 | static int patch_alc861(struct hda_codec *codec) |
| 5599 | { |
| 5600 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5601 | int err; |
| 5602 | |
| 5603 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5604 | if (spec == NULL) |
| 5605 | return -ENOMEM; |
| 5606 | |
| 5607 | codec->spec = spec; |
| 5608 | |
| 5609 | spec->mixer_nid = 0x15; |
| 5610 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5611 | alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); |
| 5612 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5613 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5614 | /* automatic parse from the BIOS config */ |
| 5615 | err = alc861_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5616 | if (err < 0) |
| 5617 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5618 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5619 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5620 | alc_auto_fill_adc_caps(codec); |
| 5621 | alc_rebuild_imux_for_auto_mic(codec); |
| 5622 | alc_remove_invalid_adc_nids(codec); |
| 5623 | } |
| 5624 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5625 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5626 | set_capture_mixer(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5627 | |
| 5628 | if (!spec->no_analog) { |
| 5629 | err = snd_hda_attach_beep_device(codec, 0x23); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5630 | if (err < 0) |
| 5631 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5632 | set_beep_amp(spec, 0x23, 0, HDA_OUTPUT); |
| 5633 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5634 | |
| 5635 | spec->vmaster_nid = 0x03; |
| 5636 | |
| 5637 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5638 | |
| 5639 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5640 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5641 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5642 | spec->power_hook = alc_power_eapd; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5643 | if (!spec->loopback.amplist) |
| 5644 | spec->loopback.amplist = alc861_loopbacks; |
| 5645 | #endif |
| 5646 | |
| 5647 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5648 | |
| 5649 | error: |
| 5650 | alc_free(codec); |
| 5651 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5652 | } |
| 5653 | |
| 5654 | /* |
| 5655 | * ALC861-VD support |
| 5656 | * |
| 5657 | * Based on ALC882 |
| 5658 | * |
| 5659 | * In addition, an independent DAC |
| 5660 | */ |
| 5661 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5662 | #define alc861vd_loopbacks alc880_loopbacks |
| 5663 | #endif |
| 5664 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5665 | static int alc861vd_parse_auto_config(struct hda_codec *codec) |
| 5666 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5667 | static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5668 | static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5669 | return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5670 | } |
| 5671 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5672 | enum { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5673 | ALC660VD_FIX_ASUS_GPIO1, |
| 5674 | ALC861VD_FIX_DALLAS, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5675 | }; |
| 5676 | |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5677 | /* exclude VREF80 */ |
| 5678 | static void alc861vd_fixup_dallas(struct hda_codec *codec, |
| 5679 | const struct alc_fixup *fix, int action) |
| 5680 | { |
| 5681 | if (action == ALC_FIXUP_ACT_PRE_PROBE) { |
| 5682 | snd_hda_override_pin_caps(codec, 0x18, 0x00001714); |
| 5683 | snd_hda_override_pin_caps(codec, 0x19, 0x0000171c); |
| 5684 | } |
| 5685 | } |
| 5686 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5687 | static const struct alc_fixup alc861vd_fixups[] = { |
| 5688 | [ALC660VD_FIX_ASUS_GPIO1] = { |
| 5689 | .type = ALC_FIXUP_VERBS, |
| 5690 | .v.verbs = (const struct hda_verb[]) { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5691 | /* reset GPIO1 */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5692 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, |
| 5693 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, |
| 5694 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, |
| 5695 | { } |
| 5696 | } |
| 5697 | }, |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5698 | [ALC861VD_FIX_DALLAS] = { |
| 5699 | .type = ALC_FIXUP_FUNC, |
| 5700 | .v.func = alc861vd_fixup_dallas, |
| 5701 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5702 | }; |
| 5703 | |
| 5704 | static const struct snd_pci_quirk alc861vd_fixup_tbl[] = { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5705 | SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5706 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1), |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5707 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5708 | {} |
| 5709 | }; |
| 5710 | |
| 5711 | static const struct hda_verb alc660vd_eapd_verbs[] = { |
| 5712 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2}, |
| 5713 | {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2}, |
| 5714 | { } |
| 5715 | }; |
| 5716 | |
| 5717 | /* |
| 5718 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5719 | static int patch_alc861vd(struct hda_codec *codec) |
| 5720 | { |
| 5721 | struct alc_spec *spec; |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5722 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5723 | |
| 5724 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5725 | if (spec == NULL) |
| 5726 | return -ENOMEM; |
| 5727 | |
| 5728 | codec->spec = spec; |
| 5729 | |
| 5730 | spec->mixer_nid = 0x0b; |
| 5731 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5732 | alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); |
| 5733 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5734 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5735 | /* automatic parse from the BIOS config */ |
| 5736 | err = alc861vd_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5737 | if (err < 0) |
| 5738 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5739 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5740 | if (codec->vendor_id == 0x10ec0660) { |
| 5741 | /* always turn on EAPD */ |
| 5742 | add_verb(spec, alc660vd_eapd_verbs); |
| 5743 | } |
| 5744 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5745 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5746 | alc_auto_fill_adc_caps(codec); |
| 5747 | alc_rebuild_imux_for_auto_mic(codec); |
| 5748 | alc_remove_invalid_adc_nids(codec); |
| 5749 | } |
| 5750 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5751 | if (!spec->no_analog && !spec->cap_mixer) |
| 5752 | set_capture_mixer(codec); |
| 5753 | |
| 5754 | if (!spec->no_analog) { |
| 5755 | err = snd_hda_attach_beep_device(codec, 0x23); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5756 | if (err < 0) |
| 5757 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5758 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 5759 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5760 | |
| 5761 | spec->vmaster_nid = 0x02; |
| 5762 | |
| 5763 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5764 | |
| 5765 | codec->patch_ops = alc_patch_ops; |
| 5766 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5767 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5768 | spec->shutup = alc_eapd_shutup; |
| 5769 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5770 | if (!spec->loopback.amplist) |
| 5771 | spec->loopback.amplist = alc861vd_loopbacks; |
| 5772 | #endif |
| 5773 | |
| 5774 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5775 | |
| 5776 | error: |
| 5777 | alc_free(codec); |
| 5778 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5779 | } |
| 5780 | |
| 5781 | /* |
| 5782 | * ALC662 support |
| 5783 | * |
| 5784 | * ALC662 is almost identical with ALC880 but has cleaner and more flexible |
| 5785 | * configuration. Each pin widget can choose any input DACs and a mixer. |
| 5786 | * Each ADC is connected from a mixer of all inputs. This makes possible |
| 5787 | * 6-channel independent captures. |
| 5788 | * |
| 5789 | * In addition, an independent DAC for the multi-playback (not used in this |
| 5790 | * driver yet). |
| 5791 | */ |
| 5792 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5793 | #define alc662_loopbacks alc880_loopbacks |
| 5794 | #endif |
| 5795 | |
| 5796 | /* |
| 5797 | * BIOS auto configuration |
| 5798 | */ |
| 5799 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5800 | static int alc662_parse_auto_config(struct hda_codec *codec) |
| 5801 | { |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 5802 | static const hda_nid_t alc662_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5803 | static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 }; |
| 5804 | static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5805 | const hda_nid_t *ssids; |
Takashi Iwai | ee979a14 | 2008-09-02 15:42:20 +0200 | [diff] [blame] | 5806 | |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 5807 | if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 || |
| 5808 | codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670) |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5809 | ssids = alc663_ssids; |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 5810 | else |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5811 | ssids = alc662_ssids; |
| 5812 | return alc_parse_auto_config(codec, alc662_ignore, ssids); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5813 | } |
| 5814 | |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5815 | static void alc272_fixup_mario(struct hda_codec *codec, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5816 | const struct alc_fixup *fix, int action) |
Takashi Iwai | 6fc398c | 2011-01-13 14:36:37 +0100 | [diff] [blame] | 5817 | { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5818 | if (action != ALC_FIXUP_ACT_PROBE) |
Takashi Iwai | 6fc398c | 2011-01-13 14:36:37 +0100 | [diff] [blame] | 5819 | return; |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5820 | if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT, |
| 5821 | (0x3b << AC_AMPCAP_OFFSET_SHIFT) | |
| 5822 | (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 5823 | (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 5824 | (0 << AC_AMPCAP_MUTE_SHIFT))) |
| 5825 | printk(KERN_WARNING |
| 5826 | "hda_codec: failed to override amp caps for NID 0x2\n"); |
| 5827 | } |
| 5828 | |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5829 | enum { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5830 | ALC662_FIXUP_ASPIRE, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5831 | ALC662_FIXUP_IDEAPAD, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5832 | ALC272_FIXUP_MARIO, |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 5833 | ALC662_FIXUP_CZC_P10T, |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 5834 | ALC662_FIXUP_SKU_IGNORE, |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 5835 | ALC662_FIXUP_HP_RP5800, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5836 | ALC662_FIXUP_ASUS_MODE1, |
| 5837 | ALC662_FIXUP_ASUS_MODE2, |
| 5838 | ALC662_FIXUP_ASUS_MODE3, |
| 5839 | ALC662_FIXUP_ASUS_MODE4, |
| 5840 | ALC662_FIXUP_ASUS_MODE5, |
| 5841 | ALC662_FIXUP_ASUS_MODE6, |
| 5842 | ALC662_FIXUP_ASUS_MODE7, |
| 5843 | ALC662_FIXUP_ASUS_MODE8, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5844 | }; |
| 5845 | |
| 5846 | static const struct alc_fixup alc662_fixups[] = { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5847 | [ALC662_FIXUP_ASPIRE] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5848 | .type = ALC_FIXUP_PINS, |
| 5849 | .v.pins = (const struct alc_pincfg[]) { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5850 | { 0x15, 0x99130112 }, /* subwoofer */ |
| 5851 | { } |
| 5852 | } |
| 5853 | }, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5854 | [ALC662_FIXUP_IDEAPAD] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5855 | .type = ALC_FIXUP_PINS, |
| 5856 | .v.pins = (const struct alc_pincfg[]) { |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5857 | { 0x17, 0x99130112 }, /* subwoofer */ |
| 5858 | { } |
| 5859 | } |
| 5860 | }, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5861 | [ALC272_FIXUP_MARIO] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5862 | .type = ALC_FIXUP_FUNC, |
| 5863 | .v.func = alc272_fixup_mario, |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 5864 | }, |
| 5865 | [ALC662_FIXUP_CZC_P10T] = { |
| 5866 | .type = ALC_FIXUP_VERBS, |
| 5867 | .v.verbs = (const struct hda_verb[]) { |
| 5868 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, |
| 5869 | {} |
| 5870 | } |
| 5871 | }, |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 5872 | [ALC662_FIXUP_SKU_IGNORE] = { |
| 5873 | .type = ALC_FIXUP_SKU, |
| 5874 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
Takashi Iwai | c6b3587 | 2011-03-28 12:05:31 +0200 | [diff] [blame] | 5875 | }, |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 5876 | [ALC662_FIXUP_HP_RP5800] = { |
| 5877 | .type = ALC_FIXUP_PINS, |
| 5878 | .v.pins = (const struct alc_pincfg[]) { |
| 5879 | { 0x14, 0x0221201f }, /* HP out */ |
| 5880 | { } |
| 5881 | }, |
| 5882 | .chained = true, |
| 5883 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5884 | }, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5885 | [ALC662_FIXUP_ASUS_MODE1] = { |
| 5886 | .type = ALC_FIXUP_PINS, |
| 5887 | .v.pins = (const struct alc_pincfg[]) { |
| 5888 | { 0x14, 0x99130110 }, /* speaker */ |
| 5889 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5890 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 5891 | { 0x21, 0x0121401f }, /* HP out */ |
| 5892 | { } |
| 5893 | }, |
| 5894 | .chained = true, |
| 5895 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5896 | }, |
| 5897 | [ALC662_FIXUP_ASUS_MODE2] = { |
Takashi Iwai | 2996bdb | 2011-08-18 16:02:24 +0200 | [diff] [blame] | 5898 | .type = ALC_FIXUP_PINS, |
| 5899 | .v.pins = (const struct alc_pincfg[]) { |
| 5900 | { 0x14, 0x99130110 }, /* speaker */ |
| 5901 | { 0x18, 0x01a19820 }, /* mic */ |
| 5902 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 5903 | { 0x1b, 0x0121401f }, /* HP out */ |
| 5904 | { } |
| 5905 | }, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5906 | .chained = true, |
| 5907 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5908 | }, |
| 5909 | [ALC662_FIXUP_ASUS_MODE3] = { |
| 5910 | .type = ALC_FIXUP_PINS, |
| 5911 | .v.pins = (const struct alc_pincfg[]) { |
| 5912 | { 0x14, 0x99130110 }, /* speaker */ |
| 5913 | { 0x15, 0x0121441f }, /* HP */ |
| 5914 | { 0x18, 0x01a19840 }, /* mic */ |
| 5915 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5916 | { 0x21, 0x01211420 }, /* HP2 */ |
| 5917 | { } |
| 5918 | }, |
| 5919 | .chained = true, |
| 5920 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5921 | }, |
| 5922 | [ALC662_FIXUP_ASUS_MODE4] = { |
| 5923 | .type = ALC_FIXUP_PINS, |
| 5924 | .v.pins = (const struct alc_pincfg[]) { |
| 5925 | { 0x14, 0x99130110 }, /* speaker */ |
| 5926 | { 0x16, 0x99130111 }, /* speaker */ |
| 5927 | { 0x18, 0x01a19840 }, /* mic */ |
| 5928 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5929 | { 0x21, 0x0121441f }, /* HP */ |
| 5930 | { } |
| 5931 | }, |
| 5932 | .chained = true, |
| 5933 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5934 | }, |
| 5935 | [ALC662_FIXUP_ASUS_MODE5] = { |
| 5936 | .type = ALC_FIXUP_PINS, |
| 5937 | .v.pins = (const struct alc_pincfg[]) { |
| 5938 | { 0x14, 0x99130110 }, /* speaker */ |
| 5939 | { 0x15, 0x0121441f }, /* HP */ |
| 5940 | { 0x16, 0x99130111 }, /* speaker */ |
| 5941 | { 0x18, 0x01a19840 }, /* mic */ |
| 5942 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5943 | { } |
| 5944 | }, |
| 5945 | .chained = true, |
| 5946 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5947 | }, |
| 5948 | [ALC662_FIXUP_ASUS_MODE6] = { |
| 5949 | .type = ALC_FIXUP_PINS, |
| 5950 | .v.pins = (const struct alc_pincfg[]) { |
| 5951 | { 0x14, 0x99130110 }, /* speaker */ |
| 5952 | { 0x15, 0x01211420 }, /* HP2 */ |
| 5953 | { 0x18, 0x01a19840 }, /* mic */ |
| 5954 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5955 | { 0x1b, 0x0121441f }, /* HP */ |
| 5956 | { } |
| 5957 | }, |
| 5958 | .chained = true, |
| 5959 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5960 | }, |
| 5961 | [ALC662_FIXUP_ASUS_MODE7] = { |
| 5962 | .type = ALC_FIXUP_PINS, |
| 5963 | .v.pins = (const struct alc_pincfg[]) { |
| 5964 | { 0x14, 0x99130110 }, /* speaker */ |
| 5965 | { 0x17, 0x99130111 }, /* speaker */ |
| 5966 | { 0x18, 0x01a19840 }, /* mic */ |
| 5967 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5968 | { 0x1b, 0x01214020 }, /* HP */ |
| 5969 | { 0x21, 0x0121401f }, /* HP */ |
| 5970 | { } |
| 5971 | }, |
| 5972 | .chained = true, |
| 5973 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5974 | }, |
| 5975 | [ALC662_FIXUP_ASUS_MODE8] = { |
| 5976 | .type = ALC_FIXUP_PINS, |
| 5977 | .v.pins = (const struct alc_pincfg[]) { |
| 5978 | { 0x14, 0x99130110 }, /* speaker */ |
| 5979 | { 0x12, 0x99a30970 }, /* int-mic */ |
| 5980 | { 0x15, 0x01214020 }, /* HP */ |
| 5981 | { 0x17, 0x99130111 }, /* speaker */ |
| 5982 | { 0x18, 0x01a19840 }, /* mic */ |
| 5983 | { 0x21, 0x0121401f }, /* HP */ |
| 5984 | { } |
| 5985 | }, |
| 5986 | .chained = true, |
| 5987 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
Takashi Iwai | 2996bdb | 2011-08-18 16:02:24 +0200 | [diff] [blame] | 5988 | }, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5989 | }; |
| 5990 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 5991 | static const struct snd_pci_quirk alc662_fixup_tbl[] = { |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5992 | SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2), |
David Henningsson | a6c47a8 | 2011-02-10 15:39:19 +0100 | [diff] [blame] | 5993 | SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE), |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 5994 | SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE), |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5995 | SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE), |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 5996 | SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5997 | SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2), |
Daniel T Chen | a0e90ac | 2010-11-20 10:20:35 -0500 | [diff] [blame] | 5998 | SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD), |
Valentine Sinitsyn | d411858 | 2010-10-01 22:24:08 +0600 | [diff] [blame] | 5999 | SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD), |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6000 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD), |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 6001 | SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T), |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6002 | |
| 6003 | #if 0 |
| 6004 | /* Below is a quirk table taken from the old code. |
| 6005 | * Basically the device should work as is without the fixup table. |
| 6006 | * If BIOS doesn't give a proper info, enable the corresponding |
| 6007 | * fixup entry. |
| 6008 | */ |
| 6009 | SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1), |
| 6010 | SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3), |
| 6011 | SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1), |
| 6012 | SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3), |
| 6013 | SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 6014 | SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6015 | SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 6016 | SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1), |
| 6017 | SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1), |
| 6018 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6019 | SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7), |
| 6020 | SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7), |
| 6021 | SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8), |
| 6022 | SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3), |
| 6023 | SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1), |
| 6024 | SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6025 | SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2), |
| 6026 | SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1), |
| 6027 | SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6028 | SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 6029 | SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 6030 | SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6031 | SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1), |
| 6032 | SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3), |
| 6033 | SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2), |
| 6034 | SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6035 | SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5), |
| 6036 | SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 6037 | SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6038 | SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1), |
| 6039 | SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6040 | SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6041 | SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3), |
| 6042 | SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3), |
| 6043 | SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1), |
| 6044 | SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1), |
| 6045 | SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1), |
| 6046 | SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1), |
| 6047 | SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1), |
| 6048 | SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6049 | SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2), |
| 6050 | SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1), |
| 6051 | SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 6052 | SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3), |
| 6053 | SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1), |
| 6054 | SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1), |
| 6055 | SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1), |
| 6056 | SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2), |
| 6057 | SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 6058 | SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4), |
| 6059 | #endif |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6060 | {} |
| 6061 | }; |
| 6062 | |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 6063 | static const struct alc_model_fixup alc662_fixup_models[] = { |
| 6064 | {.id = ALC272_FIXUP_MARIO, .name = "mario"}, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6065 | {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"}, |
| 6066 | {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"}, |
| 6067 | {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"}, |
| 6068 | {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"}, |
| 6069 | {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"}, |
| 6070 | {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"}, |
| 6071 | {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"}, |
| 6072 | {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"}, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 6073 | {} |
| 6074 | }; |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6075 | |
| 6076 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6077 | /* |
| 6078 | */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6079 | static int patch_alc662(struct hda_codec *codec) |
| 6080 | { |
| 6081 | struct alc_spec *spec; |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 6082 | int err = 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6083 | |
| 6084 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 6085 | if (!spec) |
| 6086 | return -ENOMEM; |
| 6087 | |
| 6088 | codec->spec = spec; |
| 6089 | |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 6090 | spec->mixer_nid = 0x0b; |
| 6091 | |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6092 | /* handle multiple HPs as is */ |
| 6093 | spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; |
| 6094 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 6095 | alc_auto_parse_customize_define(codec); |
| 6096 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 6097 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
| 6098 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6099 | err = alc_codec_rename_from_preset(codec); |
| 6100 | if (err < 0) |
| 6101 | goto error; |
| 6102 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 6103 | if ((alc_get_coef0(codec) & (1 << 14)) && |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6104 | codec->bus->pci->subsystem_vendor == 0x1025 && |
| 6105 | spec->cdefine.platform_type == 1) { |
| 6106 | if (alc_codec_rename(codec, "ALC272X") < 0) |
| 6107 | goto error; |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 6108 | } |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 6109 | |
Takashi Iwai | b9c5106 | 2011-08-24 18:08:07 +0200 | [diff] [blame] | 6110 | alc_pick_fixup(codec, alc662_fixup_models, |
| 6111 | alc662_fixup_tbl, alc662_fixups); |
| 6112 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 6113 | /* automatic parse from the BIOS config */ |
| 6114 | err = alc662_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6115 | if (err < 0) |
| 6116 | goto error; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6117 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 6118 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 6119 | alc_auto_fill_adc_caps(codec); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 6120 | alc_rebuild_imux_for_auto_mic(codec); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 6121 | alc_remove_invalid_adc_nids(codec); |
Takashi Iwai | dd70469 | 2009-08-11 08:45:11 +0200 | [diff] [blame] | 6122 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6123 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6124 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | b59bdf3 | 2009-08-11 09:47:30 +0200 | [diff] [blame] | 6125 | set_capture_mixer(codec); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 6126 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6127 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 6128 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6129 | if (err < 0) |
| 6130 | goto error; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 6131 | switch (codec->vendor_id) { |
| 6132 | case 0x10ec0662: |
| 6133 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 6134 | break; |
| 6135 | case 0x10ec0272: |
| 6136 | case 0x10ec0663: |
| 6137 | case 0x10ec0665: |
| 6138 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
| 6139 | break; |
| 6140 | case 0x10ec0273: |
| 6141 | set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT); |
| 6142 | break; |
| 6143 | } |
Kailang Yang | cec27c8 | 2010-02-04 14:18:18 +0100 | [diff] [blame] | 6144 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 6145 | spec->vmaster_nid = 0x02; |
| 6146 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 6147 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 6148 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6149 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | b9c5106 | 2011-08-24 18:08:07 +0200 | [diff] [blame] | 6150 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 6151 | spec->shutup = alc_eapd_shutup; |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6152 | |
Kailang Yang | bf1b022 | 2010-10-21 08:49:56 +0200 | [diff] [blame] | 6153 | alc_init_jacks(codec); |
| 6154 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 6155 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 6156 | if (!spec->loopback.amplist) |
| 6157 | spec->loopback.amplist = alc662_loopbacks; |
| 6158 | #endif |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6159 | |
| 6160 | return 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6161 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6162 | error: |
| 6163 | alc_free(codec); |
| 6164 | return err; |
Kailang Yang | b478b99 | 2011-05-18 11:51:15 +0200 | [diff] [blame] | 6165 | } |
| 6166 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6167 | /* |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6168 | * ALC680 support |
| 6169 | */ |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6170 | |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6171 | static int alc680_parse_auto_config(struct hda_codec *codec) |
| 6172 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6173 | return alc_parse_auto_config(codec, NULL, NULL); |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6174 | } |
| 6175 | |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6176 | /* |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6177 | */ |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6178 | static int patch_alc680(struct hda_codec *codec) |
| 6179 | { |
| 6180 | struct alc_spec *spec; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6181 | int err; |
| 6182 | |
| 6183 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 6184 | if (spec == NULL) |
| 6185 | return -ENOMEM; |
| 6186 | |
| 6187 | codec->spec = spec; |
| 6188 | |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 6189 | /* ALC680 has no aa-loopback mixer */ |
| 6190 | |
Takashi Iwai | 1ebec5f | 2011-08-15 13:21:48 +0200 | [diff] [blame] | 6191 | /* automatic parse from the BIOS config */ |
| 6192 | err = alc680_parse_auto_config(codec); |
| 6193 | if (err < 0) { |
| 6194 | alc_free(codec); |
| 6195 | return err; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6196 | } |
| 6197 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6198 | if (!spec->no_analog && !spec->cap_mixer) |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6199 | set_capture_mixer(codec); |
| 6200 | |
| 6201 | spec->vmaster_nid = 0x02; |
| 6202 | |
| 6203 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 1ebec5f | 2011-08-15 13:21:48 +0200 | [diff] [blame] | 6204 | spec->init_hook = alc_auto_init_std; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6205 | |
| 6206 | return 0; |
| 6207 | } |
| 6208 | |
| 6209 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6210 | * patch entries |
| 6211 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 6212 | static const struct hda_codec_preset snd_hda_preset_realtek[] = { |
Kailang Yang | 296f033 | 2011-05-18 11:52:36 +0200 | [diff] [blame] | 6213 | { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6214 | { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 }, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 6215 | { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 }, |
Kailang Yang | f6a9224 | 2007-12-13 16:52:54 +0100 | [diff] [blame] | 6216 | { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 }, |
Kailang Yang | a361d84 | 2007-06-05 12:30:55 +0200 | [diff] [blame] | 6217 | { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 }, |
Kailang Yang | f6a9224 | 2007-12-13 16:52:54 +0100 | [diff] [blame] | 6218 | { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 }, |
Kailang Yang | ebb83ee | 2009-12-17 12:23:00 +0100 | [diff] [blame] | 6219 | { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 }, |
Kailang Yang | 01afd41 | 2008-10-15 11:22:09 +0200 | [diff] [blame] | 6220 | { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 }, |
Kailang Yang | ebb83ee | 2009-12-17 12:23:00 +0100 | [diff] [blame] | 6221 | { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 }, |
Kailang Yang | 296f033 | 2011-05-18 11:52:36 +0200 | [diff] [blame] | 6222 | { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 6223 | { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660", |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6224 | .patch = patch_alc861 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 6225 | { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd }, |
| 6226 | { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 }, |
| 6227 | { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd }, |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6228 | { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 6229 | .patch = patch_alc882 }, |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6230 | { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1", |
| 6231 | .patch = patch_alc662 }, |
David Henningsson | cc667a7 | 2011-10-18 14:07:51 +0200 | [diff] [blame] | 6232 | { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3", |
| 6233 | .patch = patch_alc662 }, |
Kailang Yang | 6dda9f4 | 2008-05-27 12:05:31 +0200 | [diff] [blame] | 6234 | { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 }, |
Kailang Yang | cec27c8 | 2010-02-04 14:18:18 +0100 | [diff] [blame] | 6235 | { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 }, |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 6236 | { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 }, |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6237 | { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 6238 | { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6239 | { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 6240 | { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 }, |
Clive Messer | 669faba | 2008-09-30 15:49:13 +0200 | [diff] [blame] | 6241 | { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 6242 | .patch = patch_alc882 }, |
Takashi Iwai | cb308f9 | 2008-04-16 14:13:29 +0200 | [diff] [blame] | 6243 | { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 6244 | .patch = patch_alc882 }, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 6245 | { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6246 | { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 }, |
Kailang Yang | 4442608 | 2008-10-15 11:18:05 +0200 | [diff] [blame] | 6247 | { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 6248 | .patch = patch_alc882 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6249 | { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 }, |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 6250 | { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 }, |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 6251 | { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6252 | { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6253 | {} /* terminator */ |
| 6254 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 6255 | |
| 6256 | MODULE_ALIAS("snd-hda-codec-id:10ec*"); |
| 6257 | |
| 6258 | MODULE_LICENSE("GPL"); |
| 6259 | MODULE_DESCRIPTION("Realtek HD-audio codec"); |
| 6260 | |
| 6261 | static struct hda_codec_preset_list realtek_list = { |
| 6262 | .preset = snd_hda_preset_realtek, |
| 6263 | .owner = THIS_MODULE, |
| 6264 | }; |
| 6265 | |
| 6266 | static int __init patch_realtek_init(void) |
| 6267 | { |
| 6268 | return snd_hda_add_codec_preset(&realtek_list); |
| 6269 | } |
| 6270 | |
| 6271 | static void __exit patch_realtek_exit(void) |
| 6272 | { |
| 6273 | snd_hda_delete_codec_preset(&realtek_list); |
| 6274 | } |
| 6275 | |
| 6276 | module_init(patch_realtek_init) |
| 6277 | module_exit(patch_realtek_exit) |