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 | |
Takashi Iwai | c14c95f | 2012-02-16 16:38:07 +0100 | [diff] [blame] | 83 | #define MAX_VOL_NIDS 0x40 |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | struct alc_spec { |
| 86 | /* codec parameterization */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 87 | const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | unsigned int num_mixers; |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 89 | const struct snd_kcontrol_new *cap_mixer; /* capture mixer */ |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 90 | unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Takashi Iwai | 2d9c648 | 2009-10-13 08:06:55 +0200 | [diff] [blame] | 92 | const struct hda_verb *init_verbs[10]; /* initialization verbs |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 93 | * don't forget NULL |
| 94 | * termination! |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 95 | */ |
| 96 | unsigned int num_init_verbs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Takashi Iwai | aa563af | 2009-07-31 10:05:11 +0200 | [diff] [blame] | 98 | char stream_name_analog[32]; /* analog PCM stream */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 99 | const struct hda_pcm_stream *stream_analog_playback; |
| 100 | const struct hda_pcm_stream *stream_analog_capture; |
| 101 | const struct hda_pcm_stream *stream_analog_alt_playback; |
| 102 | const struct hda_pcm_stream *stream_analog_alt_capture; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Takashi Iwai | aa563af | 2009-07-31 10:05:11 +0200 | [diff] [blame] | 104 | char stream_name_digital[32]; /* digital PCM stream */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 105 | const struct hda_pcm_stream *stream_digital_playback; |
| 106 | const struct hda_pcm_stream *stream_digital_capture; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | /* playback */ |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 109 | struct hda_multi_out multiout; /* playback set-up |
| 110 | * max_channels, dacs must be set |
| 111 | * dig_out_nid and hp_nid are optional |
| 112 | */ |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 113 | hda_nid_t alt_dac_nid; |
Takashi Iwai | 6a05ac4 | 2009-02-13 11:19:09 +0100 | [diff] [blame] | 114 | hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */ |
Takashi Iwai | 8c44198 | 2009-01-20 18:30:20 +0100 | [diff] [blame] | 115 | int dig_out_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | /* capture */ |
| 118 | unsigned int num_adc_nids; |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 119 | const hda_nid_t *adc_nids; |
| 120 | const hda_nid_t *capsrc_nids; |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 121 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 122 | hda_nid_t mixer_nid; /* analog-mixer NID */ |
Takashi Iwai | c14c95f | 2012-02-16 16:38:07 +0100 | [diff] [blame] | 123 | DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1); |
| 124 | DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 126 | /* capture setup for dynamic dual-adc switch */ |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 127 | hda_nid_t cur_adc; |
| 128 | unsigned int cur_adc_stream_tag; |
| 129 | unsigned int cur_adc_format; |
| 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | /* capture source */ |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 132 | unsigned int num_mux_defs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | const struct hda_input_mux *input_mux; |
| 134 | unsigned int cur_mux[3]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 135 | hda_nid_t ext_mic_pin; |
| 136 | hda_nid_t dock_mic_pin; |
| 137 | hda_nid_t int_mic_pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | /* channel model */ |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 140 | const struct hda_channel_mode *channel_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | int num_channel_mode; |
Takashi Iwai | 4e195a7 | 2006-07-28 14:47:34 +0200 | [diff] [blame] | 142 | int need_dac_fix; |
Hector Martin | 3b315d7 | 2009-06-02 10:54:19 +0200 | [diff] [blame] | 143 | int const_channel_count; |
| 144 | int ext_channel_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | /* PCM information */ |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 147 | struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */ |
Takashi Iwai | 41e41f1 | 2005-06-08 14:48:49 +0200 | [diff] [blame] | 148 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 149 | /* dynamic controls, init_verbs and input_mux */ |
| 150 | struct auto_pin_cfg autocfg; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 151 | struct alc_customize_define cdefine; |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 152 | struct snd_array kctls; |
Herton Ronaldo Krzesinski | 61b9b9b | 2009-01-28 09:16:33 -0200 | [diff] [blame] | 153 | struct hda_input_mux private_imux[3]; |
Takashi Iwai | 41923e4 | 2007-10-22 17:20:10 +0200 | [diff] [blame] | 154 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 155 | hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS]; |
| 156 | hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 157 | hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS]; |
| 158 | unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS]; |
| 159 | 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] | 160 | |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 161 | /* hooks */ |
| 162 | void (*init_hook)(struct hda_codec *codec); |
| 163 | void (*unsol_event)(struct hda_codec *codec, unsigned int res); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 164 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 165 | void (*power_hook)(struct hda_codec *codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 166 | #endif |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 167 | void (*shutup)(struct hda_codec *codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 168 | void (*automute_hook)(struct hda_codec *codec); |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 169 | |
Takashi Iwai | 834be88 | 2006-03-01 14:16:17 +0100 | [diff] [blame] | 170 | /* for pin sensing */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 171 | unsigned int hp_jack_present:1; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 172 | unsigned int line_jack_present:1; |
Takashi Iwai | e942796 | 2011-04-28 15:46:07 +0200 | [diff] [blame] | 173 | unsigned int master_mute:1; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 174 | unsigned int auto_mic:1; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 175 | unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 176 | unsigned int automute_speaker:1; /* automute speaker outputs */ |
| 177 | unsigned int automute_lo:1; /* automute LO outputs */ |
| 178 | unsigned int detect_hp:1; /* Headphone detection enabled */ |
| 179 | unsigned int detect_lo:1; /* Line-out detection enabled */ |
| 180 | unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */ |
| 181 | unsigned int automute_lo_possible:1; /* there are line outs and HP */ |
Takashi Iwai | 31150f2 | 2012-01-30 10:54:08 +0100 | [diff] [blame] | 182 | unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 183 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 184 | /* other flags */ |
| 185 | unsigned int no_analog :1; /* digital I/O only */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 186 | unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */ |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 187 | unsigned int single_input_src:1; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 188 | 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] | 189 | unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */ |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 190 | unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */ |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 191 | |
| 192 | /* auto-mute control */ |
| 193 | int automute_mode; |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 194 | hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 195 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 196 | int init_amp; |
Takashi Iwai | d433a67 | 2010-09-20 15:11:54 +0200 | [diff] [blame] | 197 | int codec_variant; /* flag for other variants */ |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 198 | |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 199 | /* for virtual master */ |
| 200 | hda_nid_t vmaster_nid; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 201 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 202 | struct hda_loopback_check loopback; |
| 203 | #endif |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 204 | |
| 205 | /* for PLL fix */ |
| 206 | hda_nid_t pll_nid; |
| 207 | unsigned int pll_coef_idx, pll_coef_bit; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 208 | unsigned int coef0; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 209 | |
| 210 | /* fix-up list */ |
| 211 | int fixup_id; |
| 212 | const struct alc_fixup *fixup_list; |
| 213 | const char *fixup_name; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 214 | |
| 215 | /* multi-io */ |
| 216 | int multi_ios; |
| 217 | struct alc_multi_io multi_io[4]; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 218 | |
| 219 | /* bind volumes */ |
| 220 | struct snd_array bind_ctls; |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 221 | }; |
| 222 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 223 | #define ALC_MODEL_AUTO 0 /* common for all chips */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 225 | static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, |
| 226 | int dir, unsigned int bits) |
| 227 | { |
| 228 | if (!nid) |
| 229 | return false; |
| 230 | if (get_wcaps(codec, nid) & (1 << (dir + 1))) |
| 231 | if (query_amp_caps(codec, nid, dir) & bits) |
| 232 | return true; |
| 233 | return false; |
| 234 | } |
| 235 | |
| 236 | #define nid_has_mute(codec, nid, dir) \ |
| 237 | check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE) |
| 238 | #define nid_has_volume(codec, nid, dir) \ |
| 239 | check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS) |
| 240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | /* |
| 242 | * input MUX handling |
| 243 | */ |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 244 | static int alc_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 245 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
| 247 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 248 | struct alc_spec *spec = codec->spec; |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 249 | unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id); |
| 250 | if (mux_idx >= spec->num_mux_defs) |
| 251 | mux_idx = 0; |
Takashi Iwai | 5311114 | 2010-03-08 12:13:07 +0100 | [diff] [blame] | 252 | if (!spec->input_mux[mux_idx].num_items && mux_idx > 0) |
| 253 | mux_idx = 0; |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 254 | return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 257 | static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 258 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
| 260 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 261 | struct alc_spec *spec = codec->spec; |
| 262 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 263 | |
| 264 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
| 265 | return 0; |
| 266 | } |
| 267 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 268 | 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] | 269 | { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 270 | struct alc_spec *spec = codec->spec; |
| 271 | hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]]; |
| 272 | |
| 273 | if (spec->cur_adc && spec->cur_adc != new_adc) { |
| 274 | /* stream is running, let's swap the current ADC */ |
| 275 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); |
| 276 | spec->cur_adc = new_adc; |
| 277 | snd_hda_codec_setup_stream(codec, new_adc, |
| 278 | spec->cur_adc_stream_tag, 0, |
| 279 | spec->cur_adc_format); |
| 280 | return true; |
| 281 | } |
| 282 | return false; |
| 283 | } |
| 284 | |
Takashi Iwai | 6107159 | 2011-11-23 07:52:15 +0100 | [diff] [blame] | 285 | static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx) |
| 286 | { |
| 287 | return spec->capsrc_nids ? |
| 288 | spec->capsrc_nids[idx] : spec->adc_nids[idx]; |
| 289 | } |
| 290 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 291 | static void call_update_outputs(struct hda_codec *codec); |
| 292 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 293 | /* select the given imux item; either unmute exclusively or select the route */ |
| 294 | static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx, |
| 295 | unsigned int idx, bool force) |
| 296 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 298 | const struct hda_input_mux *imux; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 299 | unsigned int mux_idx; |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 300 | int i, type, num_conns; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 301 | hda_nid_t nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 303 | mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; |
| 304 | imux = &spec->input_mux[mux_idx]; |
Takashi Iwai | 5311114 | 2010-03-08 12:13:07 +0100 | [diff] [blame] | 305 | if (!imux->num_items && mux_idx > 0) |
| 306 | imux = &spec->input_mux[0]; |
Takashi Iwai | cce4aa3 | 2011-12-02 15:29:12 +0100 | [diff] [blame] | 307 | if (!imux->num_items) |
| 308 | return 0; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 309 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 310 | if (idx >= imux->num_items) |
| 311 | idx = imux->num_items - 1; |
| 312 | if (spec->cur_mux[adc_idx] == idx && !force) |
| 313 | return 0; |
| 314 | spec->cur_mux[adc_idx] = idx; |
| 315 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 316 | /* for shared I/O, change the pin-control accordingly */ |
| 317 | if (spec->shared_mic_hp) { |
| 318 | /* NOTE: this assumes that there are only two inputs, the |
| 319 | * first is the real internal mic and the second is HP jack. |
| 320 | */ |
| 321 | snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0, |
| 322 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 323 | spec->cur_mux[adc_idx] ? |
| 324 | PIN_VREF80 : PIN_HP); |
| 325 | spec->automute_speaker = !spec->cur_mux[adc_idx]; |
| 326 | call_update_outputs(codec); |
| 327 | } |
| 328 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 329 | if (spec->dyn_adc_switch) { |
| 330 | alc_dyn_adc_pcm_resetup(codec, idx); |
| 331 | adc_idx = spec->dyn_adc_idx[idx]; |
| 332 | } |
| 333 | |
Takashi Iwai | 6107159 | 2011-11-23 07:52:15 +0100 | [diff] [blame] | 334 | nid = get_capsrc(spec, adc_idx); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 335 | |
| 336 | /* no selection? */ |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 337 | num_conns = snd_hda_get_conn_list(codec, nid, NULL); |
| 338 | if (num_conns <= 1) |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 339 | return 1; |
| 340 | |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 341 | type = get_wcaps_type(get_wcaps(codec, nid)); |
Takashi Iwai | 0169b6b | 2009-06-22 10:50:19 +0200 | [diff] [blame] | 342 | if (type == AC_WID_AUD_MIX) { |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 343 | /* Matrix-mixer style (e.g. ALC882) */ |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 344 | int active = imux->items[idx].index; |
| 345 | for (i = 0; i < num_conns; i++) { |
| 346 | unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE; |
| 347 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i, |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 348 | HDA_AMP_MUTE, v); |
| 349 | } |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 350 | } else { |
| 351 | /* MUX style (e.g. ALC880) */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 352 | snd_hda_codec_write_cache(codec, nid, 0, |
| 353 | AC_VERB_SET_CONNECT_SEL, |
| 354 | imux->items[idx].index); |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 355 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 356 | return 1; |
| 357 | } |
| 358 | |
| 359 | static int alc_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 360 | struct snd_ctl_elem_value *ucontrol) |
| 361 | { |
| 362 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 363 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 364 | return alc_mux_select(codec, adc_idx, |
| 365 | ucontrol->value.enumerated.item[0], false); |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 366 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | /* |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 369 | * set up the input pin config (depending on the given auto-pin type) |
| 370 | */ |
| 371 | static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid, |
| 372 | int auto_pin_type) |
| 373 | { |
| 374 | unsigned int val = PIN_IN; |
| 375 | |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 376 | if (auto_pin_type == AUTO_PIN_MIC) { |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 377 | unsigned int pincap; |
Takashi Iwai | 954a29c | 2010-07-30 10:55:44 +0200 | [diff] [blame] | 378 | unsigned int oldval; |
| 379 | oldval = snd_hda_codec_read(codec, nid, 0, |
| 380 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
Takashi Iwai | 1327a32 | 2009-03-23 13:07:47 +0100 | [diff] [blame] | 381 | pincap = snd_hda_query_pin_caps(codec, nid); |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 382 | pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; |
Takashi Iwai | 954a29c | 2010-07-30 10:55:44 +0200 | [diff] [blame] | 383 | /* if the default pin setup is vref50, we give it priority */ |
| 384 | if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50) |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 385 | val = PIN_VREF80; |
Takashi Iwai | 461c6c3 | 2009-05-25 08:06:02 +0200 | [diff] [blame] | 386 | else if (pincap & AC_PINCAP_VREF_50) |
| 387 | val = PIN_VREF50; |
| 388 | else if (pincap & AC_PINCAP_VREF_100) |
| 389 | val = PIN_VREF100; |
| 390 | else if (pincap & AC_PINCAP_VREF_GRD) |
| 391 | val = PIN_VREFGRD; |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 392 | } |
| 393 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val); |
| 394 | } |
| 395 | |
| 396 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 397 | * Append the given mixer and verb elements for the later use |
| 398 | * The mixer array is referred in build_controls(), and init_verbs are |
| 399 | * called in init(). |
Takashi Iwai | d88897e | 2008-10-31 15:01:37 +0100 | [diff] [blame] | 400 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 401 | 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] | 402 | { |
| 403 | if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers))) |
| 404 | return; |
| 405 | spec->mixers[spec->num_mixers++] = mix; |
| 406 | } |
| 407 | |
| 408 | static void add_verb(struct alc_spec *spec, const struct hda_verb *verb) |
| 409 | { |
| 410 | if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs))) |
| 411 | return; |
| 412 | spec->init_verbs[spec->num_init_verbs++] = verb; |
| 413 | } |
| 414 | |
| 415 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 416 | * GPIO setup tables, used in initialization |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 417 | */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 418 | /* Enable GPIO mask and set output */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 419 | static const struct hda_verb alc_gpio1_init_verbs[] = { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 420 | {0x01, AC_VERB_SET_GPIO_MASK, 0x01}, |
| 421 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, |
| 422 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, |
| 423 | { } |
| 424 | }; |
| 425 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 426 | static const struct hda_verb alc_gpio2_init_verbs[] = { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 427 | {0x01, AC_VERB_SET_GPIO_MASK, 0x02}, |
| 428 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02}, |
| 429 | {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, |
| 430 | { } |
| 431 | }; |
| 432 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 433 | static const struct hda_verb alc_gpio3_init_verbs[] = { |
Kailang Yang | bdd148a | 2007-05-08 15:19:08 +0200 | [diff] [blame] | 434 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, |
| 435 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03}, |
| 436 | {0x01, AC_VERB_SET_GPIO_DATA, 0x03}, |
| 437 | { } |
| 438 | }; |
| 439 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 440 | /* |
| 441 | * Fix hardware PLL issue |
| 442 | * On some codecs, the analog PLL gating control must be off while |
| 443 | * the default value is 1. |
| 444 | */ |
| 445 | static void alc_fix_pll(struct hda_codec *codec) |
| 446 | { |
| 447 | struct alc_spec *spec = codec->spec; |
| 448 | unsigned int val; |
| 449 | |
| 450 | if (!spec->pll_nid) |
| 451 | return; |
| 452 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, |
| 453 | spec->pll_coef_idx); |
| 454 | val = snd_hda_codec_read(codec, spec->pll_nid, 0, |
| 455 | AC_VERB_GET_PROC_COEF, 0); |
| 456 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, |
| 457 | spec->pll_coef_idx); |
| 458 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF, |
| 459 | val & ~(1 << spec->pll_coef_bit)); |
| 460 | } |
| 461 | |
| 462 | static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid, |
| 463 | unsigned int coef_idx, unsigned int coef_bit) |
| 464 | { |
| 465 | struct alc_spec *spec = codec->spec; |
| 466 | spec->pll_nid = nid; |
| 467 | spec->pll_coef_idx = coef_idx; |
| 468 | spec->pll_coef_bit = coef_bit; |
| 469 | alc_fix_pll(codec); |
| 470 | } |
| 471 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 472 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 473 | * Jack detections for HP auto-mute and mic-switch |
| 474 | */ |
| 475 | |
| 476 | /* check each pin in the given array; returns true if any of them is plugged */ |
| 477 | 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] | 478 | { |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 479 | int i, present = 0; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 480 | |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 481 | for (i = 0; i < num_pins; i++) { |
| 482 | hda_nid_t nid = pins[i]; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 483 | if (!nid) |
| 484 | break; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 485 | present |= snd_hda_jack_detect(codec, nid); |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 486 | } |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 487 | return present; |
| 488 | } |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 489 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 490 | /* standard HP/line-out auto-mute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 491 | 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] | 492 | bool mute, bool hp_out) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 493 | { |
| 494 | struct alc_spec *spec = codec->spec; |
| 495 | unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0; |
Takashi Iwai | e942796 | 2011-04-28 15:46:07 +0200 | [diff] [blame] | 496 | unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 497 | int i; |
| 498 | |
| 499 | for (i = 0; i < num_pins; i++) { |
| 500 | hda_nid_t nid = pins[i]; |
Takashi Iwai | 31150f2 | 2012-01-30 10:54:08 +0100 | [diff] [blame] | 501 | unsigned int val; |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 502 | if (!nid) |
| 503 | break; |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 504 | switch (spec->automute_mode) { |
| 505 | case ALC_AUTOMUTE_PIN: |
Takashi Iwai | 31150f2 | 2012-01-30 10:54:08 +0100 | [diff] [blame] | 506 | /* don't reset VREF value in case it's controlling |
| 507 | * the amp (see alc861_fixup_asus_amp_vref_0f()) |
| 508 | */ |
| 509 | if (spec->keep_vref_in_automute) { |
| 510 | val = snd_hda_codec_read(codec, nid, 0, |
| 511 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 512 | val &= ~PIN_HP; |
| 513 | } else |
| 514 | val = 0; |
| 515 | val |= pin_bits; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 516 | snd_hda_codec_write(codec, nid, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 517 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
Takashi Iwai | 31150f2 | 2012-01-30 10:54:08 +0100 | [diff] [blame] | 518 | val); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 519 | break; |
| 520 | case ALC_AUTOMUTE_AMP: |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 521 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 522 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 523 | break; |
| 524 | case ALC_AUTOMUTE_MIXER: |
| 525 | nid = spec->automute_mixer_nid[i]; |
| 526 | if (!nid) |
| 527 | break; |
| 528 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 529 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 530 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 531 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 532 | break; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 533 | } |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 534 | } |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 535 | } |
| 536 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 537 | /* Toggle outputs muting */ |
| 538 | static void update_outputs(struct hda_codec *codec) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 539 | { |
| 540 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 541 | int on; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 542 | |
Takashi Iwai | c0a2026 | 2011-06-10 15:28:15 +0200 | [diff] [blame] | 543 | /* Control HP pins/amps depending on master_mute state; |
| 544 | * in general, HP pins/amps control should be enabled in all cases, |
| 545 | * but currently set only for master_mute, just to be safe |
| 546 | */ |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 547 | if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */ |
| 548 | do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins), |
Takashi Iwai | c0a2026 | 2011-06-10 15:28:15 +0200 | [diff] [blame] | 549 | spec->autocfg.hp_pins, spec->master_mute, true); |
| 550 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 551 | if (!spec->automute_speaker) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 552 | on = 0; |
| 553 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 554 | on = spec->hp_jack_present | spec->line_jack_present; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 555 | on |= spec->master_mute; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 556 | do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins), |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 557 | spec->autocfg.speaker_pins, on, false); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 558 | |
| 559 | /* toggle line-out mutes if needed, too */ |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 560 | /* if LO is a copy of either HP or Speaker, don't need to handle it */ |
| 561 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] || |
| 562 | spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0]) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 563 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 564 | if (!spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 565 | on = 0; |
| 566 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 567 | on = spec->hp_jack_present; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 568 | on |= spec->master_mute; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 569 | do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 570 | spec->autocfg.line_out_pins, on, false); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 571 | } |
| 572 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 573 | static void call_update_outputs(struct hda_codec *codec) |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 574 | { |
| 575 | struct alc_spec *spec = codec->spec; |
| 576 | if (spec->automute_hook) |
| 577 | spec->automute_hook(codec); |
| 578 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 579 | update_outputs(codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 580 | } |
| 581 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 582 | /* standard HP-automute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 583 | static void alc_hp_automute(struct hda_codec *codec) |
| 584 | { |
| 585 | struct alc_spec *spec = codec->spec; |
| 586 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 587 | spec->hp_jack_present = |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 588 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins), |
| 589 | spec->autocfg.hp_pins); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 590 | if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo)) |
Takashi Iwai | 3c715a9 | 2011-08-23 12:41:09 +0200 | [diff] [blame] | 591 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 592 | call_update_outputs(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 593 | } |
| 594 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 595 | /* standard line-out-automute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 596 | static void alc_line_automute(struct hda_codec *codec) |
| 597 | { |
| 598 | struct alc_spec *spec = codec->spec; |
| 599 | |
Takashi Iwai | e0d32e3 | 2011-09-26 15:19:55 +0200 | [diff] [blame] | 600 | /* check LO jack only when it's different from HP */ |
| 601 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0]) |
| 602 | return; |
| 603 | |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 604 | spec->line_jack_present = |
| 605 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
| 606 | spec->autocfg.line_out_pins); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 607 | if (!spec->automute_speaker || !spec->detect_lo) |
Takashi Iwai | 3c715a9 | 2011-08-23 12:41:09 +0200 | [diff] [blame] | 608 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 609 | call_update_outputs(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 610 | } |
| 611 | |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 612 | #define get_connection_index(codec, mux, nid) \ |
| 613 | snd_hda_get_conn_index(codec, mux, nid, 0) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 614 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 615 | /* standard mic auto-switch helper */ |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 616 | static void alc_mic_automute(struct hda_codec *codec) |
| 617 | { |
| 618 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 619 | hda_nid_t *pins = spec->imux_pins; |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 620 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 621 | if (!spec->auto_mic || !spec->auto_mic_valid_imux) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 622 | return; |
| 623 | if (snd_BUG_ON(!spec->adc_nids)) |
| 624 | return; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 625 | 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] | 626 | return; |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 627 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 628 | if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx])) |
| 629 | alc_mux_select(codec, 0, spec->ext_mic_idx, false); |
| 630 | else if (spec->dock_mic_idx >= 0 && |
| 631 | snd_hda_jack_detect(codec, pins[spec->dock_mic_idx])) |
| 632 | alc_mux_select(codec, 0, spec->dock_mic_idx, false); |
| 633 | else |
| 634 | alc_mux_select(codec, 0, spec->int_mic_idx, false); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 635 | } |
| 636 | |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 637 | /* handle the specified unsol action (ALC_XXX_EVENT) */ |
| 638 | static void alc_exec_unsol_event(struct hda_codec *codec, int action) |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 639 | { |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 640 | switch (action) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 641 | case ALC_HP_EVENT: |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 642 | alc_hp_automute(codec); |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 643 | break; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 644 | case ALC_FRONT_EVENT: |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 645 | alc_line_automute(codec); |
| 646 | break; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 647 | case ALC_MIC_EVENT: |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 648 | alc_mic_automute(codec); |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 649 | break; |
| 650 | } |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 651 | snd_hda_jack_report_sync(codec); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 652 | } |
| 653 | |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 654 | /* unsolicited event for HP jack sensing */ |
| 655 | static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res) |
| 656 | { |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 657 | if (codec->vendor_id == 0x10ec0880) |
| 658 | res >>= 28; |
| 659 | else |
| 660 | res >>= 26; |
Takashi Iwai | a730979 | 2012-01-19 15:03:48 +0100 | [diff] [blame] | 661 | res = snd_hda_jack_get_action(codec, res); |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 662 | alc_exec_unsol_event(codec, res); |
| 663 | } |
| 664 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 665 | /* call init functions of standard auto-mute helpers */ |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 666 | static void alc_inithook(struct hda_codec *codec) |
| 667 | { |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 668 | alc_hp_automute(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 669 | alc_line_automute(codec); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 670 | alc_mic_automute(codec); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 671 | } |
| 672 | |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 673 | /* additional initialization for ALC888 variants */ |
| 674 | static void alc888_coef_init(struct hda_codec *codec) |
| 675 | { |
| 676 | unsigned int tmp; |
| 677 | |
| 678 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0); |
| 679 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 680 | 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] | 681 | if ((tmp & 0xf0) == 0x20) |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 682 | /* alc888S-VC */ |
| 683 | snd_hda_codec_read(codec, 0x20, 0, |
| 684 | AC_VERB_SET_PROC_COEF, 0x830); |
| 685 | else |
| 686 | /* alc888-VB */ |
| 687 | snd_hda_codec_read(codec, 0x20, 0, |
| 688 | AC_VERB_SET_PROC_COEF, 0x3030); |
| 689 | } |
| 690 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 691 | /* additional initialization for ALC889 variants */ |
Jaroslav Kysela | 87a8c37 | 2009-07-23 10:58:29 +0200 | [diff] [blame] | 692 | static void alc889_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, 7); |
| 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); |
| 699 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010); |
| 700 | } |
| 701 | |
Takashi Iwai | 3fb4a50 | 2010-01-19 15:46:37 +0100 | [diff] [blame] | 702 | /* turn on/off EAPD control (only if available) */ |
| 703 | static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on) |
| 704 | { |
| 705 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) |
| 706 | return; |
| 707 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) |
| 708 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE, |
| 709 | on ? 2 : 0); |
| 710 | } |
| 711 | |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 712 | /* turn on/off EAPD controls of the codec */ |
| 713 | static void alc_auto_setup_eapd(struct hda_codec *codec, bool on) |
| 714 | { |
| 715 | /* We currently only handle front, HP */ |
Takashi Iwai | 39fa84e | 2011-06-27 15:28:57 +0200 | [diff] [blame] | 716 | static hda_nid_t pins[] = { |
| 717 | 0x0f, 0x10, 0x14, 0x15, 0 |
| 718 | }; |
| 719 | hda_nid_t *p; |
| 720 | for (p = pins; *p; p++) |
| 721 | set_eapd(codec, *p, on); |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 722 | } |
| 723 | |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 724 | /* generic shutup callback; |
| 725 | * just turning off EPAD and a little pause for avoiding pop-noise |
| 726 | */ |
| 727 | static void alc_eapd_shutup(struct hda_codec *codec) |
| 728 | { |
| 729 | alc_auto_setup_eapd(codec, false); |
| 730 | msleep(200); |
| 731 | } |
| 732 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 733 | /* generic EAPD initialization */ |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 734 | static void alc_auto_init_amp(struct hda_codec *codec, int type) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 735 | { |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 736 | unsigned int tmp; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 737 | |
Takashi Iwai | 39fa84e | 2011-06-27 15:28:57 +0200 | [diff] [blame] | 738 | alc_auto_setup_eapd(codec, true); |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 739 | switch (type) { |
| 740 | case ALC_INIT_GPIO1: |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 741 | snd_hda_sequence_write(codec, alc_gpio1_init_verbs); |
| 742 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 743 | case ALC_INIT_GPIO2: |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 744 | snd_hda_sequence_write(codec, alc_gpio2_init_verbs); |
| 745 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 746 | case ALC_INIT_GPIO3: |
Kailang Yang | bdd148a | 2007-05-08 15:19:08 +0200 | [diff] [blame] | 747 | snd_hda_sequence_write(codec, alc_gpio3_init_verbs); |
| 748 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 749 | case ALC_INIT_DEFAULT: |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 750 | switch (codec->vendor_id) { |
| 751 | case 0x10ec0260: |
| 752 | snd_hda_codec_write(codec, 0x1a, 0, |
| 753 | AC_VERB_SET_COEF_INDEX, 7); |
| 754 | tmp = snd_hda_codec_read(codec, 0x1a, 0, |
| 755 | AC_VERB_GET_PROC_COEF, 0); |
| 756 | snd_hda_codec_write(codec, 0x1a, 0, |
| 757 | AC_VERB_SET_COEF_INDEX, 7); |
| 758 | snd_hda_codec_write(codec, 0x1a, 0, |
| 759 | AC_VERB_SET_PROC_COEF, |
| 760 | tmp | 0x2010); |
| 761 | break; |
| 762 | case 0x10ec0262: |
| 763 | case 0x10ec0880: |
| 764 | case 0x10ec0882: |
| 765 | case 0x10ec0883: |
| 766 | case 0x10ec0885: |
Takashi Iwai | 4a5a4c5 | 2009-02-06 12:46:59 +0100 | [diff] [blame] | 767 | case 0x10ec0887: |
Takashi Iwai | 20b67dd | 2011-03-23 22:54:32 +0100 | [diff] [blame] | 768 | /*case 0x10ec0889:*/ /* this causes an SPDIF problem */ |
Jaroslav Kysela | 87a8c37 | 2009-07-23 10:58:29 +0200 | [diff] [blame] | 769 | alc889_coef_init(codec); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 770 | break; |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 771 | case 0x10ec0888: |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 772 | alc888_coef_init(codec); |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 773 | break; |
Takashi Iwai | 0aea778 | 2010-01-25 15:44:11 +0100 | [diff] [blame] | 774 | #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] | 775 | case 0x10ec0267: |
| 776 | case 0x10ec0268: |
| 777 | snd_hda_codec_write(codec, 0x20, 0, |
| 778 | AC_VERB_SET_COEF_INDEX, 7); |
| 779 | tmp = snd_hda_codec_read(codec, 0x20, 0, |
| 780 | AC_VERB_GET_PROC_COEF, 0); |
| 781 | snd_hda_codec_write(codec, 0x20, 0, |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 782 | AC_VERB_SET_COEF_INDEX, 7); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 783 | snd_hda_codec_write(codec, 0x20, 0, |
| 784 | AC_VERB_SET_PROC_COEF, |
| 785 | tmp | 0x3000); |
| 786 | break; |
Takashi Iwai | 0aea778 | 2010-01-25 15:44:11 +0100 | [diff] [blame] | 787 | #endif /* XXX */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 788 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 789 | break; |
| 790 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 791 | } |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 792 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 793 | /* |
| 794 | * Auto-Mute mode mixer enum support |
| 795 | */ |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 796 | static int alc_automute_mode_info(struct snd_kcontrol *kcontrol, |
| 797 | struct snd_ctl_elem_info *uinfo) |
| 798 | { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 799 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 800 | struct alc_spec *spec = codec->spec; |
| 801 | static const char * const texts2[] = { |
| 802 | "Disabled", "Enabled" |
| 803 | }; |
| 804 | static const char * const texts3[] = { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 805 | "Disabled", "Speaker Only", "Line-Out+Speaker" |
| 806 | }; |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 807 | const char * const *texts; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 808 | |
| 809 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 810 | uinfo->count = 1; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 811 | if (spec->automute_speaker_possible && spec->automute_lo_possible) { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 812 | uinfo->value.enumerated.items = 3; |
| 813 | texts = texts3; |
| 814 | } else { |
| 815 | uinfo->value.enumerated.items = 2; |
| 816 | texts = texts2; |
| 817 | } |
| 818 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 819 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 820 | strcpy(uinfo->value.enumerated.name, |
| 821 | texts[uinfo->value.enumerated.item]); |
| 822 | return 0; |
| 823 | } |
| 824 | |
| 825 | static int alc_automute_mode_get(struct snd_kcontrol *kcontrol, |
| 826 | struct snd_ctl_elem_value *ucontrol) |
| 827 | { |
| 828 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 829 | struct alc_spec *spec = codec->spec; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 830 | unsigned int val = 0; |
| 831 | if (spec->automute_speaker) |
| 832 | val++; |
| 833 | if (spec->automute_lo) |
| 834 | val++; |
| 835 | |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 836 | ucontrol->value.enumerated.item[0] = val; |
| 837 | return 0; |
| 838 | } |
| 839 | |
| 840 | static int alc_automute_mode_put(struct snd_kcontrol *kcontrol, |
| 841 | struct snd_ctl_elem_value *ucontrol) |
| 842 | { |
| 843 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 844 | struct alc_spec *spec = codec->spec; |
| 845 | |
| 846 | switch (ucontrol->value.enumerated.item[0]) { |
| 847 | case 0: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 848 | if (!spec->automute_speaker && !spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 849 | return 0; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 850 | spec->automute_speaker = 0; |
| 851 | spec->automute_lo = 0; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 852 | break; |
| 853 | case 1: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 854 | if (spec->automute_speaker_possible) { |
| 855 | if (!spec->automute_lo && spec->automute_speaker) |
| 856 | return 0; |
| 857 | spec->automute_speaker = 1; |
| 858 | spec->automute_lo = 0; |
| 859 | } else if (spec->automute_lo_possible) { |
| 860 | if (spec->automute_lo) |
| 861 | return 0; |
| 862 | spec->automute_lo = 1; |
| 863 | } else |
| 864 | return -EINVAL; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 865 | break; |
| 866 | case 2: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 867 | if (!spec->automute_lo_possible || !spec->automute_speaker_possible) |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 868 | return -EINVAL; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 869 | if (spec->automute_speaker && spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 870 | return 0; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 871 | spec->automute_speaker = 1; |
| 872 | spec->automute_lo = 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 873 | break; |
| 874 | default: |
| 875 | return -EINVAL; |
| 876 | } |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 877 | call_update_outputs(codec); |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 878 | return 1; |
| 879 | } |
| 880 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 881 | static const struct snd_kcontrol_new alc_automute_mode_enum = { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 882 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 883 | .name = "Auto-Mute Mode", |
| 884 | .info = alc_automute_mode_info, |
| 885 | .get = alc_automute_mode_get, |
| 886 | .put = alc_automute_mode_put, |
| 887 | }; |
| 888 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 889 | static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec) |
| 890 | { |
| 891 | snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32); |
| 892 | return snd_array_new(&spec->kctls); |
| 893 | } |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 894 | |
| 895 | static int alc_add_automute_mode_enum(struct hda_codec *codec) |
| 896 | { |
| 897 | struct alc_spec *spec = codec->spec; |
| 898 | struct snd_kcontrol_new *knew; |
| 899 | |
| 900 | knew = alc_kcontrol_new(spec); |
| 901 | if (!knew) |
| 902 | return -ENOMEM; |
| 903 | *knew = alc_automute_mode_enum; |
| 904 | knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL); |
| 905 | if (!knew->name) |
| 906 | return -ENOMEM; |
| 907 | return 0; |
| 908 | } |
| 909 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 910 | /* |
| 911 | * Check the availability of HP/line-out auto-mute; |
| 912 | * Set up appropriately if really supported |
| 913 | */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 914 | static void alc_init_automute(struct hda_codec *codec) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 915 | { |
| 916 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 917 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 1daf5f4 | 2011-04-28 17:57:46 +0200 | [diff] [blame] | 918 | int present = 0; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 919 | int i; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 920 | |
Takashi Iwai | 1daf5f4 | 2011-04-28 17:57:46 +0200 | [diff] [blame] | 921 | if (cfg->hp_pins[0]) |
| 922 | present++; |
| 923 | if (cfg->line_out_pins[0]) |
| 924 | present++; |
| 925 | if (cfg->speaker_pins[0]) |
| 926 | present++; |
| 927 | if (present < 2) /* need two different output types */ |
| 928 | return; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 929 | |
Takashi Iwai | c48a8fb | 2011-07-27 16:41:57 +0200 | [diff] [blame] | 930 | if (!cfg->speaker_pins[0] && |
| 931 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 932 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 933 | sizeof(cfg->speaker_pins)); |
| 934 | cfg->speaker_outs = cfg->line_outs; |
| 935 | } |
| 936 | |
Takashi Iwai | c48a8fb | 2011-07-27 16:41:57 +0200 | [diff] [blame] | 937 | if (!cfg->hp_pins[0] && |
| 938 | cfg->line_out_type == AUTO_PIN_HP_OUT) { |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 939 | memcpy(cfg->hp_pins, cfg->line_out_pins, |
| 940 | sizeof(cfg->hp_pins)); |
| 941 | cfg->hp_outs = cfg->line_outs; |
| 942 | } |
| 943 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 944 | spec->automute_mode = ALC_AUTOMUTE_PIN; |
| 945 | |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 946 | for (i = 0; i < cfg->hp_outs; i++) { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 947 | hda_nid_t nid = cfg->hp_pins[i]; |
Takashi Iwai | 06dec22 | 2011-05-17 10:00:16 +0200 | [diff] [blame] | 948 | if (!is_jack_detectable(codec, nid)) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 949 | continue; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 950 | snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n", |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 951 | nid); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 952 | snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 953 | spec->detect_hp = 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 954 | } |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 955 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 956 | if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) { |
| 957 | if (cfg->speaker_outs) |
| 958 | for (i = 0; i < cfg->line_outs; i++) { |
| 959 | hda_nid_t nid = cfg->line_out_pins[i]; |
| 960 | if (!is_jack_detectable(codec, nid)) |
| 961 | continue; |
| 962 | snd_printdd("realtek: Enable Line-Out " |
| 963 | "auto-muting on NID 0x%x\n", nid); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 964 | snd_hda_jack_detect_enable(codec, nid, |
| 965 | ALC_FRONT_EVENT); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 966 | spec->detect_lo = 1; |
| 967 | } |
| 968 | spec->automute_lo_possible = spec->detect_hp; |
| 969 | } |
| 970 | |
| 971 | spec->automute_speaker_possible = cfg->speaker_outs && |
| 972 | (spec->detect_hp || spec->detect_lo); |
| 973 | |
| 974 | spec->automute_lo = spec->automute_lo_possible; |
| 975 | spec->automute_speaker = spec->automute_speaker_possible; |
| 976 | |
| 977 | if (spec->automute_speaker_possible || spec->automute_lo_possible) { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 978 | /* create a control for automute mode */ |
| 979 | alc_add_automute_mode_enum(codec); |
| 980 | spec->unsol_event = alc_sku_unsol_event; |
| 981 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 982 | } |
| 983 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 984 | /* 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] | 985 | static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 986 | { |
| 987 | int i; |
| 988 | for (i = 0; i < nums; i++) |
| 989 | if (list[i] == nid) |
| 990 | return i; |
| 991 | return -1; |
| 992 | } |
| 993 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 994 | /* check whether dynamic ADC-switching is available */ |
| 995 | static bool alc_check_dyn_adc_switch(struct hda_codec *codec) |
| 996 | { |
| 997 | struct alc_spec *spec = codec->spec; |
| 998 | struct hda_input_mux *imux = &spec->private_imux[0]; |
| 999 | int i, n, idx; |
| 1000 | hda_nid_t cap, pin; |
| 1001 | |
| 1002 | if (imux != spec->input_mux) /* no dynamic imux? */ |
| 1003 | return false; |
| 1004 | |
| 1005 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 1006 | cap = spec->private_capsrc_nids[n]; |
| 1007 | for (i = 0; i < imux->num_items; i++) { |
| 1008 | pin = spec->imux_pins[i]; |
| 1009 | if (!pin) |
| 1010 | return false; |
| 1011 | if (get_connection_index(codec, cap, pin) < 0) |
| 1012 | break; |
| 1013 | } |
| 1014 | if (i >= imux->num_items) |
Takashi Iwai | 268ff6f | 2011-07-08 14:37:35 +0200 | [diff] [blame] | 1015 | return true; /* no ADC-switch is needed */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | for (i = 0; i < imux->num_items; i++) { |
| 1019 | pin = spec->imux_pins[i]; |
| 1020 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 1021 | cap = spec->private_capsrc_nids[n]; |
| 1022 | idx = get_connection_index(codec, cap, pin); |
| 1023 | if (idx >= 0) { |
| 1024 | imux->items[i].index = idx; |
| 1025 | spec->dyn_adc_idx[i] = n; |
| 1026 | break; |
| 1027 | } |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | snd_printdd("realtek: enabling ADC switching\n"); |
| 1032 | spec->dyn_adc_switch = 1; |
| 1033 | return true; |
| 1034 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1035 | |
| 1036 | /* rebuild imux for matching with the given auto-mic pins (if not yet) */ |
| 1037 | static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec) |
| 1038 | { |
| 1039 | struct alc_spec *spec = codec->spec; |
| 1040 | struct hda_input_mux *imux; |
| 1041 | static char * const texts[3] = { |
| 1042 | "Mic", "Internal Mic", "Dock Mic" |
| 1043 | }; |
| 1044 | int i; |
| 1045 | |
| 1046 | if (!spec->auto_mic) |
| 1047 | return false; |
| 1048 | imux = &spec->private_imux[0]; |
| 1049 | if (spec->input_mux == imux) |
| 1050 | return true; |
| 1051 | spec->imux_pins[0] = spec->ext_mic_pin; |
| 1052 | spec->imux_pins[1] = spec->int_mic_pin; |
| 1053 | spec->imux_pins[2] = spec->dock_mic_pin; |
| 1054 | for (i = 0; i < 3; i++) { |
| 1055 | strcpy(imux->items[i].label, texts[i]); |
Takashi Iwai | 6759dc3 | 2011-11-23 07:38:59 +0100 | [diff] [blame] | 1056 | if (spec->imux_pins[i]) { |
| 1057 | hda_nid_t pin = spec->imux_pins[i]; |
| 1058 | int c; |
| 1059 | for (c = 0; c < spec->num_adc_nids; c++) { |
Takashi Iwai | 6107159 | 2011-11-23 07:52:15 +0100 | [diff] [blame] | 1060 | hda_nid_t cap = get_capsrc(spec, c); |
Takashi Iwai | 6759dc3 | 2011-11-23 07:38:59 +0100 | [diff] [blame] | 1061 | int idx = get_connection_index(codec, cap, pin); |
| 1062 | if (idx >= 0) { |
| 1063 | imux->items[i].index = idx; |
| 1064 | break; |
| 1065 | } |
| 1066 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1067 | imux->num_items = i + 1; |
Takashi Iwai | 6759dc3 | 2011-11-23 07:38:59 +0100 | [diff] [blame] | 1068 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1069 | } |
| 1070 | spec->num_mux_defs = 1; |
| 1071 | spec->input_mux = imux; |
| 1072 | return true; |
| 1073 | } |
| 1074 | |
| 1075 | /* check whether all auto-mic pins are valid; setup indices if OK */ |
| 1076 | static bool alc_auto_mic_check_imux(struct hda_codec *codec) |
| 1077 | { |
| 1078 | struct alc_spec *spec = codec->spec; |
| 1079 | const struct hda_input_mux *imux; |
| 1080 | |
| 1081 | if (!spec->auto_mic) |
| 1082 | return false; |
| 1083 | if (spec->auto_mic_valid_imux) |
| 1084 | return true; /* already checked */ |
| 1085 | |
| 1086 | /* fill up imux indices */ |
| 1087 | if (!alc_check_dyn_adc_switch(codec)) { |
| 1088 | spec->auto_mic = 0; |
| 1089 | return false; |
| 1090 | } |
| 1091 | |
| 1092 | imux = spec->input_mux; |
| 1093 | spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin, |
| 1094 | spec->imux_pins, imux->num_items); |
| 1095 | spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin, |
| 1096 | spec->imux_pins, imux->num_items); |
| 1097 | spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin, |
| 1098 | spec->imux_pins, imux->num_items); |
| 1099 | if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) { |
| 1100 | spec->auto_mic = 0; |
| 1101 | return false; /* no corresponding imux */ |
| 1102 | } |
| 1103 | |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 1104 | 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] | 1105 | if (spec->dock_mic_pin) |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 1106 | snd_hda_jack_detect_enable(codec, spec->dock_mic_pin, |
| 1107 | ALC_MIC_EVENT); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1108 | |
| 1109 | spec->auto_mic_valid_imux = 1; |
| 1110 | spec->auto_mic = 1; |
| 1111 | return true; |
| 1112 | } |
| 1113 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1114 | /* |
| 1115 | * Check the availability of auto-mic switch; |
| 1116 | * Set up if really supported |
| 1117 | */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1118 | static void alc_init_auto_mic(struct hda_codec *codec) |
| 1119 | { |
| 1120 | struct alc_spec *spec = codec->spec; |
| 1121 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1122 | hda_nid_t fixed, ext, dock; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1123 | int i; |
| 1124 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 1125 | if (spec->shared_mic_hp) |
| 1126 | return; /* no auto-mic for the shared I/O */ |
| 1127 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1128 | spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1; |
| 1129 | |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1130 | fixed = ext = dock = 0; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 1131 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1132 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1133 | unsigned int defcfg; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1134 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1135 | switch (snd_hda_get_input_pin_attr(defcfg)) { |
| 1136 | case INPUT_PIN_ATTR_INT: |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1137 | if (fixed) |
| 1138 | return; /* already occupied */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1139 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 1140 | return; /* invalid type */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1141 | fixed = nid; |
| 1142 | break; |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1143 | case INPUT_PIN_ATTR_UNUSED: |
| 1144 | return; /* invalid entry */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1145 | case INPUT_PIN_ATTR_DOCK: |
| 1146 | if (dock) |
| 1147 | return; /* already occupied */ |
| 1148 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) |
| 1149 | return; /* invalid type */ |
| 1150 | dock = nid; |
| 1151 | break; |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1152 | default: |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1153 | if (ext) |
| 1154 | return; /* already occupied */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1155 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 1156 | return; /* invalid type */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1157 | ext = nid; |
| 1158 | break; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1159 | } |
| 1160 | } |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1161 | if (!ext && dock) { |
| 1162 | ext = dock; |
| 1163 | dock = 0; |
| 1164 | } |
Takashi Iwai | eaa9b3a | 2010-01-17 13:09:33 +0100 | [diff] [blame] | 1165 | if (!ext || !fixed) |
| 1166 | return; |
Takashi Iwai | e35d9d6 | 2011-05-17 11:28:16 +0200 | [diff] [blame] | 1167 | if (!is_jack_detectable(codec, ext)) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1168 | return; /* no unsol support */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1169 | if (dock && !is_jack_detectable(codec, dock)) |
| 1170 | return; /* no unsol support */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1171 | |
| 1172 | /* check imux indices */ |
| 1173 | spec->ext_mic_pin = ext; |
| 1174 | spec->int_mic_pin = fixed; |
| 1175 | spec->dock_mic_pin = dock; |
| 1176 | |
| 1177 | spec->auto_mic = 1; |
| 1178 | if (!alc_auto_mic_check_imux(codec)) |
| 1179 | return; |
| 1180 | |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1181 | snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n", |
| 1182 | ext, fixed, dock); |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1183 | spec->unsol_event = alc_sku_unsol_event; |
| 1184 | } |
| 1185 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1186 | /* check the availabilities of auto-mute and auto-mic switches */ |
| 1187 | static void alc_auto_check_switches(struct hda_codec *codec) |
| 1188 | { |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 1189 | alc_init_automute(codec); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1190 | alc_init_auto_mic(codec); |
| 1191 | } |
| 1192 | |
| 1193 | /* |
| 1194 | * Realtek SSID verification |
| 1195 | */ |
| 1196 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1197 | /* Could be any non-zero and even value. When used as fixup, tells |
| 1198 | * the driver to ignore any present sku defines. |
| 1199 | */ |
| 1200 | #define ALC_FIXUP_SKU_IGNORE (2) |
| 1201 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1202 | static int alc_auto_parse_customize_define(struct hda_codec *codec) |
| 1203 | { |
| 1204 | unsigned int ass, tmp, i; |
Takashi Iwai | 7fb5622 | 2010-03-22 17:09:47 +0100 | [diff] [blame] | 1205 | unsigned nid = 0; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1206 | struct alc_spec *spec = codec->spec; |
| 1207 | |
Takashi Iwai | b6cbe51 | 2010-07-28 17:43:36 +0200 | [diff] [blame] | 1208 | spec->cdefine.enable_pcbeep = 1; /* assume always enabled */ |
| 1209 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1210 | if (spec->cdefine.fixup) { |
| 1211 | ass = spec->cdefine.sku_cfg; |
| 1212 | if (ass == ALC_FIXUP_SKU_IGNORE) |
| 1213 | return -1; |
| 1214 | goto do_sku; |
| 1215 | } |
| 1216 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1217 | ass = codec->subsystem_id & 0xffff; |
Takashi Iwai | b6cbe51 | 2010-07-28 17:43:36 +0200 | [diff] [blame] | 1218 | if (ass != codec->bus->pci->subsystem_device && (ass & 1)) |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1219 | goto do_sku; |
| 1220 | |
| 1221 | nid = 0x1d; |
| 1222 | if (codec->vendor_id == 0x10ec0260) |
| 1223 | nid = 0x17; |
| 1224 | ass = snd_hda_codec_get_pincfg(codec, nid); |
| 1225 | |
| 1226 | if (!(ass & 1)) { |
| 1227 | printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n", |
| 1228 | codec->chip_name, ass); |
| 1229 | return -1; |
| 1230 | } |
| 1231 | |
| 1232 | /* check sum */ |
| 1233 | tmp = 0; |
| 1234 | for (i = 1; i < 16; i++) { |
| 1235 | if ((ass >> i) & 1) |
| 1236 | tmp++; |
| 1237 | } |
| 1238 | if (((ass >> 16) & 0xf) != tmp) |
| 1239 | return -1; |
| 1240 | |
| 1241 | spec->cdefine.port_connectivity = ass >> 30; |
| 1242 | spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20; |
| 1243 | spec->cdefine.check_sum = (ass >> 16) & 0xf; |
| 1244 | spec->cdefine.customization = ass >> 8; |
| 1245 | do_sku: |
| 1246 | spec->cdefine.sku_cfg = ass; |
| 1247 | spec->cdefine.external_amp = (ass & 0x38) >> 3; |
| 1248 | spec->cdefine.platform_type = (ass & 0x4) >> 2; |
| 1249 | spec->cdefine.swap = (ass & 0x2) >> 1; |
| 1250 | spec->cdefine.override = ass & 0x1; |
| 1251 | |
| 1252 | snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n", |
| 1253 | nid, spec->cdefine.sku_cfg); |
| 1254 | snd_printd("SKU: port_connectivity=0x%x\n", |
| 1255 | spec->cdefine.port_connectivity); |
| 1256 | snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep); |
| 1257 | snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum); |
| 1258 | snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization); |
| 1259 | snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp); |
| 1260 | snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type); |
| 1261 | snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap); |
| 1262 | snd_printd("SKU: override=0x%x\n", spec->cdefine.override); |
| 1263 | |
| 1264 | return 0; |
| 1265 | } |
| 1266 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1267 | /* return true if the given NID is found in the list */ |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1268 | static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 1269 | { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1270 | return find_idx_in_nid_list(nid, list, nums) >= 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1271 | } |
| 1272 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1273 | /* check subsystem ID and set up device-specific initialization; |
| 1274 | * return 1 if initialized, 0 if invalid SSID |
| 1275 | */ |
| 1276 | /* 32-bit subsystem ID for BIOS loading in HD Audio codec. |
| 1277 | * 31 ~ 16 : Manufacture ID |
| 1278 | * 15 ~ 8 : SKU ID |
| 1279 | * 7 ~ 0 : Assembly ID |
| 1280 | * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36 |
| 1281 | */ |
| 1282 | static int alc_subsystem_id(struct hda_codec *codec, |
| 1283 | hda_nid_t porta, hda_nid_t porte, |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1284 | hda_nid_t portd, hda_nid_t porti) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1285 | { |
| 1286 | unsigned int ass, tmp, i; |
| 1287 | unsigned nid; |
| 1288 | struct alc_spec *spec = codec->spec; |
| 1289 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1290 | if (spec->cdefine.fixup) { |
| 1291 | ass = spec->cdefine.sku_cfg; |
| 1292 | if (ass == ALC_FIXUP_SKU_IGNORE) |
| 1293 | return 0; |
| 1294 | goto do_sku; |
| 1295 | } |
| 1296 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1297 | ass = codec->subsystem_id & 0xffff; |
| 1298 | if ((ass != codec->bus->pci->subsystem_device) && (ass & 1)) |
| 1299 | goto do_sku; |
| 1300 | |
| 1301 | /* invalid SSID, check the special NID pin defcfg instead */ |
| 1302 | /* |
Sasha Alexandr | def319f | 2009-06-16 16:00:15 -0400 | [diff] [blame] | 1303 | * 31~30 : port connectivity |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1304 | * 29~21 : reserve |
| 1305 | * 20 : PCBEEP input |
| 1306 | * 19~16 : Check sum (15:1) |
| 1307 | * 15~1 : Custom |
| 1308 | * 0 : override |
| 1309 | */ |
| 1310 | nid = 0x1d; |
| 1311 | if (codec->vendor_id == 0x10ec0260) |
| 1312 | nid = 0x17; |
| 1313 | ass = snd_hda_codec_get_pincfg(codec, nid); |
| 1314 | snd_printd("realtek: No valid SSID, " |
| 1315 | "checking pincfg 0x%08x for NID 0x%x\n", |
Takashi Iwai | cb6605c | 2009-04-28 13:03:19 +0200 | [diff] [blame] | 1316 | ass, nid); |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1317 | if (!(ass & 1)) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1318 | return 0; |
| 1319 | if ((ass >> 30) != 1) /* no physical connection */ |
| 1320 | return 0; |
| 1321 | |
| 1322 | /* check sum */ |
| 1323 | tmp = 0; |
| 1324 | for (i = 1; i < 16; i++) { |
| 1325 | if ((ass >> i) & 1) |
| 1326 | tmp++; |
| 1327 | } |
| 1328 | if (((ass >> 16) & 0xf) != tmp) |
| 1329 | return 0; |
| 1330 | do_sku: |
| 1331 | snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n", |
| 1332 | ass & 0xffff, codec->vendor_id); |
| 1333 | /* |
| 1334 | * 0 : override |
| 1335 | * 1 : Swap Jack |
| 1336 | * 2 : 0 --> Desktop, 1 --> Laptop |
| 1337 | * 3~5 : External Amplifier control |
| 1338 | * 7~6 : Reserved |
| 1339 | */ |
| 1340 | tmp = (ass & 0x38) >> 3; /* external Amp control */ |
| 1341 | switch (tmp) { |
| 1342 | case 1: |
| 1343 | spec->init_amp = ALC_INIT_GPIO1; |
| 1344 | break; |
| 1345 | case 3: |
| 1346 | spec->init_amp = ALC_INIT_GPIO2; |
| 1347 | break; |
| 1348 | case 7: |
| 1349 | spec->init_amp = ALC_INIT_GPIO3; |
| 1350 | break; |
| 1351 | case 5: |
Takashi Iwai | 5a8cfb4 | 2010-11-26 17:11:18 +0100 | [diff] [blame] | 1352 | default: |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1353 | spec->init_amp = ALC_INIT_DEFAULT; |
| 1354 | break; |
| 1355 | } |
| 1356 | |
| 1357 | /* is laptop or Desktop and enable the function "Mute internal speaker |
| 1358 | * when the external headphone out jack is plugged" |
| 1359 | */ |
| 1360 | if (!(ass & 0x8000)) |
| 1361 | return 1; |
| 1362 | /* |
| 1363 | * 10~8 : Jack location |
| 1364 | * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered |
| 1365 | * 14~13: Resvered |
| 1366 | * 15 : 1 --> enable the function "Mute internal speaker |
| 1367 | * when the external headphone out jack is plugged" |
| 1368 | */ |
Takashi Iwai | 5fe6e01 | 2011-09-26 10:41:21 +0200 | [diff] [blame] | 1369 | if (!spec->autocfg.hp_pins[0] && |
| 1370 | !(spec->autocfg.line_out_pins[0] && |
| 1371 | spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) { |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1372 | hda_nid_t nid; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1373 | tmp = (ass >> 11) & 0x3; /* HP to chassis */ |
| 1374 | if (tmp == 0) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1375 | nid = porta; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1376 | else if (tmp == 1) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1377 | nid = porte; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1378 | else if (tmp == 2) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1379 | nid = portd; |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1380 | else if (tmp == 3) |
| 1381 | nid = porti; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1382 | else |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1383 | return 1; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1384 | if (found_in_nid_list(nid, spec->autocfg.line_out_pins, |
| 1385 | spec->autocfg.line_outs)) |
| 1386 | return 1; |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1387 | spec->autocfg.hp_pins[0] = nid; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1388 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1389 | return 1; |
| 1390 | } |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 1391 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 1392 | /* Check the validity of ALC subsystem-id |
| 1393 | * ports contains an array of 4 pin NIDs for port-A, E, D and I */ |
| 1394 | 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] | 1395 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 1396 | 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] | 1397 | struct alc_spec *spec = codec->spec; |
| 1398 | snd_printd("realtek: " |
| 1399 | "Enable default setup for auto mode as fallback\n"); |
| 1400 | spec->init_amp = ALC_INIT_DEFAULT; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1401 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1402 | } |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 1403 | |
Takashi Iwai | 41e41f1 | 2005-06-08 14:48:49 +0200 | [diff] [blame] | 1404 | /* |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1405 | * Fix-up pin default configurations and add default verbs |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1406 | */ |
| 1407 | |
| 1408 | struct alc_pincfg { |
| 1409 | hda_nid_t nid; |
| 1410 | u32 val; |
| 1411 | }; |
| 1412 | |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1413 | struct alc_model_fixup { |
| 1414 | const int id; |
| 1415 | const char *name; |
| 1416 | }; |
| 1417 | |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1418 | struct alc_fixup { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1419 | int type; |
Takashi Iwai | 361fe6e | 2011-01-14 09:55:32 +0100 | [diff] [blame] | 1420 | bool chained; |
| 1421 | int chain_id; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1422 | union { |
| 1423 | unsigned int sku; |
| 1424 | const struct alc_pincfg *pins; |
| 1425 | const struct hda_verb *verbs; |
| 1426 | void (*func)(struct hda_codec *codec, |
| 1427 | const struct alc_fixup *fix, |
| 1428 | int action); |
| 1429 | } v; |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1430 | }; |
| 1431 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1432 | enum { |
| 1433 | ALC_FIXUP_INVALID, |
| 1434 | ALC_FIXUP_SKU, |
| 1435 | ALC_FIXUP_PINS, |
| 1436 | ALC_FIXUP_VERBS, |
| 1437 | ALC_FIXUP_FUNC, |
| 1438 | }; |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1439 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1440 | enum { |
| 1441 | ALC_FIXUP_ACT_PRE_PROBE, |
| 1442 | ALC_FIXUP_ACT_PROBE, |
Takashi Iwai | 5870112 | 2011-01-13 15:41:45 +0100 | [diff] [blame] | 1443 | ALC_FIXUP_ACT_INIT, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1444 | }; |
| 1445 | |
| 1446 | static void alc_apply_fixup(struct hda_codec *codec, int action) |
| 1447 | { |
| 1448 | struct alc_spec *spec = codec->spec; |
| 1449 | int id = spec->fixup_id; |
Takashi Iwai | aa1d0c5 | 2011-01-19 17:27:58 +0100 | [diff] [blame] | 1450 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1451 | const char *modelname = spec->fixup_name; |
Takashi Iwai | aa1d0c5 | 2011-01-19 17:27:58 +0100 | [diff] [blame] | 1452 | #endif |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1453 | int depth = 0; |
| 1454 | |
| 1455 | if (!spec->fixup_list) |
| 1456 | return; |
| 1457 | |
| 1458 | while (id >= 0) { |
| 1459 | const struct alc_fixup *fix = spec->fixup_list + id; |
| 1460 | const struct alc_pincfg *cfg; |
| 1461 | |
| 1462 | switch (fix->type) { |
| 1463 | case ALC_FIXUP_SKU: |
| 1464 | if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku) |
Jesper Juhl | e53de8f | 2011-11-13 23:11:50 +0100 | [diff] [blame] | 1465 | break; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1466 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1467 | "Apply sku override for %s\n", |
| 1468 | codec->chip_name, modelname); |
| 1469 | spec->cdefine.sku_cfg = fix->v.sku; |
| 1470 | spec->cdefine.fixup = 1; |
| 1471 | break; |
| 1472 | case ALC_FIXUP_PINS: |
| 1473 | cfg = fix->v.pins; |
| 1474 | if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg) |
| 1475 | break; |
| 1476 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1477 | "Apply pincfg for %s\n", |
| 1478 | codec->chip_name, modelname); |
| 1479 | for (; cfg->nid; cfg++) |
| 1480 | snd_hda_codec_set_pincfg(codec, cfg->nid, |
| 1481 | cfg->val); |
| 1482 | break; |
| 1483 | case ALC_FIXUP_VERBS: |
| 1484 | if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs) |
| 1485 | break; |
| 1486 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1487 | "Apply fix-verbs for %s\n", |
| 1488 | codec->chip_name, modelname); |
| 1489 | add_verb(codec->spec, fix->v.verbs); |
| 1490 | break; |
| 1491 | case ALC_FIXUP_FUNC: |
| 1492 | if (!fix->v.func) |
| 1493 | break; |
| 1494 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1495 | "Apply fix-func for %s\n", |
| 1496 | codec->chip_name, modelname); |
| 1497 | fix->v.func(codec, fix, action); |
| 1498 | break; |
| 1499 | default: |
| 1500 | snd_printk(KERN_ERR "hda_codec: %s: " |
| 1501 | "Invalid fixup type %d\n", |
| 1502 | codec->chip_name, fix->type); |
| 1503 | break; |
| 1504 | } |
Takashi Iwai | 24af2b1 | 2011-05-02 13:55:36 +0200 | [diff] [blame] | 1505 | if (!fix->chained) |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1506 | break; |
| 1507 | if (++depth > 10) |
| 1508 | break; |
Takashi Iwai | 24af2b1 | 2011-05-02 13:55:36 +0200 | [diff] [blame] | 1509 | id = fix->chain_id; |
Takashi Iwai | 9d57883 | 2010-11-22 13:29:19 +0100 | [diff] [blame] | 1510 | } |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1511 | } |
| 1512 | |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1513 | static void alc_pick_fixup(struct hda_codec *codec, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1514 | const struct alc_model_fixup *models, |
| 1515 | const struct snd_pci_quirk *quirk, |
| 1516 | const struct alc_fixup *fixlist) |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1517 | { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1518 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 596830e | 2011-11-09 15:06:45 +0100 | [diff] [blame] | 1519 | const struct snd_pci_quirk *q; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1520 | int id = -1; |
| 1521 | const char *name = NULL; |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1522 | |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1523 | if (codec->modelname && models) { |
| 1524 | while (models->name) { |
| 1525 | if (!strcmp(codec->modelname, models->name)) { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1526 | id = models->id; |
| 1527 | name = models->name; |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1528 | break; |
| 1529 | } |
| 1530 | models++; |
| 1531 | } |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1532 | } |
| 1533 | if (id < 0) { |
Takashi Iwai | 596830e | 2011-11-09 15:06:45 +0100 | [diff] [blame] | 1534 | q = snd_pci_quirk_lookup(codec->bus->pci, quirk); |
| 1535 | if (q) { |
| 1536 | id = q->value; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1537 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
Takashi Iwai | 596830e | 2011-11-09 15:06:45 +0100 | [diff] [blame] | 1538 | name = q->name; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1539 | #endif |
| 1540 | } |
| 1541 | } |
Takashi Iwai | 596830e | 2011-11-09 15:06:45 +0100 | [diff] [blame] | 1542 | if (id < 0) { |
| 1543 | for (q = quirk; q->subvendor; q++) { |
| 1544 | unsigned int vendorid = |
| 1545 | q->subdevice | (q->subvendor << 16); |
| 1546 | if (vendorid == codec->subsystem_id) { |
| 1547 | id = q->value; |
| 1548 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
| 1549 | name = q->name; |
| 1550 | #endif |
| 1551 | break; |
| 1552 | } |
| 1553 | } |
| 1554 | } |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1555 | |
| 1556 | spec->fixup_id = id; |
| 1557 | if (id >= 0) { |
| 1558 | spec->fixup_list = fixlist; |
| 1559 | spec->fixup_name = name; |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1560 | } |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1561 | } |
| 1562 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1563 | /* |
| 1564 | * COEF access helper functions |
| 1565 | */ |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 1566 | static int alc_read_coef_idx(struct hda_codec *codec, |
| 1567 | unsigned int coef_idx) |
| 1568 | { |
| 1569 | unsigned int val; |
| 1570 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, |
| 1571 | coef_idx); |
| 1572 | val = snd_hda_codec_read(codec, 0x20, 0, |
| 1573 | AC_VERB_GET_PROC_COEF, 0); |
| 1574 | return val; |
| 1575 | } |
| 1576 | |
Kailang Yang | 977ddd6 | 2010-09-15 10:02:29 +0200 | [diff] [blame] | 1577 | static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx, |
| 1578 | unsigned int coef_val) |
| 1579 | { |
| 1580 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, |
| 1581 | coef_idx); |
| 1582 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, |
| 1583 | coef_val); |
| 1584 | } |
| 1585 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 1586 | /* a special bypass for COEF 0; read the cached value at the second time */ |
| 1587 | static unsigned int alc_get_coef0(struct hda_codec *codec) |
| 1588 | { |
| 1589 | struct alc_spec *spec = codec->spec; |
| 1590 | if (!spec->coef0) |
| 1591 | spec->coef0 = alc_read_coef_idx(codec, 0); |
| 1592 | return spec->coef0; |
| 1593 | } |
| 1594 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1595 | /* |
| 1596 | * Digital I/O handling |
| 1597 | */ |
| 1598 | |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1599 | /* set right pin controls for digital I/O */ |
| 1600 | static void alc_auto_init_digital(struct hda_codec *codec) |
| 1601 | { |
| 1602 | struct alc_spec *spec = codec->spec; |
| 1603 | int i; |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 1604 | hda_nid_t pin, dac; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1605 | |
| 1606 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
| 1607 | pin = spec->autocfg.dig_out_pins[i]; |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 1608 | if (!pin) |
| 1609 | continue; |
| 1610 | snd_hda_codec_write(codec, pin, 0, |
| 1611 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); |
| 1612 | if (!i) |
| 1613 | dac = spec->multiout.dig_out_nid; |
| 1614 | else |
| 1615 | dac = spec->slave_dig_outs[i - 1]; |
| 1616 | if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP)) |
| 1617 | continue; |
| 1618 | snd_hda_codec_write(codec, dac, 0, |
| 1619 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 1620 | AMP_OUT_UNMUTE); |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1621 | } |
| 1622 | pin = spec->autocfg.dig_in_pin; |
| 1623 | if (pin) |
| 1624 | snd_hda_codec_write(codec, pin, 0, |
| 1625 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1626 | PIN_IN); |
| 1627 | } |
| 1628 | |
| 1629 | /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */ |
| 1630 | static void alc_auto_parse_digital(struct hda_codec *codec) |
| 1631 | { |
| 1632 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1633 | int i, err, nums; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1634 | hda_nid_t dig_nid; |
| 1635 | |
| 1636 | /* support multiple SPDIFs; the secondary is set up as a slave */ |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1637 | nums = 0; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1638 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1639 | hda_nid_t conn[4]; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1640 | err = snd_hda_get_connections(codec, |
| 1641 | spec->autocfg.dig_out_pins[i], |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1642 | conn, ARRAY_SIZE(conn)); |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1643 | if (err <= 0) |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1644 | continue; |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1645 | dig_nid = conn[0]; /* assume the first element is audio-out */ |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1646 | if (!nums) { |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1647 | spec->multiout.dig_out_nid = dig_nid; |
| 1648 | spec->dig_out_type = spec->autocfg.dig_out_type[0]; |
| 1649 | } else { |
| 1650 | spec->multiout.slave_dig_outs = spec->slave_dig_outs; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1651 | if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1) |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1652 | break; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1653 | spec->slave_dig_outs[nums - 1] = dig_nid; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1654 | } |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1655 | nums++; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | if (spec->autocfg.dig_in_pin) { |
Takashi Iwai | 01fdf18 | 2010-09-24 09:09:42 +0200 | [diff] [blame] | 1659 | dig_nid = codec->start_nid; |
| 1660 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { |
| 1661 | unsigned int wcaps = get_wcaps(codec, dig_nid); |
| 1662 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
| 1663 | continue; |
| 1664 | if (!(wcaps & AC_WCAP_DIGITAL)) |
| 1665 | continue; |
| 1666 | if (!(wcaps & AC_WCAP_CONN_LIST)) |
| 1667 | continue; |
| 1668 | err = get_connection_index(codec, dig_nid, |
| 1669 | spec->autocfg.dig_in_pin); |
| 1670 | if (err >= 0) { |
| 1671 | spec->dig_in_nid = dig_nid; |
| 1672 | break; |
| 1673 | } |
| 1674 | } |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1675 | } |
| 1676 | } |
| 1677 | |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1678 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1679 | * capture mixer elements |
Vincent Petry | ef8ef5f | 2008-11-23 11:31:41 +0800 | [diff] [blame] | 1680 | */ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1681 | static int alc_cap_vol_info(struct snd_kcontrol *kcontrol, |
| 1682 | struct snd_ctl_elem_info *uinfo) |
| 1683 | { |
| 1684 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1685 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1686 | unsigned long val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1687 | int err; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1688 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1689 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1690 | if (spec->vol_in_capsrc) |
| 1691 | val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT); |
| 1692 | else |
| 1693 | val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT); |
| 1694 | kcontrol->private_value = val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1695 | err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo); |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1696 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1697 | return err; |
| 1698 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1700 | static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, |
| 1701 | unsigned int size, unsigned int __user *tlv) |
| 1702 | { |
| 1703 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1704 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1705 | unsigned long val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1706 | int err; |
| 1707 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1708 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1709 | if (spec->vol_in_capsrc) |
| 1710 | val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT); |
| 1711 | else |
| 1712 | val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT); |
| 1713 | kcontrol->private_value = val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1714 | err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv); |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1715 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1716 | return err; |
| 1717 | } |
| 1718 | |
| 1719 | typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol, |
| 1720 | struct snd_ctl_elem_value *ucontrol); |
| 1721 | |
| 1722 | static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol, |
| 1723 | struct snd_ctl_elem_value *ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1724 | getput_call_t func, bool check_adc_switch) |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1725 | { |
| 1726 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1727 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1728 | int i, err = 0; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1729 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1730 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1731 | if (check_adc_switch && spec->dyn_adc_switch) { |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1732 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 1733 | kcontrol->private_value = |
| 1734 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], |
| 1735 | 3, 0, HDA_INPUT); |
| 1736 | err = func(kcontrol, ucontrol); |
| 1737 | if (err < 0) |
| 1738 | goto error; |
| 1739 | } |
| 1740 | } else { |
| 1741 | i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1742 | if (spec->vol_in_capsrc) |
| 1743 | kcontrol->private_value = |
| 1744 | HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i], |
| 1745 | 3, 0, HDA_OUTPUT); |
| 1746 | else |
| 1747 | kcontrol->private_value = |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1748 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], |
| 1749 | 3, 0, HDA_INPUT); |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1750 | err = func(kcontrol, ucontrol); |
| 1751 | } |
| 1752 | error: |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1753 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1754 | return err; |
| 1755 | } |
| 1756 | |
| 1757 | static int alc_cap_vol_get(struct snd_kcontrol *kcontrol, |
| 1758 | struct snd_ctl_elem_value *ucontrol) |
| 1759 | { |
| 1760 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1761 | snd_hda_mixer_amp_volume_get, false); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | static int alc_cap_vol_put(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_put, true); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | /* capture mixer elements */ |
| 1772 | #define alc_cap_sw_info snd_ctl_boolean_stereo_info |
| 1773 | |
| 1774 | static int alc_cap_sw_get(struct snd_kcontrol *kcontrol, |
| 1775 | struct snd_ctl_elem_value *ucontrol) |
| 1776 | { |
| 1777 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1778 | snd_hda_mixer_amp_switch_get, false); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | static int alc_cap_sw_put(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_put, true); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1786 | } |
| 1787 | |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1788 | #define _DEFINE_CAPMIX(num) \ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1789 | { \ |
| 1790 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1791 | .name = "Capture Switch", \ |
| 1792 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \ |
| 1793 | .count = num, \ |
| 1794 | .info = alc_cap_sw_info, \ |
| 1795 | .get = alc_cap_sw_get, \ |
| 1796 | .put = alc_cap_sw_put, \ |
| 1797 | }, \ |
| 1798 | { \ |
| 1799 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1800 | .name = "Capture Volume", \ |
| 1801 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \ |
| 1802 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ |
| 1803 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \ |
| 1804 | .count = num, \ |
| 1805 | .info = alc_cap_vol_info, \ |
| 1806 | .get = alc_cap_vol_get, \ |
| 1807 | .put = alc_cap_vol_put, \ |
| 1808 | .tlv = { .c = alc_cap_vol_tlv }, \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | #define _DEFINE_CAPSRC(num) \ |
Takashi Iwai | 3c3e989 | 2008-10-31 17:48:56 +0100 | [diff] [blame] | 1812 | { \ |
| 1813 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1814 | /* .name = "Capture Source", */ \ |
| 1815 | .name = "Input Source", \ |
| 1816 | .count = num, \ |
| 1817 | .info = alc_mux_enum_info, \ |
| 1818 | .get = alc_mux_enum_get, \ |
| 1819 | .put = alc_mux_enum_put, \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | #define DEFINE_CAPMIX(num) \ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1823 | static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1824 | _DEFINE_CAPMIX(num), \ |
| 1825 | _DEFINE_CAPSRC(num), \ |
| 1826 | { } /* end */ \ |
| 1827 | } |
| 1828 | |
| 1829 | #define DEFINE_CAPMIX_NOSRC(num) \ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1830 | static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1831 | _DEFINE_CAPMIX(num), \ |
| 1832 | { } /* end */ \ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | /* up to three ADCs */ |
| 1836 | DEFINE_CAPMIX(1); |
| 1837 | DEFINE_CAPMIX(2); |
| 1838 | DEFINE_CAPMIX(3); |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1839 | DEFINE_CAPMIX_NOSRC(1); |
| 1840 | DEFINE_CAPMIX_NOSRC(2); |
| 1841 | DEFINE_CAPMIX_NOSRC(3); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1842 | |
| 1843 | /* |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1844 | * virtual master controls |
| 1845 | */ |
| 1846 | |
| 1847 | /* |
| 1848 | * slave controls for virtual master |
| 1849 | */ |
Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 1850 | static const char * const alc_slave_pfxs[] = { |
| 1851 | "Front", "Surround", "Center", "LFE", "Side", |
| 1852 | "Headphone", "Speaker", "Mono", "Line-Out", |
| 1853 | "CLFE", "Bass Speaker", "PCM", |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1854 | NULL, |
| 1855 | }; |
| 1856 | |
| 1857 | /* |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1858 | * build control elements |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | */ |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1860 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1861 | #define NID_MAPPING (-1) |
| 1862 | |
| 1863 | #define SUBDEV_SPEAKER_ (0 << 6) |
| 1864 | #define SUBDEV_HP_ (1 << 6) |
| 1865 | #define SUBDEV_LINE_ (2 << 6) |
| 1866 | #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f)) |
| 1867 | #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f)) |
| 1868 | #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f)) |
| 1869 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1870 | static void alc_free_kctls(struct hda_codec *codec); |
| 1871 | |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1872 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1873 | /* additional beep mixers; the actual parameters are overwritten at build */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1874 | static const struct snd_kcontrol_new alc_beep_mixer[] = { |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1875 | HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT), |
Jaroslav Kysela | 123c07a | 2009-10-21 14:48:23 +0200 | [diff] [blame] | 1876 | HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT), |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1877 | { } /* end */ |
| 1878 | }; |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1879 | #endif |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1880 | |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 1881 | static int __alc_build_controls(struct hda_codec *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | { |
| 1883 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2f44f84 | 2010-06-22 11:12:32 +0200 | [diff] [blame] | 1884 | struct snd_kcontrol *kctl = NULL; |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1885 | const struct snd_kcontrol_new *knew; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1886 | int i, j, err; |
| 1887 | unsigned int u; |
| 1888 | hda_nid_t nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | |
| 1890 | for (i = 0; i < spec->num_mixers; i++) { |
| 1891 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 1892 | if (err < 0) |
| 1893 | return err; |
| 1894 | } |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1895 | if (spec->cap_mixer) { |
| 1896 | err = snd_hda_add_new_ctls(codec, spec->cap_mixer); |
| 1897 | if (err < 0) |
| 1898 | return err; |
| 1899 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | if (spec->multiout.dig_out_nid) { |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 1901 | err = snd_hda_create_spdif_out_ctls(codec, |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 1902 | spec->multiout.dig_out_nid, |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 1903 | spec->multiout.dig_out_nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | if (err < 0) |
| 1905 | return err; |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1906 | if (!spec->no_analog) { |
| 1907 | err = snd_hda_create_spdif_share_sw(codec, |
| 1908 | &spec->multiout); |
| 1909 | if (err < 0) |
| 1910 | return err; |
| 1911 | spec->multiout.share_spdif = 1; |
| 1912 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | } |
| 1914 | if (spec->dig_in_nid) { |
| 1915 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); |
| 1916 | if (err < 0) |
| 1917 | return err; |
| 1918 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1919 | |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1920 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1921 | /* create beep controls if needed */ |
| 1922 | if (spec->beep_amp) { |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1923 | const struct snd_kcontrol_new *knew; |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1924 | for (knew = alc_beep_mixer; knew->name; knew++) { |
| 1925 | struct snd_kcontrol *kctl; |
| 1926 | kctl = snd_ctl_new1(knew, codec); |
| 1927 | if (!kctl) |
| 1928 | return -ENOMEM; |
| 1929 | kctl->private_value = spec->beep_amp; |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 1930 | err = snd_hda_ctl_add(codec, 0, kctl); |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1931 | if (err < 0) |
| 1932 | return err; |
| 1933 | } |
| 1934 | } |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1935 | #endif |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1936 | |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1937 | /* if we have no master control, let's create it */ |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1938 | if (!spec->no_analog && |
| 1939 | !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1940 | unsigned int vmaster_tlv[4]; |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1941 | snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1942 | HDA_OUTPUT, vmaster_tlv); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1943 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", |
Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 1944 | vmaster_tlv, alc_slave_pfxs, |
| 1945 | "Playback Volume"); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1946 | if (err < 0) |
| 1947 | return err; |
| 1948 | } |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1949 | if (!spec->no_analog && |
| 1950 | !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1951 | err = snd_hda_add_vmaster(codec, "Master Playback Switch", |
Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 1952 | NULL, alc_slave_pfxs, |
| 1953 | "Playback Switch"); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1954 | if (err < 0) |
| 1955 | return err; |
| 1956 | } |
| 1957 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1958 | /* assign Capture Source enums to NID */ |
Takashi Iwai | fbe618f | 2010-06-11 11:24:58 +0200 | [diff] [blame] | 1959 | if (spec->capsrc_nids || spec->adc_nids) { |
| 1960 | kctl = snd_hda_find_mixer_ctl(codec, "Capture Source"); |
| 1961 | if (!kctl) |
| 1962 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); |
| 1963 | for (i = 0; kctl && i < kctl->count; i++) { |
Takashi Iwai | 6107159 | 2011-11-23 07:52:15 +0100 | [diff] [blame] | 1964 | err = snd_hda_add_nid(codec, kctl, i, |
| 1965 | get_capsrc(spec, i)); |
Takashi Iwai | fbe618f | 2010-06-11 11:24:58 +0200 | [diff] [blame] | 1966 | if (err < 0) |
| 1967 | return err; |
| 1968 | } |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1969 | } |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 1970 | if (spec->cap_mixer && spec->adc_nids) { |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1971 | const char *kname = kctl ? kctl->id.name : NULL; |
| 1972 | for (knew = spec->cap_mixer; knew->name; knew++) { |
| 1973 | if (kname && strcmp(knew->name, kname) == 0) |
| 1974 | continue; |
| 1975 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 1976 | for (i = 0; kctl && i < kctl->count; i++) { |
| 1977 | err = snd_hda_add_nid(codec, kctl, i, |
| 1978 | spec->adc_nids[i]); |
| 1979 | if (err < 0) |
| 1980 | return err; |
| 1981 | } |
| 1982 | } |
| 1983 | } |
| 1984 | |
| 1985 | /* other nid->control mapping */ |
| 1986 | for (i = 0; i < spec->num_mixers; i++) { |
| 1987 | for (knew = spec->mixers[i]; knew->name; knew++) { |
| 1988 | if (knew->iface != NID_MAPPING) |
| 1989 | continue; |
| 1990 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 1991 | if (kctl == NULL) |
| 1992 | continue; |
| 1993 | u = knew->subdevice; |
| 1994 | for (j = 0; j < 4; j++, u >>= 8) { |
| 1995 | nid = u & 0x3f; |
| 1996 | if (nid == 0) |
| 1997 | continue; |
| 1998 | switch (u & 0xc0) { |
| 1999 | case SUBDEV_SPEAKER_: |
| 2000 | nid = spec->autocfg.speaker_pins[nid]; |
| 2001 | break; |
| 2002 | case SUBDEV_LINE_: |
| 2003 | nid = spec->autocfg.line_out_pins[nid]; |
| 2004 | break; |
| 2005 | case SUBDEV_HP_: |
| 2006 | nid = spec->autocfg.hp_pins[nid]; |
| 2007 | break; |
| 2008 | default: |
| 2009 | continue; |
| 2010 | } |
| 2011 | err = snd_hda_add_nid(codec, kctl, 0, nid); |
| 2012 | if (err < 0) |
| 2013 | return err; |
| 2014 | } |
| 2015 | u = knew->private_value; |
| 2016 | for (j = 0; j < 4; j++, u >>= 8) { |
| 2017 | nid = u & 0xff; |
| 2018 | if (nid == 0) |
| 2019 | continue; |
| 2020 | err = snd_hda_add_nid(codec, kctl, 0, nid); |
| 2021 | if (err < 0) |
| 2022 | return err; |
| 2023 | } |
| 2024 | } |
| 2025 | } |
Takashi Iwai | bae84e7 | 2010-03-22 08:30:20 +0100 | [diff] [blame] | 2026 | |
| 2027 | alc_free_kctls(codec); /* no longer needed */ |
| 2028 | |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 2029 | return 0; |
| 2030 | } |
| 2031 | |
| 2032 | static int alc_build_controls(struct hda_codec *codec) |
| 2033 | { |
| 2034 | struct alc_spec *spec = codec->spec; |
| 2035 | int err = __alc_build_controls(codec); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 2036 | if (err < 0) |
| 2037 | return err; |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 2038 | return snd_hda_jack_add_kctls(codec, &spec->autocfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | /* |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2043 | * Common callbacks |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2044 | */ |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 2045 | |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 2046 | static void alc_init_special_input_src(struct hda_codec *codec); |
| 2047 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | static int alc_init(struct hda_codec *codec) |
| 2049 | { |
| 2050 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2051 | unsigned int i; |
| 2052 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 2053 | alc_fix_pll(codec); |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 2054 | alc_auto_init_amp(codec, spec->init_amp); |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 2055 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2056 | for (i = 0; i < spec->num_init_verbs; i++) |
| 2057 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 2058 | alc_init_special_input_src(codec); |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2059 | |
| 2060 | if (spec->init_hook) |
| 2061 | spec->init_hook(codec); |
| 2062 | |
Takashi Iwai | 5870112 | 2011-01-13 15:41:45 +0100 | [diff] [blame] | 2063 | alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT); |
| 2064 | |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 2065 | snd_hda_jack_report_sync(codec); |
| 2066 | |
Takashi Iwai | 9e5341b | 2010-09-21 09:57:06 +0200 | [diff] [blame] | 2067 | hda_call_check_power_status(codec, 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | return 0; |
| 2069 | } |
| 2070 | |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2071 | static void alc_unsol_event(struct hda_codec *codec, unsigned int res) |
| 2072 | { |
| 2073 | struct alc_spec *spec = codec->spec; |
| 2074 | |
| 2075 | if (spec->unsol_event) |
| 2076 | spec->unsol_event(codec, res); |
| 2077 | } |
| 2078 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2079 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2080 | static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 2081 | { |
| 2082 | struct alc_spec *spec = codec->spec; |
| 2083 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); |
| 2084 | } |
| 2085 | #endif |
| 2086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | /* |
| 2088 | * Analog playback callbacks |
| 2089 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2090 | static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2092 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | { |
| 2094 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 2095 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 2096 | hinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | } |
| 2098 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2099 | static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | struct hda_codec *codec, |
| 2101 | unsigned int stream_tag, |
| 2102 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2103 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | { |
| 2105 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 2106 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, |
| 2107 | stream_tag, format, substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2110 | static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2112 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | { |
| 2114 | struct alc_spec *spec = codec->spec; |
| 2115 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
| 2116 | } |
| 2117 | |
| 2118 | /* |
| 2119 | * Digital out |
| 2120 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2121 | static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2123 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | { |
| 2125 | struct alc_spec *spec = codec->spec; |
| 2126 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 2127 | } |
| 2128 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2129 | static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 2130 | struct hda_codec *codec, |
| 2131 | unsigned int stream_tag, |
| 2132 | unsigned int format, |
| 2133 | struct snd_pcm_substream *substream) |
| 2134 | { |
| 2135 | struct alc_spec *spec = codec->spec; |
| 2136 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 2137 | stream_tag, format, substream); |
| 2138 | } |
| 2139 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2140 | static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 9b5f12e | 2009-02-13 11:47:37 +0100 | [diff] [blame] | 2141 | struct hda_codec *codec, |
| 2142 | struct snd_pcm_substream *substream) |
| 2143 | { |
| 2144 | struct alc_spec *spec = codec->spec; |
| 2145 | return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
| 2146 | } |
| 2147 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2148 | static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2150 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | { |
| 2152 | struct alc_spec *spec = codec->spec; |
| 2153 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 2154 | } |
| 2155 | |
| 2156 | /* |
| 2157 | * Analog capture |
| 2158 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2159 | static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | struct hda_codec *codec, |
| 2161 | unsigned int stream_tag, |
| 2162 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2163 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | { |
| 2165 | struct alc_spec *spec = codec->spec; |
| 2166 | |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2167 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | stream_tag, 0, format); |
| 2169 | return 0; |
| 2170 | } |
| 2171 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2172 | static int alc_alt_capture_pcm_cleanup(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 | |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 2178 | snd_hda_codec_cleanup_stream(codec, |
| 2179 | spec->adc_nids[substream->number + 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | return 0; |
| 2181 | } |
| 2182 | |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2183 | /* analog capture with dynamic dual-adc changes */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2184 | static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2185 | struct hda_codec *codec, |
| 2186 | unsigned int stream_tag, |
| 2187 | unsigned int format, |
| 2188 | struct snd_pcm_substream *substream) |
| 2189 | { |
| 2190 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2191 | 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] | 2192 | spec->cur_adc_stream_tag = stream_tag; |
| 2193 | spec->cur_adc_format = format; |
| 2194 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); |
| 2195 | return 0; |
| 2196 | } |
| 2197 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2198 | static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2199 | struct hda_codec *codec, |
| 2200 | struct snd_pcm_substream *substream) |
| 2201 | { |
| 2202 | struct alc_spec *spec = codec->spec; |
| 2203 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
| 2204 | spec->cur_adc = 0; |
| 2205 | return 0; |
| 2206 | } |
| 2207 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2208 | static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = { |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2209 | .substreams = 1, |
| 2210 | .channels_min = 2, |
| 2211 | .channels_max = 2, |
| 2212 | .nid = 0, /* fill later */ |
| 2213 | .ops = { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2214 | .prepare = dyn_adc_capture_pcm_prepare, |
| 2215 | .cleanup = dyn_adc_capture_pcm_cleanup |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2216 | }, |
| 2217 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | |
| 2219 | /* |
| 2220 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2221 | static const struct hda_pcm_stream alc_pcm_analog_playback = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | .substreams = 1, |
| 2223 | .channels_min = 2, |
| 2224 | .channels_max = 8, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2225 | /* NID is set in alc_build_pcms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2227 | .open = alc_playback_pcm_open, |
| 2228 | .prepare = alc_playback_pcm_prepare, |
| 2229 | .cleanup = alc_playback_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | }, |
| 2231 | }; |
| 2232 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2233 | static const struct hda_pcm_stream alc_pcm_analog_capture = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2234 | .substreams = 1, |
| 2235 | .channels_min = 2, |
| 2236 | .channels_max = 2, |
| 2237 | /* NID is set in alc_build_pcms */ |
| 2238 | }; |
| 2239 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2240 | static const struct hda_pcm_stream alc_pcm_analog_alt_playback = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2241 | .substreams = 1, |
| 2242 | .channels_min = 2, |
| 2243 | .channels_max = 2, |
| 2244 | /* NID is set in alc_build_pcms */ |
| 2245 | }; |
| 2246 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2247 | static const struct hda_pcm_stream alc_pcm_analog_alt_capture = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2248 | .substreams = 2, /* can be overridden */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | .channels_min = 2, |
| 2250 | .channels_max = 2, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2251 | /* NID is set in alc_build_pcms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2253 | .prepare = alc_alt_capture_pcm_prepare, |
| 2254 | .cleanup = alc_alt_capture_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | }, |
| 2256 | }; |
| 2257 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2258 | static const struct hda_pcm_stream alc_pcm_digital_playback = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | .substreams = 1, |
| 2260 | .channels_min = 2, |
| 2261 | .channels_max = 2, |
| 2262 | /* NID is set in alc_build_pcms */ |
| 2263 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2264 | .open = alc_dig_playback_pcm_open, |
| 2265 | .close = alc_dig_playback_pcm_close, |
| 2266 | .prepare = alc_dig_playback_pcm_prepare, |
| 2267 | .cleanup = alc_dig_playback_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | }, |
| 2269 | }; |
| 2270 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2271 | static const struct hda_pcm_stream alc_pcm_digital_capture = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | .substreams = 1, |
| 2273 | .channels_min = 2, |
| 2274 | .channels_max = 2, |
| 2275 | /* NID is set in alc_build_pcms */ |
| 2276 | }; |
| 2277 | |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 2278 | /* 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] | 2279 | static const struct hda_pcm_stream alc_pcm_null_stream = { |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 2280 | .substreams = 0, |
| 2281 | .channels_min = 0, |
| 2282 | .channels_max = 0, |
| 2283 | }; |
| 2284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | static int alc_build_pcms(struct hda_codec *codec) |
| 2286 | { |
| 2287 | struct alc_spec *spec = codec->spec; |
| 2288 | struct hda_pcm *info = spec->pcm_rec; |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2289 | const struct hda_pcm_stream *p; |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2290 | bool have_multi_adcs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | int i; |
| 2292 | |
| 2293 | codec->num_pcms = 1; |
| 2294 | codec->pcm_info = info; |
| 2295 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2296 | if (spec->no_analog) |
| 2297 | goto skip_analog; |
| 2298 | |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 2299 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), |
| 2300 | "%s Analog", codec->chip_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | info->name = spec->stream_name_analog; |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 2302 | |
Takashi Iwai | eedec3d | 2012-02-06 10:24:04 +0100 | [diff] [blame] | 2303 | if (spec->multiout.num_dacs > 0) { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2304 | p = spec->stream_analog_playback; |
| 2305 | if (!p) |
| 2306 | p = &alc_pcm_analog_playback; |
| 2307 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2308 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; |
| 2309 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2310 | if (spec->adc_nids) { |
| 2311 | p = spec->stream_analog_capture; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2312 | if (!p) { |
| 2313 | if (spec->dyn_adc_switch) |
| 2314 | p = &dyn_adc_pcm_analog_capture; |
| 2315 | else |
| 2316 | p = &alc_pcm_analog_capture; |
| 2317 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2318 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2319 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 2320 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2322 | if (spec->channel_mode) { |
| 2323 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0; |
| 2324 | for (i = 0; i < spec->num_channel_mode; i++) { |
| 2325 | if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) { |
| 2326 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels; |
| 2327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | } |
| 2329 | } |
| 2330 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2331 | skip_analog: |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2332 | /* SPDIF for stream index #1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 2334 | snprintf(spec->stream_name_digital, |
| 2335 | sizeof(spec->stream_name_digital), |
| 2336 | "%s Digital", codec->chip_name); |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2337 | codec->num_pcms = 2; |
Wu Fengguang | b25c9da | 2009-02-06 15:02:27 +0800 | [diff] [blame] | 2338 | codec->slave_dig_outs = spec->multiout.slave_dig_outs; |
Takashi Iwai | c06134d | 2006-10-11 18:49:13 +0200 | [diff] [blame] | 2339 | info = spec->pcm_rec + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | info->name = spec->stream_name_digital; |
Takashi Iwai | 8c44198 | 2009-01-20 18:30:20 +0100 | [diff] [blame] | 2341 | if (spec->dig_out_type) |
| 2342 | info->pcm_type = spec->dig_out_type; |
| 2343 | else |
| 2344 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2345 | if (spec->multiout.dig_out_nid) { |
| 2346 | p = spec->stream_digital_playback; |
| 2347 | if (!p) |
| 2348 | p = &alc_pcm_digital_playback; |
| 2349 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; |
| 2351 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2352 | if (spec->dig_in_nid) { |
| 2353 | p = spec->stream_digital_capture; |
| 2354 | if (!p) |
| 2355 | p = &alc_pcm_digital_capture; |
| 2356 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; |
| 2358 | } |
Takashi Iwai | 963f803 | 2008-08-11 10:04:40 +0200 | [diff] [blame] | 2359 | /* FIXME: do we need this for all Realtek codec models? */ |
| 2360 | codec->spdif_status_reset = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | } |
| 2362 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2363 | if (spec->no_analog) |
| 2364 | return 0; |
| 2365 | |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2366 | /* If the use of more than one ADC is requested for the current |
| 2367 | * model, configure a second analog capture-only PCM. |
| 2368 | */ |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2369 | have_multi_adcs = (spec->num_adc_nids > 1) && |
| 2370 | !spec->dyn_adc_switch && !spec->auto_mic && |
| 2371 | (!spec->input_mux || spec->input_mux->num_items > 1); |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2372 | /* Additional Analaog capture for index #2 */ |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2373 | if (spec->alt_dac_nid || have_multi_adcs) { |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2374 | codec->num_pcms = 3; |
Takashi Iwai | c06134d | 2006-10-11 18:49:13 +0200 | [diff] [blame] | 2375 | info = spec->pcm_rec + 2; |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2376 | info->name = spec->stream_name_analog; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2377 | if (spec->alt_dac_nid) { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2378 | p = spec->stream_analog_alt_playback; |
| 2379 | if (!p) |
| 2380 | p = &alc_pcm_analog_alt_playback; |
| 2381 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2382 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 2383 | spec->alt_dac_nid; |
| 2384 | } else { |
| 2385 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 2386 | alc_pcm_null_stream; |
| 2387 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0; |
| 2388 | } |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2389 | if (have_multi_adcs) { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2390 | p = spec->stream_analog_alt_capture; |
| 2391 | if (!p) |
| 2392 | p = &alc_pcm_analog_alt_capture; |
| 2393 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2394 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 2395 | spec->adc_nids[1]; |
| 2396 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = |
| 2397 | spec->num_adc_nids - 1; |
| 2398 | } else { |
| 2399 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 2400 | alc_pcm_null_stream; |
| 2401 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0; |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2402 | } |
| 2403 | } |
| 2404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | return 0; |
| 2406 | } |
| 2407 | |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2408 | static inline void alc_shutup(struct hda_codec *codec) |
| 2409 | { |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 2410 | struct alc_spec *spec = codec->spec; |
| 2411 | |
| 2412 | if (spec && spec->shutup) |
| 2413 | spec->shutup(codec); |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2414 | snd_hda_shutup_pins(codec); |
| 2415 | } |
| 2416 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2417 | static void alc_free_kctls(struct hda_codec *codec) |
| 2418 | { |
| 2419 | struct alc_spec *spec = codec->spec; |
| 2420 | |
| 2421 | if (spec->kctls.list) { |
| 2422 | struct snd_kcontrol_new *kctl = spec->kctls.list; |
| 2423 | int i; |
| 2424 | for (i = 0; i < spec->kctls.used; i++) |
| 2425 | kfree(kctl[i].name); |
| 2426 | } |
| 2427 | snd_array_free(&spec->kctls); |
| 2428 | } |
| 2429 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2430 | static void alc_free_bind_ctls(struct hda_codec *codec) |
| 2431 | { |
| 2432 | struct alc_spec *spec = codec->spec; |
| 2433 | if (spec->bind_ctls.list) { |
| 2434 | struct hda_bind_ctls **ctl = spec->bind_ctls.list; |
| 2435 | int i; |
| 2436 | for (i = 0; i < spec->bind_ctls.used; i++) |
| 2437 | kfree(ctl[i]); |
| 2438 | } |
| 2439 | snd_array_free(&spec->bind_ctls); |
| 2440 | } |
| 2441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | static void alc_free(struct hda_codec *codec) |
| 2443 | { |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2444 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2445 | |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2446 | if (!spec) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2447 | return; |
| 2448 | |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2449 | alc_shutup(codec); |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2450 | alc_free_kctls(codec); |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2451 | alc_free_bind_ctls(codec); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2452 | kfree(spec); |
Kusanagi Kouichi | 680cd53 | 2009-02-05 00:00:58 +0900 | [diff] [blame] | 2453 | snd_hda_detach_beep_device(codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | } |
| 2455 | |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2456 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2457 | static void alc_power_eapd(struct hda_codec *codec) |
| 2458 | { |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 2459 | alc_auto_setup_eapd(codec, false); |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2460 | } |
| 2461 | |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2462 | static int alc_suspend(struct hda_codec *codec, pm_message_t state) |
| 2463 | { |
| 2464 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2465 | alc_shutup(codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2466 | if (spec && spec->power_hook) |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2467 | spec->power_hook(codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2468 | return 0; |
| 2469 | } |
| 2470 | #endif |
| 2471 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 2472 | #ifdef CONFIG_PM |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2473 | static int alc_resume(struct hda_codec *codec) |
| 2474 | { |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 2475 | msleep(150); /* to avoid pop noise */ |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2476 | codec->patch_ops.init(codec); |
| 2477 | snd_hda_codec_resume_amp(codec); |
| 2478 | snd_hda_codec_resume_cache(codec); |
Takashi Iwai | 9e5341b | 2010-09-21 09:57:06 +0200 | [diff] [blame] | 2479 | hda_call_check_power_status(codec, 0x01); |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2480 | return 0; |
| 2481 | } |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2482 | #endif |
| 2483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | /* |
| 2485 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 2486 | static const struct hda_codec_ops alc_patch_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | .build_controls = alc_build_controls, |
| 2488 | .build_pcms = alc_build_pcms, |
| 2489 | .init = alc_init, |
| 2490 | .free = alc_free, |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2491 | .unsol_event = alc_unsol_event, |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 2492 | #ifdef CONFIG_PM |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2493 | .resume = alc_resume, |
| 2494 | #endif |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2495 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2496 | .suspend = alc_suspend, |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2497 | .check_power_status = alc_check_power_status, |
| 2498 | #endif |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2499 | .reboot_notify = alc_shutup, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | }; |
| 2501 | |
Kailang Yang | c027ddc | 2010-03-19 11:33:06 +0100 | [diff] [blame] | 2502 | /* replace the codec chip_name with the given string */ |
| 2503 | static int alc_codec_rename(struct hda_codec *codec, const char *name) |
| 2504 | { |
| 2505 | kfree(codec->chip_name); |
| 2506 | codec->chip_name = kstrdup(name, GFP_KERNEL); |
| 2507 | if (!codec->chip_name) { |
| 2508 | alc_free(codec); |
| 2509 | return -ENOMEM; |
| 2510 | } |
| 2511 | return 0; |
| 2512 | } |
| 2513 | |
Takashi Iwai | 2fa522b | 2005-05-12 14:51:12 +0200 | [diff] [blame] | 2514 | /* |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2515 | * Rename codecs appropriately from COEF value |
| 2516 | */ |
| 2517 | struct alc_codec_rename_table { |
| 2518 | unsigned int vendor_id; |
| 2519 | unsigned short coef_mask; |
| 2520 | unsigned short coef_bits; |
| 2521 | const char *name; |
| 2522 | }; |
| 2523 | |
| 2524 | static struct alc_codec_rename_table rename_tbl[] = { |
| 2525 | { 0x10ec0269, 0xfff0, 0x3010, "ALC277" }, |
| 2526 | { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" }, |
| 2527 | { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" }, |
| 2528 | { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" }, |
| 2529 | { 0x10ec0269, 0xffff, 0xa023, "ALC259" }, |
| 2530 | { 0x10ec0269, 0xffff, 0x6023, "ALC281X" }, |
| 2531 | { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" }, |
| 2532 | { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" }, |
| 2533 | { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" }, |
| 2534 | { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" }, |
| 2535 | { 0x10ec0899, 0x2000, 0x2000, "ALC899" }, |
| 2536 | { 0x10ec0892, 0xffff, 0x8020, "ALC661" }, |
| 2537 | { 0x10ec0892, 0xffff, 0x8011, "ALC661" }, |
| 2538 | { 0x10ec0892, 0xffff, 0x4011, "ALC656" }, |
| 2539 | { } /* terminator */ |
| 2540 | }; |
| 2541 | |
| 2542 | static int alc_codec_rename_from_preset(struct hda_codec *codec) |
| 2543 | { |
| 2544 | const struct alc_codec_rename_table *p; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2545 | |
| 2546 | for (p = rename_tbl; p->vendor_id; p++) { |
| 2547 | if (p->vendor_id != codec->vendor_id) |
| 2548 | continue; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 2549 | if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits) |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2550 | return alc_codec_rename(codec, p->name); |
| 2551 | } |
| 2552 | return 0; |
| 2553 | } |
| 2554 | |
| 2555 | /* |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2556 | * Automatic parse of I/O pins from the BIOS configuration |
| 2557 | */ |
| 2558 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2559 | enum { |
| 2560 | ALC_CTL_WIDGET_VOL, |
| 2561 | ALC_CTL_WIDGET_MUTE, |
| 2562 | ALC_CTL_BIND_MUTE, |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2563 | ALC_CTL_BIND_VOL, |
| 2564 | ALC_CTL_BIND_SW, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2565 | }; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2566 | static const struct snd_kcontrol_new alc_control_templates[] = { |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2567 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
| 2568 | HDA_CODEC_MUTE(NULL, 0, 0, 0), |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2569 | HDA_BIND_MUTE(NULL, 0, 0, 0), |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2570 | HDA_BIND_VOL(NULL, 0), |
| 2571 | HDA_BIND_SW(NULL, 0), |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2572 | }; |
| 2573 | |
| 2574 | /* add dynamic controls */ |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2575 | 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] | 2576 | int cidx, unsigned long val) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2577 | { |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2578 | struct snd_kcontrol_new *knew; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2579 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2580 | knew = alc_kcontrol_new(spec); |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2581 | if (!knew) |
| 2582 | return -ENOMEM; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2583 | *knew = alc_control_templates[type]; |
Paulo Marques | 543537b | 2005-06-23 00:09:02 -0700 | [diff] [blame] | 2584 | knew->name = kstrdup(name, GFP_KERNEL); |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2585 | if (!knew->name) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2586 | return -ENOMEM; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2587 | knew->index = cidx; |
Jaroslav Kysela | 4d02d1b | 2009-11-12 10:15:48 +0100 | [diff] [blame] | 2588 | if (get_amp_nid_(val)) |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 2589 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2590 | knew->private_value = val; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2591 | return 0; |
| 2592 | } |
| 2593 | |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2594 | static int add_control_with_pfx(struct alc_spec *spec, int type, |
| 2595 | const char *pfx, const char *dir, |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2596 | const char *sfx, int cidx, unsigned long val) |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2597 | { |
| 2598 | char name[32]; |
| 2599 | snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx); |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2600 | return add_control(spec, type, name, cidx, val); |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2601 | } |
| 2602 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2603 | #define add_pb_vol_ctrl(spec, type, pfx, val) \ |
| 2604 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val) |
| 2605 | #define add_pb_sw_ctrl(spec, type, pfx, val) \ |
| 2606 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val) |
| 2607 | #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \ |
| 2608 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val) |
| 2609 | #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \ |
| 2610 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val) |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2611 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2612 | static const char * const channel_name[4] = { |
| 2613 | "Front", "Surround", "CLFE", "Side" |
| 2614 | }; |
| 2615 | |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2616 | static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch, |
| 2617 | bool can_be_master, int *index) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2618 | { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2619 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2620 | |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2621 | *index = 0; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2622 | if (cfg->line_outs == 1 && !spec->multi_ios && |
| 2623 | !cfg->hp_outs && !cfg->speaker_outs && can_be_master) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2624 | return "Master"; |
| 2625 | |
| 2626 | switch (cfg->line_out_type) { |
| 2627 | case AUTO_PIN_SPEAKER_OUT: |
David Henningsson | ebbeb3d | 2011-03-04 14:08:30 +0100 | [diff] [blame] | 2628 | if (cfg->line_outs == 1) |
| 2629 | return "Speaker"; |
Takashi Iwai | fbabc24 | 2011-12-07 17:14:20 +0100 | [diff] [blame] | 2630 | if (cfg->line_outs == 2) |
| 2631 | return ch ? "Bass Speaker" : "Speaker"; |
David Henningsson | ebbeb3d | 2011-03-04 14:08:30 +0100 | [diff] [blame] | 2632 | break; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2633 | case AUTO_PIN_HP_OUT: |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2634 | /* for multi-io case, only the primary out */ |
| 2635 | if (ch && spec->multi_ios) |
| 2636 | break; |
| 2637 | *index = ch; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2638 | return "Headphone"; |
| 2639 | default: |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2640 | if (cfg->line_outs == 1 && !spec->multi_ios) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2641 | return "PCM"; |
| 2642 | break; |
| 2643 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2644 | if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name))) |
| 2645 | return "PCM"; |
| 2646 | |
| 2647 | return channel_name[ch]; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2648 | } |
| 2649 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2650 | /* create input playback/capture controls for the given pin */ |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2651 | 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] | 2652 | const char *ctlname, int ctlidx, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 2653 | int idx, hda_nid_t mix_nid) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2654 | { |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 2655 | int err; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2656 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2657 | err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2658 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 2659 | if (err < 0) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2660 | return err; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2661 | err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2662 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 2663 | if (err < 0) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2664 | return err; |
| 2665 | return 0; |
| 2666 | } |
| 2667 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2668 | 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] | 2669 | { |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2670 | unsigned int pincap = snd_hda_query_pin_caps(codec, nid); |
| 2671 | return (pincap & AC_PINCAP_IN) != 0; |
| 2672 | } |
| 2673 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2674 | /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */ |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2675 | static int alc_auto_fill_adc_caps(struct hda_codec *codec) |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2676 | { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2677 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2678 | hda_nid_t nid; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2679 | hda_nid_t *adc_nids = spec->private_adc_nids; |
| 2680 | hda_nid_t *cap_nids = spec->private_capsrc_nids; |
| 2681 | int max_nums = ARRAY_SIZE(spec->private_adc_nids); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2682 | int i, nums = 0; |
| 2683 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 2684 | if (spec->shared_mic_hp) |
| 2685 | max_nums = 1; /* no multi streams with the shared HP/mic */ |
| 2686 | |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2687 | nid = codec->start_nid; |
| 2688 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 2689 | hda_nid_t src; |
| 2690 | const hda_nid_t *list; |
| 2691 | unsigned int caps = get_wcaps(codec, nid); |
| 2692 | int type = get_wcaps_type(caps); |
| 2693 | |
| 2694 | if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL)) |
| 2695 | continue; |
| 2696 | adc_nids[nums] = nid; |
| 2697 | cap_nids[nums] = nid; |
| 2698 | src = nid; |
| 2699 | for (;;) { |
| 2700 | int n; |
| 2701 | type = get_wcaps_type(get_wcaps(codec, src)); |
| 2702 | if (type == AC_WID_PIN) |
| 2703 | break; |
| 2704 | if (type == AC_WID_AUD_SEL) { |
| 2705 | cap_nids[nums] = src; |
| 2706 | break; |
| 2707 | } |
| 2708 | n = snd_hda_get_conn_list(codec, src, &list); |
| 2709 | if (n > 1) { |
| 2710 | cap_nids[nums] = src; |
| 2711 | break; |
| 2712 | } else if (n != 1) |
| 2713 | break; |
| 2714 | src = *list; |
| 2715 | } |
| 2716 | if (++nums >= max_nums) |
| 2717 | break; |
| 2718 | } |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2719 | spec->adc_nids = spec->private_adc_nids; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2720 | spec->capsrc_nids = spec->private_capsrc_nids; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2721 | spec->num_adc_nids = nums; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2722 | return nums; |
| 2723 | } |
| 2724 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2725 | /* create playback/capture controls for input pins */ |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2726 | static int alc_auto_create_input_ctls(struct hda_codec *codec) |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2727 | { |
| 2728 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2729 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2730 | hda_nid_t mixer = spec->mixer_nid; |
Herton Ronaldo Krzesinski | 61b9b9b | 2009-01-28 09:16:33 -0200 | [diff] [blame] | 2731 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2732 | int num_adcs; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2733 | int i, c, err, idx, type_idx = 0; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2734 | const char *prev_label = NULL; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2735 | |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2736 | num_adcs = alc_auto_fill_adc_caps(codec); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2737 | if (num_adcs < 0) |
| 2738 | return 0; |
| 2739 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2740 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2741 | hda_nid_t pin; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2742 | const char *label; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2743 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2744 | pin = cfg->inputs[i].pin; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2745 | if (!alc_is_input_pin(codec, pin)) |
| 2746 | continue; |
| 2747 | |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2748 | label = hda_get_autocfg_input_label(codec, cfg, i); |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 2749 | if (spec->shared_mic_hp && !strcmp(label, "Misc")) |
| 2750 | label = "Headphone Mic"; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2751 | if (prev_label && !strcmp(label, prev_label)) |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2752 | type_idx++; |
| 2753 | else |
| 2754 | type_idx = 0; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2755 | prev_label = label; |
| 2756 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2757 | if (mixer) { |
| 2758 | idx = get_connection_index(codec, mixer, pin); |
| 2759 | if (idx >= 0) { |
| 2760 | err = new_analog_input(spec, pin, |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2761 | label, type_idx, |
| 2762 | idx, mixer); |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2763 | if (err < 0) |
| 2764 | return err; |
| 2765 | } |
| 2766 | } |
| 2767 | |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2768 | for (c = 0; c < num_adcs; c++) { |
Takashi Iwai | 6107159 | 2011-11-23 07:52:15 +0100 | [diff] [blame] | 2769 | hda_nid_t cap = get_capsrc(spec, c); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2770 | idx = get_connection_index(codec, cap, pin); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2771 | if (idx >= 0) { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2772 | spec->imux_pins[imux->num_items] = pin; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2773 | snd_hda_add_imux_item(imux, label, idx, NULL); |
| 2774 | break; |
| 2775 | } |
| 2776 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2777 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2778 | |
| 2779 | spec->num_mux_defs = 1; |
| 2780 | spec->input_mux = imux; |
| 2781 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2782 | return 0; |
| 2783 | } |
| 2784 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 2785 | /* create a shared input with the headphone out */ |
| 2786 | static int alc_auto_create_shared_input(struct hda_codec *codec) |
| 2787 | { |
| 2788 | struct alc_spec *spec = codec->spec; |
| 2789 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2790 | unsigned int defcfg; |
| 2791 | hda_nid_t nid; |
| 2792 | |
| 2793 | /* only one internal input pin? */ |
| 2794 | if (cfg->num_inputs != 1) |
| 2795 | return 0; |
| 2796 | defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin); |
| 2797 | if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT) |
| 2798 | return 0; |
| 2799 | |
| 2800 | if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) |
| 2801 | nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */ |
| 2802 | else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT) |
| 2803 | nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */ |
| 2804 | else |
| 2805 | return 0; /* both not available */ |
| 2806 | |
| 2807 | if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN)) |
| 2808 | return 0; /* no input */ |
| 2809 | |
| 2810 | cfg->inputs[1].pin = nid; |
| 2811 | cfg->inputs[1].type = AUTO_PIN_MIC; |
| 2812 | cfg->num_inputs = 2; |
| 2813 | spec->shared_mic_hp = 1; |
| 2814 | snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid); |
| 2815 | return 0; |
| 2816 | } |
| 2817 | |
Takashi Iwai | f6c7e54 | 2008-02-12 18:32:23 +0100 | [diff] [blame] | 2818 | static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid, |
| 2819 | unsigned int pin_type) |
| 2820 | { |
| 2821 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 2822 | pin_type); |
| 2823 | /* unmute pin */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 2824 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
| 2825 | 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] | 2826 | AMP_OUT_UNMUTE); |
Takashi Iwai | f6c7e54 | 2008-02-12 18:32:23 +0100 | [diff] [blame] | 2827 | } |
| 2828 | |
Takashi Iwai | baba8ee | 2007-04-23 17:17:48 +0200 | [diff] [blame] | 2829 | static int get_pin_type(int line_out_type) |
| 2830 | { |
| 2831 | if (line_out_type == AUTO_PIN_HP_OUT) |
| 2832 | return PIN_HP; |
| 2833 | else |
| 2834 | return PIN_OUT; |
| 2835 | } |
| 2836 | |
Takashi Iwai | 0a7f532 | 2011-07-06 15:15:12 +0200 | [diff] [blame] | 2837 | static void alc_auto_init_analog_input(struct hda_codec *codec) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2838 | { |
| 2839 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2840 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2841 | int i; |
| 2842 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2843 | for (i = 0; i < cfg->num_inputs; i++) { |
| 2844 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2845 | if (alc_is_input_pin(codec, nid)) { |
Takashi Iwai | 30ea098 | 2010-09-16 18:47:56 +0200 | [diff] [blame] | 2846 | alc_set_input_pin(codec, nid, cfg->inputs[i].type); |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 2847 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2848 | snd_hda_codec_write(codec, nid, 0, |
| 2849 | AC_VERB_SET_AMP_GAIN_MUTE, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2850 | AMP_OUT_MUTE); |
| 2851 | } |
| 2852 | } |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 2853 | |
| 2854 | /* mute all loopback inputs */ |
| 2855 | if (spec->mixer_nid) { |
| 2856 | int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL); |
| 2857 | for (i = 0; i < nums; i++) |
| 2858 | snd_hda_codec_write(codec, spec->mixer_nid, 0, |
| 2859 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 2860 | AMP_IN_MUTE(i)); |
| 2861 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2862 | } |
| 2863 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2864 | /* convert from MIX nid to DAC */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2865 | 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] | 2866 | { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2867 | hda_nid_t list[5]; |
Takashi Iwai | 1304ac8 | 2011-04-06 15:16:21 +0200 | [diff] [blame] | 2868 | int i, num; |
| 2869 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 2870 | if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT) |
| 2871 | return nid; |
Takashi Iwai | 1304ac8 | 2011-04-06 15:16:21 +0200 | [diff] [blame] | 2872 | num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list)); |
| 2873 | for (i = 0; i < num; i++) { |
| 2874 | if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT) |
| 2875 | return list[i]; |
| 2876 | } |
| 2877 | return 0; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2878 | } |
| 2879 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2880 | /* go down to the selector widget before the mixer */ |
| 2881 | static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin) |
| 2882 | { |
| 2883 | hda_nid_t srcs[5]; |
| 2884 | int num = snd_hda_get_connections(codec, pin, srcs, |
| 2885 | ARRAY_SIZE(srcs)); |
| 2886 | if (num != 1 || |
| 2887 | get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL) |
| 2888 | return pin; |
| 2889 | return srcs[0]; |
| 2890 | } |
| 2891 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2892 | /* get MIX nid connected to the given pin targeted to DAC */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2893 | 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] | 2894 | hda_nid_t dac) |
| 2895 | { |
David Henningsson | cc1c452 | 2010-11-24 14:17:47 +0100 | [diff] [blame] | 2896 | hda_nid_t mix[5]; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2897 | int i, num; |
| 2898 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2899 | pin = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2900 | num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); |
| 2901 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2902 | if (alc_auto_mix_to_dac(codec, mix[i]) == dac) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2903 | return mix[i]; |
| 2904 | } |
| 2905 | return 0; |
| 2906 | } |
| 2907 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2908 | /* select the connection from pin to DAC if needed */ |
| 2909 | static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin, |
| 2910 | hda_nid_t dac) |
| 2911 | { |
| 2912 | hda_nid_t mix[5]; |
| 2913 | int i, num; |
| 2914 | |
| 2915 | pin = alc_go_down_to_selector(codec, pin); |
| 2916 | num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); |
| 2917 | if (num < 2) |
| 2918 | return 0; |
| 2919 | for (i = 0; i < num; i++) { |
| 2920 | if (alc_auto_mix_to_dac(codec, mix[i]) == dac) { |
| 2921 | snd_hda_codec_update_cache(codec, pin, 0, |
| 2922 | AC_VERB_SET_CONNECT_SEL, i); |
| 2923 | return 0; |
| 2924 | } |
| 2925 | } |
| 2926 | return 0; |
| 2927 | } |
| 2928 | |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 2929 | static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid) |
| 2930 | { |
| 2931 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 2932 | int i; |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 2933 | if (found_in_nid_list(nid, spec->multiout.dac_nids, |
| 2934 | ARRAY_SIZE(spec->private_dac_nids)) || |
| 2935 | found_in_nid_list(nid, spec->multiout.hp_out_nid, |
| 2936 | ARRAY_SIZE(spec->multiout.hp_out_nid)) || |
| 2937 | found_in_nid_list(nid, spec->multiout.extra_out_nid, |
| 2938 | ARRAY_SIZE(spec->multiout.extra_out_nid))) |
| 2939 | return true; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 2940 | for (i = 0; i < spec->multi_ios; i++) { |
| 2941 | if (spec->multi_io[i].dac == nid) |
| 2942 | return true; |
| 2943 | } |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 2944 | return false; |
| 2945 | } |
| 2946 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2947 | /* look for an empty DAC slot */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2948 | 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] | 2949 | { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2950 | hda_nid_t srcs[5]; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2951 | int i, num; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2952 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2953 | pin = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2954 | num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs)); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2955 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2956 | hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2957 | if (!nid) |
| 2958 | continue; |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 2959 | if (!alc_is_dac_already_used(codec, nid)) |
| 2960 | return nid; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2961 | } |
| 2962 | return 0; |
| 2963 | } |
| 2964 | |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 2965 | /* check whether the DAC is reachable from the pin */ |
| 2966 | static bool alc_auto_is_dac_reachable(struct hda_codec *codec, |
| 2967 | hda_nid_t pin, hda_nid_t dac) |
| 2968 | { |
| 2969 | hda_nid_t srcs[5]; |
| 2970 | int i, num; |
| 2971 | |
| 2972 | pin = alc_go_down_to_selector(codec, pin); |
| 2973 | num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs)); |
| 2974 | for (i = 0; i < num; i++) { |
| 2975 | hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]); |
| 2976 | if (nid == dac) |
| 2977 | return true; |
| 2978 | } |
| 2979 | return false; |
| 2980 | } |
| 2981 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2982 | static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin) |
| 2983 | { |
Takashi Iwai | 140547e | 2012-02-16 17:23:46 +0100 | [diff] [blame] | 2984 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2985 | hda_nid_t sel = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 2986 | hda_nid_t nid, nid_found, srcs[5]; |
| 2987 | int i, num = snd_hda_get_connections(codec, sel, srcs, |
Takashi Iwai | 140547e | 2012-02-16 17:23:46 +0100 | [diff] [blame] | 2988 | ARRAY_SIZE(srcs)); |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 2989 | if (num == 1) |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2990 | return alc_auto_look_for_dac(codec, pin); |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 2991 | nid_found = 0; |
| 2992 | for (i = 0; i < num; i++) { |
| 2993 | if (srcs[i] == spec->mixer_nid) |
| 2994 | continue; |
| 2995 | nid = alc_auto_mix_to_dac(codec, srcs[i]); |
| 2996 | if (nid && !alc_is_dac_already_used(codec, nid)) { |
| 2997 | if (nid_found) |
| 2998 | return 0; |
| 2999 | nid_found = nid; |
| 3000 | } |
| 3001 | } |
| 3002 | return nid_found; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3003 | } |
| 3004 | |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3005 | /* mark up volume and mute control NIDs: used during badness parsing and |
| 3006 | * at creating actual controls |
| 3007 | */ |
| 3008 | static inline unsigned int get_ctl_pos(unsigned int data) |
| 3009 | { |
| 3010 | hda_nid_t nid = get_amp_nid_(data); |
| 3011 | unsigned int dir; |
| 3012 | if (snd_BUG_ON(nid >= MAX_VOL_NIDS)) |
| 3013 | return 0; |
| 3014 | dir = get_amp_direction_(data); |
| 3015 | return (nid << 1) | dir; |
| 3016 | } |
| 3017 | |
| 3018 | #define is_ctl_used(bits, data) \ |
| 3019 | test_bit(get_ctl_pos(data), bits) |
| 3020 | #define mark_ctl_usage(bits, data) \ |
| 3021 | set_bit(get_ctl_pos(data), bits) |
| 3022 | |
| 3023 | static void clear_vol_marks(struct hda_codec *codec) |
| 3024 | { |
| 3025 | struct alc_spec *spec = codec->spec; |
| 3026 | memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls)); |
| 3027 | memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls)); |
| 3028 | } |
| 3029 | |
| 3030 | /* badness definition */ |
| 3031 | enum { |
| 3032 | /* No primary DAC is found for the main output */ |
| 3033 | BAD_NO_PRIMARY_DAC = 0x10000, |
| 3034 | /* No DAC is found for the extra output */ |
| 3035 | BAD_NO_DAC = 0x4000, |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3036 | /* No possible multi-ios */ |
| 3037 | BAD_MULTI_IO = 0x103, |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3038 | /* No individual DAC for extra output */ |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3039 | BAD_NO_EXTRA_DAC = 0x102, |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3040 | /* No individual DAC for extra surrounds */ |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3041 | BAD_NO_EXTRA_SURR_DAC = 0x101, |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3042 | /* Primary DAC shared with main surrounds */ |
| 3043 | BAD_SHARED_SURROUND = 0x100, |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3044 | /* Primary DAC shared with main CLFE */ |
| 3045 | BAD_SHARED_CLFE = 0x10, |
| 3046 | /* Primary DAC shared with extra surrounds */ |
| 3047 | BAD_SHARED_EXTRA_SURROUND = 0x10, |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3048 | /* Volume widget is shared */ |
| 3049 | BAD_SHARED_VOL = 0x10, |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3050 | }; |
| 3051 | |
| 3052 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, |
| 3053 | hda_nid_t pin, hda_nid_t dac); |
| 3054 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, |
| 3055 | hda_nid_t pin, hda_nid_t dac); |
| 3056 | |
| 3057 | static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin, |
| 3058 | hda_nid_t dac) |
| 3059 | { |
| 3060 | struct alc_spec *spec = codec->spec; |
| 3061 | hda_nid_t nid; |
| 3062 | unsigned int val; |
| 3063 | int badness = 0; |
| 3064 | |
| 3065 | nid = alc_look_for_out_vol_nid(codec, pin, dac); |
| 3066 | if (nid) { |
| 3067 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); |
| 3068 | if (is_ctl_used(spec->vol_ctls, nid)) |
| 3069 | badness += BAD_SHARED_VOL; |
| 3070 | else |
| 3071 | mark_ctl_usage(spec->vol_ctls, val); |
| 3072 | } else |
| 3073 | badness += BAD_SHARED_VOL; |
| 3074 | nid = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3075 | if (nid) { |
| 3076 | unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid)); |
| 3077 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) |
| 3078 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); |
| 3079 | else |
| 3080 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT); |
| 3081 | if (is_ctl_used(spec->sw_ctls, val)) |
| 3082 | badness += BAD_SHARED_VOL; |
| 3083 | else |
| 3084 | mark_ctl_usage(spec->sw_ctls, val); |
| 3085 | } else |
| 3086 | badness += BAD_SHARED_VOL; |
| 3087 | return badness; |
| 3088 | } |
| 3089 | |
| 3090 | /* try to assign DACs to extra pins and return the resultant badness */ |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3091 | static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs, |
| 3092 | const hda_nid_t *pins, hda_nid_t *dacs) |
| 3093 | { |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3094 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3095 | int i; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3096 | int badness = 0; |
| 3097 | hda_nid_t dac; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3098 | |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 3099 | if (!num_outs) |
| 3100 | return 0; |
| 3101 | |
| 3102 | if (!dacs[0]) |
| 3103 | dacs[0] = alc_auto_look_for_dac(codec, pins[0]); |
| 3104 | if (!dacs[0]) { |
| 3105 | for (i = 1; i < num_outs; i++) { |
| 3106 | dac = dacs[i]; |
| 3107 | if (dac && alc_auto_is_dac_reachable(codec, pins[0], dac)) { |
| 3108 | dacs[0] = dac; |
| 3109 | dacs[i] = 0; |
| 3110 | break; |
| 3111 | } |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3112 | } |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3113 | } |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 3114 | dac = dacs[0]; |
| 3115 | if (!dac) { |
| 3116 | dac = spec->private_dac_nids[0]; |
| 3117 | if (!alc_auto_is_dac_reachable(codec, pins[0], dac)) |
| 3118 | return BAD_NO_DAC; |
| 3119 | badness += BAD_NO_EXTRA_DAC; |
| 3120 | } |
| 3121 | if (dac) |
| 3122 | badness += eval_shared_vol_badness(codec, pins[0], dac); |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3123 | |
| 3124 | for (i = 1; i < num_outs; i++) |
| 3125 | dacs[i] = get_dac_if_single(codec, pins[i]); |
| 3126 | for (i = 1; i < num_outs; i++) { |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3127 | dac = dacs[i]; |
| 3128 | if (!dac) |
| 3129 | dac = dacs[i] = alc_auto_look_for_dac(codec, pins[i]); |
| 3130 | if (!dac) { |
| 3131 | if (alc_auto_is_dac_reachable(codec, pins[i], dacs[0])) { |
| 3132 | dac = dacs[0]; |
| 3133 | badness += BAD_SHARED_EXTRA_SURROUND; |
| 3134 | } else if (alc_auto_is_dac_reachable(codec, pins[i], |
| 3135 | spec->private_dac_nids[0])) { |
| 3136 | dac = spec->private_dac_nids[0]; |
| 3137 | badness += BAD_NO_EXTRA_SURR_DAC; |
| 3138 | } else |
| 3139 | badness += BAD_NO_DAC; |
| 3140 | } |
| 3141 | if (dac) |
| 3142 | badness += eval_shared_vol_badness(codec, pins[i], dac); |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3143 | } |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3144 | return badness; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3148 | hda_nid_t reference_pin, |
| 3149 | bool hardwired, int offset); |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3150 | |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 3151 | static bool alc_map_singles(struct hda_codec *codec, int outs, |
| 3152 | const hda_nid_t *pins, hda_nid_t *dacs) |
| 3153 | { |
| 3154 | int i; |
| 3155 | bool found = false; |
| 3156 | for (i = 0; i < outs; i++) { |
| 3157 | if (dacs[i]) |
| 3158 | continue; |
| 3159 | dacs[i] = get_dac_if_single(codec, pins[i]); |
| 3160 | if (dacs[i]) |
| 3161 | found = true; |
| 3162 | } |
| 3163 | return found; |
| 3164 | } |
| 3165 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3166 | /* fill in the dac_nids table from the parsed pin configuration */ |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3167 | static int fill_and_eval_dacs(struct hda_codec *codec, |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3168 | bool fill_hardwired, |
| 3169 | bool fill_mio_first) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3170 | { |
| 3171 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 0a34b42 | 2011-12-07 17:20:30 +0100 | [diff] [blame] | 3172 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 3173 | int i, j, err, badness; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3174 | |
Takashi Iwai | 8f398ae | 2011-07-23 18:57:11 +0200 | [diff] [blame] | 3175 | /* set num_dacs once to full for alc_auto_look_for_dac() */ |
| 3176 | spec->multiout.num_dacs = cfg->line_outs; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3177 | spec->multiout.dac_nids = spec->private_dac_nids; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3178 | memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids)); |
| 3179 | memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid)); |
| 3180 | memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid)); |
Takashi Iwai | 0a34b42 | 2011-12-07 17:20:30 +0100 | [diff] [blame] | 3181 | spec->multi_ios = 0; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3182 | clear_vol_marks(codec); |
| 3183 | badness = 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3184 | |
| 3185 | /* fill hard-wired DACs first */ |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3186 | if (fill_hardwired) { |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 3187 | bool mapped; |
| 3188 | do { |
| 3189 | mapped = alc_map_singles(codec, cfg->line_outs, |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3190 | cfg->line_out_pins, |
| 3191 | spec->private_dac_nids); |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 3192 | mapped |= alc_map_singles(codec, cfg->hp_outs, |
| 3193 | cfg->hp_pins, |
| 3194 | spec->multiout.hp_out_nid); |
| 3195 | mapped |= alc_map_singles(codec, cfg->speaker_outs, |
| 3196 | cfg->speaker_pins, |
| 3197 | spec->multiout.extra_out_nid); |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3198 | if (fill_mio_first && cfg->line_outs == 1 && |
| 3199 | cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
| 3200 | err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0); |
| 3201 | if (!err) |
| 3202 | mapped = true; |
| 3203 | } |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 3204 | } while (mapped); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3205 | } |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3206 | |
| 3207 | for (i = 0; i < cfg->line_outs; i++) { |
| 3208 | hda_nid_t pin = cfg->line_out_pins[i]; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3209 | hda_nid_t dac; |
| 3210 | if (!spec->private_dac_nids[i]) |
| 3211 | spec->private_dac_nids[i] = |
| 3212 | alc_auto_look_for_dac(codec, pin); |
| 3213 | dac = spec->private_dac_nids[i]; |
Takashi Iwai | 185d99f | 2012-02-16 18:39:45 +0100 | [diff] [blame] | 3214 | if (!dac && !i) { |
| 3215 | for (j = 1; j < cfg->line_outs; j++) { |
| 3216 | hda_nid_t dac2 = spec->private_dac_nids[j]; |
| 3217 | if (dac2 && |
| 3218 | alc_auto_is_dac_reachable(codec, pin, dac2)) { |
| 3219 | dac = spec->private_dac_nids[0] = dac2; |
| 3220 | spec->private_dac_nids[j] = 0; |
| 3221 | break; |
| 3222 | } |
| 3223 | } |
| 3224 | } |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3225 | if (!dac) { |
| 3226 | if (!i) |
| 3227 | badness += BAD_NO_PRIMARY_DAC; |
| 3228 | else if (alc_auto_is_dac_reachable(codec, pin, |
| 3229 | spec->private_dac_nids[0])) { |
| 3230 | if (i == 1) |
| 3231 | badness += BAD_SHARED_SURROUND; |
| 3232 | else |
| 3233 | badness += BAD_SHARED_CLFE; |
| 3234 | dac = spec->private_dac_nids[0]; |
| 3235 | } else |
| 3236 | badness += BAD_NO_DAC; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3237 | } |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3238 | if (dac) |
| 3239 | badness += eval_shared_vol_badness(codec, pin, dac); |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3240 | } |
| 3241 | |
Takashi Iwai | 8f398ae | 2011-07-23 18:57:11 +0200 | [diff] [blame] | 3242 | /* re-count num_dacs and squash invalid entries */ |
| 3243 | spec->multiout.num_dacs = 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3244 | for (i = 0; i < cfg->line_outs; i++) { |
| 3245 | if (spec->private_dac_nids[i]) |
| 3246 | spec->multiout.num_dacs++; |
Takashi Iwai | 0a34b42 | 2011-12-07 17:20:30 +0100 | [diff] [blame] | 3247 | else { |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3248 | memmove(spec->private_dac_nids + i, |
| 3249 | spec->private_dac_nids + i + 1, |
| 3250 | sizeof(hda_nid_t) * (cfg->line_outs - i - 1)); |
Takashi Iwai | 0a34b42 | 2011-12-07 17:20:30 +0100 | [diff] [blame] | 3251 | spec->private_dac_nids[cfg->line_outs - 1] = 0; |
| 3252 | } |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3253 | } |
| 3254 | |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3255 | if (fill_mio_first && |
| 3256 | cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3257 | /* try to fill multi-io first */ |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3258 | err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3259 | if (err < 0) |
| 3260 | return err; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3261 | /* we don't count badness at this stage yet */ |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3262 | } |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3263 | |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3264 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) { |
| 3265 | err = alc_auto_fill_extra_dacs(codec, cfg->hp_outs, |
| 3266 | cfg->hp_pins, |
| 3267 | spec->multiout.hp_out_nid); |
| 3268 | if (err < 0) |
| 3269 | return err; |
| 3270 | badness += err; |
| 3271 | } |
Takashi Iwai | 0a34b42 | 2011-12-07 17:20:30 +0100 | [diff] [blame] | 3272 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3273 | err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, |
| 3274 | cfg->speaker_pins, |
| 3275 | spec->multiout.extra_out_nid); |
| 3276 | if (err < 0) |
| 3277 | return err; |
| 3278 | badness += err; |
| 3279 | } |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3280 | if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
| 3281 | err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3282 | if (err < 0) |
| 3283 | return err; |
| 3284 | badness += err; |
| 3285 | } |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3286 | if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { |
| 3287 | /* try multi-ios with HP + inputs */ |
| 3288 | err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false, 1); |
| 3289 | if (err < 0) |
| 3290 | return err; |
| 3291 | badness += err; |
| 3292 | } |
| 3293 | |
| 3294 | if (spec->multi_ios == 2) { |
| 3295 | for (i = 0; i < 2; i++) |
| 3296 | spec->private_dac_nids[spec->multiout.num_dacs++] = |
| 3297 | spec->multi_io[i].dac; |
| 3298 | spec->ext_channel_count = 2; |
| 3299 | } else if (spec->multi_ios) { |
| 3300 | spec->multi_ios = 0; |
| 3301 | badness += BAD_MULTI_IO; |
| 3302 | } |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3303 | |
| 3304 | return badness; |
| 3305 | } |
| 3306 | |
| 3307 | #define DEBUG_BADNESS |
| 3308 | |
| 3309 | #ifdef DEBUG_BADNESS |
| 3310 | #define debug_badness snd_printdd |
| 3311 | #else |
| 3312 | #define debug_badness(...) |
| 3313 | #endif |
| 3314 | |
| 3315 | static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg) |
| 3316 | { |
| 3317 | debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n", |
| 3318 | cfg->line_out_pins[0], cfg->line_out_pins[1], |
| 3319 | cfg->line_out_pins[2], cfg->line_out_pins[2], |
| 3320 | spec->multiout.dac_nids[0], |
| 3321 | spec->multiout.dac_nids[1], |
| 3322 | spec->multiout.dac_nids[2], |
| 3323 | spec->multiout.dac_nids[3]); |
Takashi Iwai | 6f45304 | 2012-02-17 14:09:20 +0100 | [diff] [blame] | 3324 | if (spec->multi_ios > 0) |
| 3325 | debug_badness("multi_ios(%d) = %x/%x : %x/%x\n", |
| 3326 | spec->multi_ios, |
| 3327 | spec->multi_io[0].pin, spec->multi_io[1].pin, |
| 3328 | spec->multi_io[0].dac, spec->multi_io[1].dac); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3329 | debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n", |
| 3330 | cfg->hp_pins[0], cfg->hp_pins[1], |
| 3331 | cfg->hp_pins[2], cfg->hp_pins[2], |
| 3332 | spec->multiout.hp_out_nid[0], |
| 3333 | spec->multiout.hp_out_nid[1], |
| 3334 | spec->multiout.hp_out_nid[2], |
| 3335 | spec->multiout.hp_out_nid[3]); |
| 3336 | debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n", |
| 3337 | cfg->speaker_pins[0], cfg->speaker_pins[1], |
| 3338 | cfg->speaker_pins[2], cfg->speaker_pins[3], |
| 3339 | spec->multiout.extra_out_nid[0], |
| 3340 | spec->multiout.extra_out_nid[1], |
| 3341 | spec->multiout.extra_out_nid[2], |
| 3342 | spec->multiout.extra_out_nid[3]); |
| 3343 | } |
| 3344 | |
| 3345 | static int alc_auto_fill_dac_nids(struct hda_codec *codec) |
| 3346 | { |
| 3347 | struct alc_spec *spec = codec->spec; |
| 3348 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3349 | struct auto_pin_cfg *best_cfg; |
| 3350 | int best_badness = INT_MAX; |
| 3351 | int badness; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3352 | bool fill_hardwired = true, fill_mio_first = true; |
| 3353 | bool best_wired = true, best_mio = true; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3354 | bool hp_spk_swapped = false; |
| 3355 | |
| 3356 | best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL); |
| 3357 | if (!best_cfg) |
| 3358 | return -ENOMEM; |
| 3359 | *best_cfg = *cfg; |
| 3360 | |
| 3361 | for (;;) { |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3362 | badness = fill_and_eval_dacs(codec, fill_hardwired, |
| 3363 | fill_mio_first); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3364 | if (badness < 0) |
| 3365 | return badness; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3366 | debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n", |
| 3367 | cfg->line_out_type, fill_hardwired, fill_mio_first, |
| 3368 | badness); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3369 | debug_show_configs(spec, cfg); |
| 3370 | if (badness < best_badness) { |
| 3371 | best_badness = badness; |
| 3372 | *best_cfg = *cfg; |
| 3373 | best_wired = fill_hardwired; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3374 | best_mio = fill_mio_first; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3375 | } |
| 3376 | if (!badness) |
| 3377 | break; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3378 | fill_mio_first = !fill_mio_first; |
| 3379 | if (!fill_mio_first) |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3380 | continue; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3381 | fill_hardwired = !fill_hardwired; |
| 3382 | if (!fill_hardwired) |
| 3383 | continue; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3384 | if (hp_spk_swapped) |
| 3385 | break; |
| 3386 | hp_spk_swapped = true; |
| 3387 | if (cfg->speaker_outs > 0 && |
Takashi Iwai | 0a34b42 | 2011-12-07 17:20:30 +0100 | [diff] [blame] | 3388 | cfg->line_out_type == AUTO_PIN_HP_OUT) { |
| 3389 | cfg->hp_outs = cfg->line_outs; |
| 3390 | memcpy(cfg->hp_pins, cfg->line_out_pins, |
| 3391 | sizeof(cfg->hp_pins)); |
| 3392 | cfg->line_outs = cfg->speaker_outs; |
| 3393 | memcpy(cfg->line_out_pins, cfg->speaker_pins, |
| 3394 | sizeof(cfg->speaker_pins)); |
| 3395 | cfg->speaker_outs = 0; |
| 3396 | memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins)); |
| 3397 | cfg->line_out_type = AUTO_PIN_SPEAKER_OUT; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3398 | fill_hardwired = true; |
| 3399 | continue; |
| 3400 | } |
| 3401 | if (cfg->hp_outs > 0 && |
| 3402 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { |
| 3403 | cfg->speaker_outs = cfg->line_outs; |
| 3404 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 3405 | sizeof(cfg->speaker_pins)); |
| 3406 | cfg->line_outs = cfg->hp_outs; |
| 3407 | memcpy(cfg->line_out_pins, cfg->hp_pins, |
| 3408 | sizeof(cfg->hp_pins)); |
| 3409 | cfg->hp_outs = 0; |
| 3410 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); |
| 3411 | cfg->line_out_type = AUTO_PIN_HP_OUT; |
| 3412 | fill_hardwired = true; |
| 3413 | continue; |
| 3414 | } |
| 3415 | break; |
Takashi Iwai | 0a34b42 | 2011-12-07 17:20:30 +0100 | [diff] [blame] | 3416 | } |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3417 | |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3418 | if (badness) { |
| 3419 | *cfg = *best_cfg; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3420 | fill_and_eval_dacs(codec, best_wired, best_mio); |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3421 | } |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3422 | debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n", |
| 3423 | cfg->line_out_type, best_wired, best_mio); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3424 | debug_show_configs(spec, cfg); |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3425 | |
David Henningsson | fde48a1 | 2011-12-09 18:27:42 +0800 | [diff] [blame] | 3426 | if (cfg->line_out_pins[0]) |
| 3427 | spec->vmaster_nid = |
| 3428 | alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0], |
| 3429 | spec->multiout.dac_nids[0]); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3430 | |
| 3431 | /* clear the bitmap flags for creating controls */ |
| 3432 | clear_vol_marks(codec); |
| 3433 | kfree(best_cfg); |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3434 | return 0; |
| 3435 | } |
| 3436 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3437 | static int alc_auto_add_vol_ctl(struct hda_codec *codec, |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3438 | const char *pfx, int cidx, |
| 3439 | hda_nid_t nid, unsigned int chs) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3440 | { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3441 | struct alc_spec *spec = codec->spec; |
| 3442 | unsigned int val; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3443 | if (!nid) |
| 3444 | return 0; |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3445 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); |
| 3446 | if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */ |
| 3447 | return 0; |
| 3448 | mark_ctl_usage(spec->vol_ctls, val); |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3449 | 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] | 3450 | val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3451 | } |
| 3452 | |
Takashi Iwai | e29d377 | 2011-11-14 17:13:23 +0100 | [diff] [blame] | 3453 | static int alc_auto_add_stereo_vol(struct hda_codec *codec, |
| 3454 | const char *pfx, int cidx, |
| 3455 | hda_nid_t nid) |
| 3456 | { |
| 3457 | int chs = 1; |
| 3458 | if (get_wcaps(codec, nid) & AC_WCAP_STEREO) |
| 3459 | chs = 3; |
| 3460 | return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs); |
| 3461 | } |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3462 | |
| 3463 | /* create a mute-switch for the given mixer widget; |
| 3464 | * if it has multiple sources (e.g. DAC and loopback), create a bind-mute |
| 3465 | */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3466 | static int alc_auto_add_sw_ctl(struct hda_codec *codec, |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3467 | const char *pfx, int cidx, |
| 3468 | hda_nid_t nid, unsigned int chs) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3469 | { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3470 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3471 | int wid_type; |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3472 | int type; |
| 3473 | unsigned long val; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3474 | if (!nid) |
| 3475 | return 0; |
| 3476 | wid_type = get_wcaps_type(get_wcaps(codec, nid)); |
| 3477 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) { |
| 3478 | type = ALC_CTL_WIDGET_MUTE; |
| 3479 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); |
| 3480 | } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) { |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3481 | type = ALC_CTL_WIDGET_MUTE; |
| 3482 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT); |
| 3483 | } else { |
| 3484 | type = ALC_CTL_BIND_MUTE; |
| 3485 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT); |
| 3486 | } |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3487 | if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */ |
| 3488 | return 0; |
| 3489 | mark_ctl_usage(spec->sw_ctls, val); |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3490 | return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3491 | } |
| 3492 | |
Takashi Iwai | e29d377 | 2011-11-14 17:13:23 +0100 | [diff] [blame] | 3493 | static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx, |
| 3494 | int cidx, hda_nid_t nid) |
| 3495 | { |
| 3496 | int chs = 1; |
| 3497 | if (get_wcaps(codec, nid) & AC_WCAP_STEREO) |
| 3498 | chs = 3; |
| 3499 | return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs); |
| 3500 | } |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3501 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3502 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, |
| 3503 | hda_nid_t pin, hda_nid_t dac) |
| 3504 | { |
| 3505 | hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac); |
| 3506 | if (nid_has_mute(codec, pin, HDA_OUTPUT)) |
| 3507 | return pin; |
| 3508 | else if (mix && nid_has_mute(codec, mix, HDA_INPUT)) |
| 3509 | return mix; |
| 3510 | else if (nid_has_mute(codec, dac, HDA_OUTPUT)) |
| 3511 | return dac; |
| 3512 | return 0; |
| 3513 | } |
| 3514 | |
| 3515 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, |
| 3516 | hda_nid_t pin, hda_nid_t dac) |
| 3517 | { |
| 3518 | hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac); |
| 3519 | if (nid_has_volume(codec, dac, HDA_OUTPUT)) |
| 3520 | return dac; |
| 3521 | else if (nid_has_volume(codec, mix, HDA_OUTPUT)) |
| 3522 | return mix; |
| 3523 | else if (nid_has_volume(codec, pin, HDA_OUTPUT)) |
| 3524 | return pin; |
| 3525 | return 0; |
| 3526 | } |
| 3527 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3528 | /* add playback controls from the parsed DAC table */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3529 | static int alc_auto_create_multi_out_ctls(struct hda_codec *codec, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3530 | const struct auto_pin_cfg *cfg) |
| 3531 | { |
| 3532 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3533 | int i, err, noutputs; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3534 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3535 | noutputs = cfg->line_outs; |
Takashi Iwai | b90bf1d | 2012-01-19 11:42:55 +0100 | [diff] [blame] | 3536 | if (spec->multi_ios > 0 && cfg->line_outs < 3) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3537 | noutputs += spec->multi_ios; |
| 3538 | |
| 3539 | for (i = 0; i < noutputs; i++) { |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 3540 | const char *name; |
| 3541 | int index; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3542 | hda_nid_t dac, pin; |
| 3543 | hda_nid_t sw, vol; |
| 3544 | |
| 3545 | dac = spec->multiout.dac_nids[i]; |
| 3546 | if (!dac) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3547 | continue; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3548 | if (i >= cfg->line_outs) |
| 3549 | pin = spec->multi_io[i - 1].pin; |
| 3550 | else |
| 3551 | pin = cfg->line_out_pins[i]; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3552 | |
| 3553 | sw = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3554 | vol = alc_look_for_out_vol_nid(codec, pin, dac); |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 3555 | name = alc_get_line_out_pfx(spec, i, true, &index); |
Takashi Iwai | 9c4e84d | 2011-08-24 17:27:52 +0200 | [diff] [blame] | 3556 | if (!name || !strcmp(name, "CLFE")) { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3557 | /* Center/LFE */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3558 | err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3559 | if (err < 0) |
| 3560 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3561 | err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3562 | if (err < 0) |
| 3563 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3564 | err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3565 | if (err < 0) |
| 3566 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3567 | err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3568 | if (err < 0) |
| 3569 | return err; |
| 3570 | } else { |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3571 | err = alc_auto_add_stereo_vol(codec, name, index, vol); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3572 | if (err < 0) |
| 3573 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3574 | err = alc_auto_add_stereo_sw(codec, name, index, sw); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3575 | if (err < 0) |
| 3576 | return err; |
| 3577 | } |
| 3578 | } |
| 3579 | return 0; |
| 3580 | } |
| 3581 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3582 | static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin, |
Takashi Iwai | 766ddee | 2011-12-07 16:55:19 +0100 | [diff] [blame] | 3583 | hda_nid_t dac, const char *pfx, |
| 3584 | int cidx) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3585 | { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3586 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3587 | hda_nid_t sw, vol; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3588 | int err; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3589 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3590 | if (!dac) { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3591 | unsigned int val; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3592 | /* the corresponding DAC is already occupied */ |
| 3593 | if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)) |
| 3594 | return 0; /* no way */ |
| 3595 | /* create a switch only */ |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3596 | val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT); |
| 3597 | if (is_ctl_used(spec->sw_ctls, val)) |
| 3598 | return 0; /* already created */ |
| 3599 | mark_ctl_usage(spec->sw_ctls, val); |
Takashi Iwai | 766ddee | 2011-12-07 16:55:19 +0100 | [diff] [blame] | 3600 | return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3601 | } |
| 3602 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3603 | sw = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3604 | vol = alc_look_for_out_vol_nid(codec, pin, dac); |
Takashi Iwai | 766ddee | 2011-12-07 16:55:19 +0100 | [diff] [blame] | 3605 | err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3606 | if (err < 0) |
Takashi Iwai | 24fb917 | 2008-09-02 14:48:20 +0200 | [diff] [blame] | 3607 | return err; |
Takashi Iwai | 766ddee | 2011-12-07 16:55:19 +0100 | [diff] [blame] | 3608 | err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3609 | if (err < 0) |
| 3610 | return err; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3611 | return 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3612 | } |
| 3613 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3614 | static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec, |
| 3615 | unsigned int nums, |
| 3616 | struct hda_ctl_ops *ops) |
| 3617 | { |
| 3618 | struct alc_spec *spec = codec->spec; |
| 3619 | struct hda_bind_ctls **ctlp, *ctl; |
| 3620 | snd_array_init(&spec->bind_ctls, sizeof(ctl), 8); |
| 3621 | ctlp = snd_array_new(&spec->bind_ctls); |
| 3622 | if (!ctlp) |
| 3623 | return NULL; |
| 3624 | ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL); |
| 3625 | *ctlp = ctl; |
| 3626 | if (ctl) |
| 3627 | ctl->ops = ops; |
| 3628 | return ctl; |
| 3629 | } |
| 3630 | |
| 3631 | /* add playback controls for speaker and HP outputs */ |
| 3632 | static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins, |
| 3633 | const hda_nid_t *pins, |
| 3634 | const hda_nid_t *dacs, |
| 3635 | const char *pfx) |
| 3636 | { |
| 3637 | struct alc_spec *spec = codec->spec; |
| 3638 | struct hda_bind_ctls *ctl; |
| 3639 | char name[32]; |
| 3640 | int i, n, err; |
| 3641 | |
| 3642 | if (!num_pins || !pins[0]) |
| 3643 | return 0; |
| 3644 | |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3645 | if (num_pins == 1) { |
| 3646 | hda_nid_t dac = *dacs; |
| 3647 | if (!dac) |
| 3648 | dac = spec->multiout.dac_nids[0]; |
Takashi Iwai | 766ddee | 2011-12-07 16:55:19 +0100 | [diff] [blame] | 3649 | return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0); |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3650 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3651 | |
| 3652 | if (dacs[num_pins - 1]) { |
| 3653 | /* OK, we have a multi-output system with individual volumes */ |
| 3654 | for (i = 0; i < num_pins; i++) { |
Takashi Iwai | 766ddee | 2011-12-07 16:55:19 +0100 | [diff] [blame] | 3655 | if (num_pins >= 3) { |
| 3656 | snprintf(name, sizeof(name), "%s %s", |
| 3657 | pfx, channel_name[i]); |
| 3658 | err = alc_auto_create_extra_out(codec, pins[i], dacs[i], |
| 3659 | name, 0); |
| 3660 | } else { |
| 3661 | err = alc_auto_create_extra_out(codec, pins[i], dacs[i], |
| 3662 | pfx, i); |
| 3663 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3664 | if (err < 0) |
| 3665 | return err; |
| 3666 | } |
| 3667 | return 0; |
| 3668 | } |
| 3669 | |
| 3670 | /* Let's create a bind-controls */ |
| 3671 | ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw); |
| 3672 | if (!ctl) |
| 3673 | return -ENOMEM; |
| 3674 | n = 0; |
| 3675 | for (i = 0; i < num_pins; i++) { |
| 3676 | if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP) |
| 3677 | ctl->values[n++] = |
| 3678 | HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT); |
| 3679 | } |
| 3680 | if (n) { |
| 3681 | snprintf(name, sizeof(name), "%s Playback Switch", pfx); |
| 3682 | err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl); |
| 3683 | if (err < 0) |
| 3684 | return err; |
| 3685 | } |
| 3686 | |
| 3687 | ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol); |
| 3688 | if (!ctl) |
| 3689 | return -ENOMEM; |
| 3690 | n = 0; |
| 3691 | for (i = 0; i < num_pins; i++) { |
| 3692 | hda_nid_t vol; |
| 3693 | if (!pins[i] || !dacs[i]) |
| 3694 | continue; |
| 3695 | vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]); |
| 3696 | if (vol) |
| 3697 | ctl->values[n++] = |
| 3698 | HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT); |
| 3699 | } |
| 3700 | if (n) { |
| 3701 | snprintf(name, sizeof(name), "%s Playback Volume", pfx); |
| 3702 | err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl); |
| 3703 | if (err < 0) |
| 3704 | return err; |
| 3705 | } |
| 3706 | return 0; |
| 3707 | } |
| 3708 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3709 | static int alc_auto_create_hp_out(struct hda_codec *codec) |
| 3710 | { |
| 3711 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3712 | return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs, |
| 3713 | spec->autocfg.hp_pins, |
| 3714 | spec->multiout.hp_out_nid, |
| 3715 | "Headphone"); |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3716 | } |
| 3717 | |
| 3718 | static int alc_auto_create_speaker_out(struct hda_codec *codec) |
| 3719 | { |
| 3720 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3721 | return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs, |
| 3722 | spec->autocfg.speaker_pins, |
| 3723 | spec->multiout.extra_out_nid, |
| 3724 | "Speaker"); |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3725 | } |
| 3726 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3727 | static void alc_auto_set_output_and_unmute(struct hda_codec *codec, |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3728 | hda_nid_t pin, int pin_type, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3729 | hda_nid_t dac) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3730 | { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3731 | int i, num; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3732 | hda_nid_t nid, mix = 0; |
Takashi Iwai | ce503f3 | 2010-07-30 10:37:29 +0200 | [diff] [blame] | 3733 | hda_nid_t srcs[HDA_MAX_CONNECTIONS]; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3734 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3735 | alc_set_pin_output(codec, pin, pin_type); |
| 3736 | nid = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3737 | num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs)); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3738 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 3739 | if (alc_auto_mix_to_dac(codec, srcs[i]) != dac) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3740 | continue; |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3741 | mix = srcs[i]; |
| 3742 | break; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3743 | } |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3744 | if (!mix) |
| 3745 | return; |
| 3746 | |
| 3747 | /* need the manual connection? */ |
| 3748 | if (num > 1) |
| 3749 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i); |
| 3750 | /* unmute mixer widget inputs */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3751 | if (nid_has_mute(codec, mix, HDA_INPUT)) { |
| 3752 | 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] | 3753 | AMP_IN_UNMUTE(0)); |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3754 | 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] | 3755 | AMP_IN_UNMUTE(1)); |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3756 | } |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3757 | /* initialize volume */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3758 | nid = alc_look_for_out_vol_nid(codec, pin, dac); |
| 3759 | if (nid) |
| 3760 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 3761 | AMP_OUT_ZERO); |
Takashi Iwai | 43dea22 | 2011-11-06 11:25:34 +0100 | [diff] [blame] | 3762 | |
| 3763 | /* unmute DAC if it's not assigned to a mixer */ |
| 3764 | nid = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3765 | if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT)) |
| 3766 | snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 3767 | AMP_OUT_ZERO); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3768 | } |
| 3769 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3770 | static void alc_auto_init_multi_out(struct hda_codec *codec) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3771 | { |
| 3772 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3773 | int pin_type = get_pin_type(spec->autocfg.line_out_type); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3774 | int i; |
| 3775 | |
| 3776 | for (i = 0; i <= HDA_SIDE; i++) { |
| 3777 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; |
| 3778 | if (nid) |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3779 | alc_auto_set_output_and_unmute(codec, nid, pin_type, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3780 | spec->multiout.dac_nids[i]); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3781 | } |
| 3782 | } |
| 3783 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3784 | static void alc_auto_init_extra_out(struct hda_codec *codec) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3785 | { |
| 3786 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3787 | int i; |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3788 | hda_nid_t pin, dac; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3789 | |
David Henningsson | 636030e | 2011-10-12 19:26:03 +0200 | [diff] [blame] | 3790 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3791 | if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT) |
| 3792 | break; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3793 | pin = spec->autocfg.hp_pins[i]; |
| 3794 | if (!pin) |
| 3795 | break; |
| 3796 | dac = spec->multiout.hp_out_nid[i]; |
| 3797 | if (!dac) { |
| 3798 | if (i > 0 && spec->multiout.hp_out_nid[0]) |
| 3799 | dac = spec->multiout.hp_out_nid[0]; |
| 3800 | else |
| 3801 | dac = spec->multiout.dac_nids[0]; |
| 3802 | } |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3803 | alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac); |
| 3804 | } |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3805 | for (i = 0; i < spec->autocfg.speaker_outs; i++) { |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3806 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) |
| 3807 | break; |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3808 | pin = spec->autocfg.speaker_pins[i]; |
| 3809 | if (!pin) |
| 3810 | break; |
| 3811 | dac = spec->multiout.extra_out_nid[i]; |
| 3812 | if (!dac) { |
| 3813 | if (i > 0 && spec->multiout.extra_out_nid[0]) |
| 3814 | dac = spec->multiout.extra_out_nid[0]; |
| 3815 | else |
| 3816 | dac = spec->multiout.dac_nids[0]; |
| 3817 | } |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3818 | alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac); |
| 3819 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3820 | } |
| 3821 | |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3822 | /* check whether the given pin can be a multi-io pin */ |
| 3823 | static bool can_be_multiio_pin(struct hda_codec *codec, |
| 3824 | unsigned int location, hda_nid_t nid) |
| 3825 | { |
| 3826 | unsigned int defcfg, caps; |
| 3827 | |
| 3828 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
| 3829 | if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX) |
| 3830 | return false; |
| 3831 | if (location && get_defcfg_location(defcfg) != location) |
| 3832 | return false; |
| 3833 | caps = snd_hda_query_pin_caps(codec, nid); |
| 3834 | if (!(caps & AC_PINCAP_OUT)) |
| 3835 | return false; |
| 3836 | return true; |
| 3837 | } |
| 3838 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3839 | /* |
| 3840 | * multi-io helper |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3841 | * |
| 3842 | * When hardwired is set, try to fill ony hardwired pins, and returns |
| 3843 | * zero if any pins are filled, non-zero if nothing found. |
| 3844 | * When hardwired is off, try to fill possible input pins, and returns |
| 3845 | * the badness value. |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3846 | */ |
| 3847 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3848 | hda_nid_t reference_pin, |
| 3849 | bool hardwired, int offset) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3850 | { |
| 3851 | struct alc_spec *spec = codec->spec; |
| 3852 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3853 | int type, i, j, dacs, num_pins, old_pins; |
| 3854 | unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin); |
| 3855 | unsigned int location = get_defcfg_location(defcfg); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3856 | int badness = 0; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3857 | |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3858 | old_pins = spec->multi_ios; |
| 3859 | if (old_pins >= 2) |
| 3860 | goto end_fill; |
| 3861 | |
| 3862 | num_pins = 0; |
| 3863 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { |
| 3864 | for (i = 0; i < cfg->num_inputs; i++) { |
| 3865 | if (cfg->inputs[i].type != type) |
| 3866 | continue; |
| 3867 | if (can_be_multiio_pin(codec, location, |
| 3868 | cfg->inputs[i].pin)) |
| 3869 | num_pins++; |
| 3870 | } |
| 3871 | } |
| 3872 | if (num_pins < 2) |
| 3873 | goto end_fill; |
| 3874 | |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3875 | dacs = spec->multiout.num_dacs; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3876 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { |
| 3877 | for (i = 0; i < cfg->num_inputs; i++) { |
| 3878 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3879 | hda_nid_t dac = 0; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3880 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3881 | if (cfg->inputs[i].type != type) |
| 3882 | continue; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3883 | if (!can_be_multiio_pin(codec, location, nid)) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3884 | continue; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3885 | for (j = 0; j < spec->multi_ios; j++) { |
| 3886 | if (nid == spec->multi_io[j].pin) |
| 3887 | break; |
| 3888 | } |
| 3889 | if (j < spec->multi_ios) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3890 | continue; |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3891 | |
| 3892 | if (offset && offset + spec->multi_ios < dacs) { |
| 3893 | dac = spec->private_dac_nids[offset + spec->multi_ios]; |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3894 | if (!alc_auto_is_dac_reachable(codec, nid, dac)) |
| 3895 | dac = 0; |
| 3896 | } |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3897 | if (hardwired) |
| 3898 | dac = get_dac_if_single(codec, nid); |
| 3899 | else if (!dac) |
Takashi Iwai | 07b18f6 | 2011-11-10 15:42:54 +0100 | [diff] [blame] | 3900 | dac = alc_auto_look_for_dac(codec, nid); |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3901 | if (!dac) { |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3902 | badness++; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3903 | continue; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3904 | } |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3905 | spec->multi_io[spec->multi_ios].pin = nid; |
| 3906 | spec->multi_io[spec->multi_ios].dac = dac; |
| 3907 | spec->multi_ios++; |
| 3908 | if (spec->multi_ios >= 2) |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3909 | break; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3910 | } |
| 3911 | } |
Takashi Iwai | 276dd70 | 2012-02-17 16:17:03 +0100 | [diff] [blame] | 3912 | end_fill: |
| 3913 | if (badness) |
| 3914 | badness = BAD_MULTI_IO; |
| 3915 | if (old_pins == spec->multi_ios) { |
| 3916 | if (hardwired) |
| 3917 | return 1; /* nothing found */ |
| 3918 | else |
| 3919 | return badness; /* no badness if nothing found */ |
| 3920 | } |
| 3921 | if (!hardwired && spec->multi_ios < 2) { |
| 3922 | spec->multi_ios = old_pins; |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3923 | return badness; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3924 | } |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3925 | |
Takashi Iwai | 1c4a54b | 2012-02-16 16:45:59 +0100 | [diff] [blame] | 3926 | return 0; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3927 | } |
| 3928 | |
| 3929 | static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol, |
| 3930 | struct snd_ctl_elem_info *uinfo) |
| 3931 | { |
| 3932 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3933 | struct alc_spec *spec = codec->spec; |
| 3934 | |
| 3935 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 3936 | uinfo->count = 1; |
| 3937 | uinfo->value.enumerated.items = spec->multi_ios + 1; |
| 3938 | if (uinfo->value.enumerated.item > spec->multi_ios) |
| 3939 | uinfo->value.enumerated.item = spec->multi_ios; |
| 3940 | sprintf(uinfo->value.enumerated.name, "%dch", |
| 3941 | (uinfo->value.enumerated.item + 1) * 2); |
| 3942 | return 0; |
| 3943 | } |
| 3944 | |
| 3945 | static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol, |
| 3946 | struct snd_ctl_elem_value *ucontrol) |
| 3947 | { |
| 3948 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3949 | struct alc_spec *spec = codec->spec; |
| 3950 | ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2; |
| 3951 | return 0; |
| 3952 | } |
| 3953 | |
| 3954 | static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output) |
| 3955 | { |
| 3956 | struct alc_spec *spec = codec->spec; |
| 3957 | hda_nid_t nid = spec->multi_io[idx].pin; |
| 3958 | |
| 3959 | if (!spec->multi_io[idx].ctl_in) |
| 3960 | spec->multi_io[idx].ctl_in = |
| 3961 | snd_hda_codec_read(codec, nid, 0, |
| 3962 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 3963 | if (output) { |
| 3964 | snd_hda_codec_update_cache(codec, nid, 0, |
| 3965 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 3966 | PIN_OUT); |
| 3967 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
| 3968 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
| 3969 | HDA_AMP_MUTE, 0); |
| 3970 | alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac); |
| 3971 | } else { |
| 3972 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
| 3973 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
| 3974 | HDA_AMP_MUTE, HDA_AMP_MUTE); |
| 3975 | snd_hda_codec_update_cache(codec, nid, 0, |
| 3976 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 3977 | spec->multi_io[idx].ctl_in); |
| 3978 | } |
| 3979 | return 0; |
| 3980 | } |
| 3981 | |
| 3982 | static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol, |
| 3983 | struct snd_ctl_elem_value *ucontrol) |
| 3984 | { |
| 3985 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3986 | struct alc_spec *spec = codec->spec; |
| 3987 | int i, ch; |
| 3988 | |
| 3989 | ch = ucontrol->value.enumerated.item[0]; |
| 3990 | if (ch < 0 || ch > spec->multi_ios) |
| 3991 | return -EINVAL; |
| 3992 | if (ch == (spec->ext_channel_count - 1) / 2) |
| 3993 | return 0; |
| 3994 | spec->ext_channel_count = (ch + 1) * 2; |
| 3995 | for (i = 0; i < spec->multi_ios; i++) |
| 3996 | alc_set_multi_io(codec, i, i < ch); |
| 3997 | spec->multiout.max_channels = spec->ext_channel_count; |
Takashi Iwai | 7b1655f | 2011-07-14 15:31:21 +0200 | [diff] [blame] | 3998 | if (spec->need_dac_fix && !spec->const_channel_count) |
| 3999 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 4000 | return 1; |
| 4001 | } |
| 4002 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 4003 | static const struct snd_kcontrol_new alc_auto_channel_mode_enum = { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 4004 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 4005 | .name = "Channel Mode", |
| 4006 | .info = alc_auto_ch_mode_info, |
| 4007 | .get = alc_auto_ch_mode_get, |
| 4008 | .put = alc_auto_ch_mode_put, |
| 4009 | }; |
| 4010 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 4011 | static int alc_auto_add_multi_channel_mode(struct hda_codec *codec) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 4012 | { |
| 4013 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 4014 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 4015 | if (spec->multi_ios > 0) { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 4016 | struct snd_kcontrol_new *knew; |
| 4017 | |
| 4018 | knew = alc_kcontrol_new(spec); |
| 4019 | if (!knew) |
| 4020 | return -ENOMEM; |
| 4021 | *knew = alc_auto_channel_mode_enum; |
| 4022 | knew->name = kstrdup("Channel Mode", GFP_KERNEL); |
| 4023 | if (!knew->name) |
| 4024 | return -ENOMEM; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 4025 | } |
| 4026 | return 0; |
| 4027 | } |
| 4028 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4029 | /* filter out invalid adc_nids (and capsrc_nids) that don't give all |
| 4030 | * active input pins |
| 4031 | */ |
| 4032 | static void alc_remove_invalid_adc_nids(struct hda_codec *codec) |
| 4033 | { |
| 4034 | struct alc_spec *spec = codec->spec; |
| 4035 | const struct hda_input_mux *imux; |
| 4036 | hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)]; |
| 4037 | hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)]; |
| 4038 | int i, n, nums; |
| 4039 | |
| 4040 | imux = spec->input_mux; |
| 4041 | if (!imux) |
| 4042 | return; |
| 4043 | if (spec->dyn_adc_switch) |
| 4044 | return; |
| 4045 | |
| 4046 | nums = 0; |
| 4047 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 4048 | hda_nid_t cap = spec->private_capsrc_nids[n]; |
| 4049 | int num_conns = snd_hda_get_conn_list(codec, cap, NULL); |
| 4050 | for (i = 0; i < imux->num_items; i++) { |
| 4051 | hda_nid_t pin = spec->imux_pins[i]; |
| 4052 | if (pin) { |
| 4053 | if (get_connection_index(codec, cap, pin) < 0) |
| 4054 | break; |
| 4055 | } else if (num_conns <= imux->items[i].index) |
| 4056 | break; |
| 4057 | } |
| 4058 | if (i >= imux->num_items) { |
| 4059 | adc_nids[nums] = spec->private_adc_nids[n]; |
| 4060 | capsrc_nids[nums++] = cap; |
| 4061 | } |
| 4062 | } |
| 4063 | if (!nums) { |
| 4064 | /* check whether ADC-switch is possible */ |
| 4065 | if (!alc_check_dyn_adc_switch(codec)) { |
| 4066 | printk(KERN_WARNING "hda_codec: %s: no valid ADC found;" |
| 4067 | " using fallback 0x%x\n", |
| 4068 | codec->chip_name, spec->private_adc_nids[0]); |
| 4069 | spec->num_adc_nids = 1; |
| 4070 | spec->auto_mic = 0; |
| 4071 | return; |
| 4072 | } |
| 4073 | } else if (nums != spec->num_adc_nids) { |
| 4074 | memcpy(spec->private_adc_nids, adc_nids, |
| 4075 | nums * sizeof(hda_nid_t)); |
| 4076 | memcpy(spec->private_capsrc_nids, capsrc_nids, |
| 4077 | nums * sizeof(hda_nid_t)); |
| 4078 | spec->num_adc_nids = nums; |
| 4079 | } |
| 4080 | |
| 4081 | if (spec->auto_mic) |
| 4082 | alc_auto_mic_check_imux(codec); /* check auto-mic setups */ |
| 4083 | else if (spec->input_mux->num_items == 1) |
| 4084 | spec->num_adc_nids = 1; /* reduce to a single ADC */ |
| 4085 | } |
| 4086 | |
| 4087 | /* |
| 4088 | * initialize ADC paths |
| 4089 | */ |
| 4090 | static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx) |
| 4091 | { |
| 4092 | struct alc_spec *spec = codec->spec; |
| 4093 | hda_nid_t nid; |
| 4094 | |
| 4095 | nid = spec->adc_nids[adc_idx]; |
| 4096 | /* mute ADC */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 4097 | if (nid_has_mute(codec, nid, HDA_INPUT)) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4098 | snd_hda_codec_write(codec, nid, 0, |
| 4099 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 4100 | AMP_IN_MUTE(0)); |
| 4101 | return; |
| 4102 | } |
| 4103 | if (!spec->capsrc_nids) |
| 4104 | return; |
| 4105 | nid = spec->capsrc_nids[adc_idx]; |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 4106 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4107 | snd_hda_codec_write(codec, nid, 0, |
| 4108 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 4109 | AMP_OUT_MUTE); |
| 4110 | } |
| 4111 | |
| 4112 | static void alc_auto_init_input_src(struct hda_codec *codec) |
| 4113 | { |
| 4114 | struct alc_spec *spec = codec->spec; |
| 4115 | int c, nums; |
| 4116 | |
| 4117 | for (c = 0; c < spec->num_adc_nids; c++) |
| 4118 | alc_auto_init_adc(codec, c); |
| 4119 | if (spec->dyn_adc_switch) |
| 4120 | nums = 1; |
| 4121 | else |
| 4122 | nums = spec->num_adc_nids; |
| 4123 | for (c = 0; c < nums; c++) |
| 4124 | alc_mux_select(codec, 0, spec->cur_mux[c], true); |
| 4125 | } |
| 4126 | |
| 4127 | /* add mic boosts if needed */ |
| 4128 | static int alc_auto_add_mic_boost(struct hda_codec *codec) |
| 4129 | { |
| 4130 | struct alc_spec *spec = codec->spec; |
| 4131 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 4132 | int i, err; |
| 4133 | int type_idx = 0; |
| 4134 | hda_nid_t nid; |
| 4135 | const char *prev_label = NULL; |
| 4136 | |
| 4137 | for (i = 0; i < cfg->num_inputs; i++) { |
| 4138 | if (cfg->inputs[i].type > AUTO_PIN_MIC) |
| 4139 | break; |
| 4140 | nid = cfg->inputs[i].pin; |
| 4141 | if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { |
| 4142 | const char *label; |
| 4143 | char boost_label[32]; |
| 4144 | |
| 4145 | label = hda_get_autocfg_input_label(codec, cfg, i); |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 4146 | if (spec->shared_mic_hp && !strcmp(label, "Misc")) |
| 4147 | label = "Headphone Mic"; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4148 | if (prev_label && !strcmp(label, prev_label)) |
| 4149 | type_idx++; |
| 4150 | else |
| 4151 | type_idx = 0; |
| 4152 | prev_label = label; |
| 4153 | |
| 4154 | snprintf(boost_label, sizeof(boost_label), |
| 4155 | "%s Boost Volume", label); |
| 4156 | err = add_control(spec, ALC_CTL_WIDGET_VOL, |
| 4157 | boost_label, type_idx, |
| 4158 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT)); |
| 4159 | if (err < 0) |
| 4160 | return err; |
| 4161 | } |
| 4162 | } |
| 4163 | return 0; |
| 4164 | } |
| 4165 | |
| 4166 | /* select or unmute the given capsrc route */ |
| 4167 | static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap, |
| 4168 | int idx) |
| 4169 | { |
| 4170 | if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) { |
| 4171 | snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx, |
| 4172 | HDA_AMP_MUTE, 0); |
| 4173 | } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) { |
| 4174 | snd_hda_codec_write_cache(codec, cap, 0, |
| 4175 | AC_VERB_SET_CONNECT_SEL, idx); |
| 4176 | } |
| 4177 | } |
| 4178 | |
| 4179 | /* set the default connection to that pin */ |
| 4180 | static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin) |
| 4181 | { |
| 4182 | struct alc_spec *spec = codec->spec; |
| 4183 | int i; |
| 4184 | |
| 4185 | if (!pin) |
| 4186 | return 0; |
| 4187 | for (i = 0; i < spec->num_adc_nids; i++) { |
Takashi Iwai | 6107159 | 2011-11-23 07:52:15 +0100 | [diff] [blame] | 4188 | hda_nid_t cap = get_capsrc(spec, i); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4189 | int idx; |
| 4190 | |
| 4191 | idx = get_connection_index(codec, cap, pin); |
| 4192 | if (idx < 0) |
| 4193 | continue; |
| 4194 | select_or_unmute_capsrc(codec, cap, idx); |
| 4195 | return i; /* return the found index */ |
| 4196 | } |
| 4197 | return -1; /* not found */ |
| 4198 | } |
| 4199 | |
| 4200 | /* initialize some special cases for input sources */ |
| 4201 | static void alc_init_special_input_src(struct hda_codec *codec) |
| 4202 | { |
| 4203 | struct alc_spec *spec = codec->spec; |
| 4204 | int i; |
| 4205 | |
| 4206 | for (i = 0; i < spec->autocfg.num_inputs; i++) |
| 4207 | init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin); |
| 4208 | } |
| 4209 | |
| 4210 | /* assign appropriate capture mixers */ |
| 4211 | static void set_capture_mixer(struct hda_codec *codec) |
| 4212 | { |
| 4213 | struct alc_spec *spec = codec->spec; |
| 4214 | static const struct snd_kcontrol_new *caps[2][3] = { |
| 4215 | { alc_capture_mixer_nosrc1, |
| 4216 | alc_capture_mixer_nosrc2, |
| 4217 | alc_capture_mixer_nosrc3 }, |
| 4218 | { alc_capture_mixer1, |
| 4219 | alc_capture_mixer2, |
| 4220 | alc_capture_mixer3 }, |
| 4221 | }; |
| 4222 | |
| 4223 | /* check whether either of ADC or MUX has a volume control */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 4224 | if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4225 | if (!spec->capsrc_nids) |
| 4226 | return; /* no volume */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 4227 | if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT)) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4228 | return; /* no volume in capsrc, too */ |
| 4229 | spec->vol_in_capsrc = 1; |
| 4230 | } |
| 4231 | |
| 4232 | if (spec->num_adc_nids > 0) { |
| 4233 | int mux = 0; |
| 4234 | int num_adcs = 0; |
| 4235 | |
| 4236 | if (spec->input_mux && spec->input_mux->num_items > 1) |
| 4237 | mux = 1; |
| 4238 | if (spec->auto_mic) { |
| 4239 | num_adcs = 1; |
| 4240 | mux = 0; |
| 4241 | } else if (spec->dyn_adc_switch) |
| 4242 | num_adcs = 1; |
| 4243 | if (!num_adcs) { |
| 4244 | if (spec->num_adc_nids > 3) |
| 4245 | spec->num_adc_nids = 3; |
| 4246 | else if (!spec->num_adc_nids) |
| 4247 | return; |
| 4248 | num_adcs = spec->num_adc_nids; |
| 4249 | } |
| 4250 | spec->cap_mixer = caps[mux][num_adcs - 1]; |
| 4251 | } |
| 4252 | } |
| 4253 | |
| 4254 | /* |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 4255 | * standard auto-parser initializations |
| 4256 | */ |
| 4257 | static void alc_auto_init_std(struct hda_codec *codec) |
| 4258 | { |
| 4259 | struct alc_spec *spec = codec->spec; |
| 4260 | alc_auto_init_multi_out(codec); |
| 4261 | alc_auto_init_extra_out(codec); |
| 4262 | alc_auto_init_analog_input(codec); |
| 4263 | alc_auto_init_input_src(codec); |
| 4264 | alc_auto_init_digital(codec); |
| 4265 | if (spec->unsol_event) |
| 4266 | alc_inithook(codec); |
| 4267 | } |
| 4268 | |
| 4269 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4270 | * Digital-beep handlers |
| 4271 | */ |
| 4272 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
| 4273 | #define set_beep_amp(spec, nid, idx, dir) \ |
| 4274 | ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir)) |
| 4275 | |
| 4276 | static const struct snd_pci_quirk beep_white_list[] = { |
| 4277 | SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1), |
| 4278 | SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1), |
| 4279 | SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1), |
| 4280 | SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1), |
| 4281 | SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1), |
| 4282 | {} |
| 4283 | }; |
| 4284 | |
| 4285 | static inline int has_cdefine_beep(struct hda_codec *codec) |
| 4286 | { |
| 4287 | struct alc_spec *spec = codec->spec; |
| 4288 | const struct snd_pci_quirk *q; |
| 4289 | q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list); |
| 4290 | if (q) |
| 4291 | return q->value; |
| 4292 | return spec->cdefine.enable_pcbeep; |
| 4293 | } |
| 4294 | #else |
| 4295 | #define set_beep_amp(spec, nid, idx, dir) /* NOP */ |
| 4296 | #define has_cdefine_beep(codec) 0 |
| 4297 | #endif |
| 4298 | |
| 4299 | /* parse the BIOS configuration and set up the alc_spec */ |
| 4300 | /* return 1 if successful, 0 if the proper config is not found, |
| 4301 | * or a negative error code |
| 4302 | */ |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4303 | static int alc_parse_auto_config(struct hda_codec *codec, |
| 4304 | const hda_nid_t *ignore_nids, |
| 4305 | const hda_nid_t *ssid_nids) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4306 | { |
| 4307 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 4308 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4309 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4310 | |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 4311 | err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids, |
| 4312 | spec->parse_flags); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4313 | if (err < 0) |
| 4314 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 4315 | if (!cfg->line_outs) { |
| 4316 | if (cfg->dig_outs || cfg->dig_in_pin) { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4317 | spec->multiout.max_channels = 2; |
| 4318 | spec->no_analog = 1; |
| 4319 | goto dig_only; |
| 4320 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4321 | return 0; /* can't find valid BIOS pin config */ |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4322 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 4323 | |
Takashi Iwai | 0650367 | 2011-10-06 08:27:19 +0200 | [diff] [blame] | 4324 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && |
| 4325 | cfg->line_outs <= cfg->hp_outs) { |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 4326 | /* use HP as primary out */ |
| 4327 | cfg->speaker_outs = cfg->line_outs; |
| 4328 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 4329 | sizeof(cfg->speaker_pins)); |
| 4330 | cfg->line_outs = cfg->hp_outs; |
| 4331 | memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins)); |
| 4332 | cfg->hp_outs = 0; |
| 4333 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); |
| 4334 | cfg->line_out_type = AUTO_PIN_HP_OUT; |
| 4335 | } |
| 4336 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4337 | err = alc_auto_fill_dac_nids(codec); |
| 4338 | if (err < 0) |
| 4339 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 4340 | err = alc_auto_add_multi_channel_mode(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4341 | if (err < 0) |
| 4342 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 4343 | err = alc_auto_create_multi_out_ctls(codec, cfg); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4344 | if (err < 0) |
| 4345 | return err; |
| 4346 | err = alc_auto_create_hp_out(codec); |
| 4347 | if (err < 0) |
| 4348 | return err; |
| 4349 | err = alc_auto_create_speaker_out(codec); |
| 4350 | if (err < 0) |
| 4351 | return err; |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 4352 | err = alc_auto_create_shared_input(codec); |
| 4353 | if (err < 0) |
| 4354 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4355 | err = alc_auto_create_input_ctls(codec); |
| 4356 | if (err < 0) |
| 4357 | return err; |
| 4358 | |
| 4359 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 4360 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4361 | dig_only: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4362 | alc_auto_parse_digital(codec); |
| 4363 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4364 | if (!spec->no_analog) |
| 4365 | alc_remove_invalid_adc_nids(codec); |
| 4366 | |
| 4367 | if (ssid_nids) |
| 4368 | alc_ssid_check(codec, ssid_nids); |
| 4369 | |
| 4370 | if (!spec->no_analog) { |
| 4371 | alc_auto_check_switches(codec); |
| 4372 | err = alc_auto_add_mic_boost(codec); |
| 4373 | if (err < 0) |
| 4374 | return err; |
| 4375 | } |
| 4376 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4377 | if (spec->kctls.list) |
| 4378 | add_mixer(spec, spec->kctls.list); |
| 4379 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4380 | return 1; |
| 4381 | } |
| 4382 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4383 | static int alc880_parse_auto_config(struct hda_codec *codec) |
| 4384 | { |
| 4385 | static const hda_nid_t alc880_ignore[] = { 0x1d, 0 }; |
| 4386 | static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 4387 | return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids); |
| 4388 | } |
| 4389 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4390 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4391 | static const struct hda_amp_list alc880_loopbacks[] = { |
| 4392 | { 0x0b, HDA_INPUT, 0 }, |
| 4393 | { 0x0b, HDA_INPUT, 1 }, |
| 4394 | { 0x0b, HDA_INPUT, 2 }, |
| 4395 | { 0x0b, HDA_INPUT, 3 }, |
| 4396 | { 0x0b, HDA_INPUT, 4 }, |
| 4397 | { } /* end */ |
| 4398 | }; |
| 4399 | #endif |
| 4400 | |
| 4401 | /* |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4402 | * ALC880 fix-ups |
| 4403 | */ |
| 4404 | enum { |
| 4405 | ALC880_FIXUP_GPIO2, |
| 4406 | ALC880_FIXUP_MEDION_RIM, |
Takashi Iwai | dc6af52 | 2012-02-17 16:18:59 +0100 | [diff] [blame] | 4407 | ALC880_FIXUP_LG, |
Takashi Iwai | f02aab5 | 2012-02-17 16:33:56 +0100 | [diff] [blame^] | 4408 | ALC880_FIXUP_W810, |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4409 | }; |
| 4410 | |
| 4411 | static const struct alc_fixup alc880_fixups[] = { |
| 4412 | [ALC880_FIXUP_GPIO2] = { |
| 4413 | .type = ALC_FIXUP_VERBS, |
| 4414 | .v.verbs = alc_gpio2_init_verbs, |
| 4415 | }, |
| 4416 | [ALC880_FIXUP_MEDION_RIM] = { |
| 4417 | .type = ALC_FIXUP_VERBS, |
| 4418 | .v.verbs = (const struct hda_verb[]) { |
| 4419 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4420 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 }, |
| 4421 | { } |
| 4422 | }, |
| 4423 | .chained = true, |
| 4424 | .chain_id = ALC880_FIXUP_GPIO2, |
| 4425 | }, |
Takashi Iwai | dc6af52 | 2012-02-17 16:18:59 +0100 | [diff] [blame] | 4426 | [ALC880_FIXUP_LG] = { |
| 4427 | .type = ALC_FIXUP_PINS, |
| 4428 | .v.pins = (const struct alc_pincfg[]) { |
| 4429 | /* disable bogus unused pins */ |
| 4430 | { 0x16, 0x411111f0 }, |
| 4431 | { 0x18, 0x411111f0 }, |
| 4432 | { 0x1a, 0x411111f0 }, |
| 4433 | { } |
| 4434 | } |
| 4435 | }, |
Takashi Iwai | f02aab5 | 2012-02-17 16:33:56 +0100 | [diff] [blame^] | 4436 | [ALC880_FIXUP_W810] = { |
| 4437 | .type = ALC_FIXUP_PINS, |
| 4438 | .v.pins = (const struct alc_pincfg[]) { |
| 4439 | /* disable bogus unused pins */ |
| 4440 | { 0x17, 0x411111f0 }, |
| 4441 | { } |
| 4442 | }, |
| 4443 | .chained = true, |
| 4444 | .chain_id = ALC880_FIXUP_GPIO2, |
| 4445 | }, |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4446 | }; |
| 4447 | |
| 4448 | static const struct snd_pci_quirk alc880_fixup_tbl[] = { |
Takashi Iwai | f02aab5 | 2012-02-17 16:33:56 +0100 | [diff] [blame^] | 4449 | SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810), |
| 4450 | SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810), |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4451 | SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM), |
Takashi Iwai | dc6af52 | 2012-02-17 16:18:59 +0100 | [diff] [blame] | 4452 | SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG), |
| 4453 | SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG), |
| 4454 | SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG), |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4455 | {} |
| 4456 | }; |
| 4457 | |
| 4458 | |
| 4459 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4460 | * board setups |
| 4461 | */ |
| 4462 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4463 | #define alc_board_config \ |
| 4464 | snd_hda_check_board_config |
| 4465 | #define alc_board_codec_sid_config \ |
| 4466 | snd_hda_check_board_codec_sid_config |
| 4467 | #include "alc_quirks.c" |
| 4468 | #else |
| 4469 | #define alc_board_config(codec, nums, models, tbl) -1 |
| 4470 | #define alc_board_codec_sid_config(codec, nums, models, tbl) -1 |
| 4471 | #define setup_preset(codec, x) /* NOP */ |
| 4472 | #endif |
| 4473 | |
| 4474 | /* |
| 4475 | * OK, here we have finally the patch for ALC880 |
| 4476 | */ |
| 4477 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4478 | #include "alc880_quirks.c" |
| 4479 | #endif |
| 4480 | |
| 4481 | static int patch_alc880(struct hda_codec *codec) |
| 4482 | { |
| 4483 | struct alc_spec *spec; |
| 4484 | int board_config; |
| 4485 | int err; |
| 4486 | |
| 4487 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4488 | if (spec == NULL) |
| 4489 | return -ENOMEM; |
| 4490 | |
| 4491 | codec->spec = spec; |
| 4492 | |
| 4493 | spec->mixer_nid = 0x0b; |
Takashi Iwai | 7b1655f | 2011-07-14 15:31:21 +0200 | [diff] [blame] | 4494 | spec->need_dac_fix = 1; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4495 | |
| 4496 | board_config = alc_board_config(codec, ALC880_MODEL_LAST, |
| 4497 | alc880_models, alc880_cfg_tbl); |
| 4498 | if (board_config < 0) { |
| 4499 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 4500 | codec->chip_name); |
| 4501 | board_config = ALC_MODEL_AUTO; |
| 4502 | } |
| 4503 | |
| 4504 | if (board_config == ALC_MODEL_AUTO) { |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4505 | alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups); |
| 4506 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 4507 | } |
| 4508 | |
| 4509 | if (board_config == ALC_MODEL_AUTO) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4510 | /* automatic parse from the BIOS config */ |
| 4511 | err = alc880_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4512 | if (err < 0) |
| 4513 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4514 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4515 | else if (!err) { |
| 4516 | printk(KERN_INFO |
| 4517 | "hda_codec: Cannot set up configuration " |
| 4518 | "from BIOS. Using 3-stack mode...\n"); |
| 4519 | board_config = ALC880_3ST; |
| 4520 | } |
| 4521 | #endif |
| 4522 | } |
| 4523 | |
David Henningsson | fde48a1 | 2011-12-09 18:27:42 +0800 | [diff] [blame] | 4524 | if (board_config != ALC_MODEL_AUTO) { |
| 4525 | spec->vmaster_nid = 0x0c; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4526 | setup_preset(codec, &alc880_presets[board_config]); |
David Henningsson | fde48a1 | 2011-12-09 18:27:42 +0800 | [diff] [blame] | 4527 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4528 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4529 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4530 | alc_auto_fill_adc_caps(codec); |
| 4531 | alc_rebuild_imux_for_auto_mic(codec); |
| 4532 | alc_remove_invalid_adc_nids(codec); |
| 4533 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4534 | |
| 4535 | if (!spec->no_analog && !spec->cap_mixer) |
| 4536 | set_capture_mixer(codec); |
| 4537 | |
| 4538 | if (!spec->no_analog) { |
| 4539 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4540 | if (err < 0) |
| 4541 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4542 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 4543 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4544 | |
Takashi Iwai | ee3b296 | 2011-11-15 14:26:54 +0100 | [diff] [blame] | 4545 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4546 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4547 | codec->patch_ops = alc_patch_ops; |
| 4548 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 4549 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 4550 | else |
| 4551 | codec->patch_ops.build_controls = __alc_build_controls; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4552 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4553 | if (!spec->loopback.amplist) |
| 4554 | spec->loopback.amplist = alc880_loopbacks; |
| 4555 | #endif |
| 4556 | |
| 4557 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4558 | |
| 4559 | error: |
| 4560 | alc_free(codec); |
| 4561 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | |
| 4565 | /* |
| 4566 | * ALC260 support |
| 4567 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4568 | static int alc260_parse_auto_config(struct hda_codec *codec) |
| 4569 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4570 | static const hda_nid_t alc260_ignore[] = { 0x17, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4571 | static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 }; |
| 4572 | return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4573 | } |
| 4574 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4575 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4576 | static const struct hda_amp_list alc260_loopbacks[] = { |
| 4577 | { 0x07, HDA_INPUT, 0 }, |
| 4578 | { 0x07, HDA_INPUT, 1 }, |
| 4579 | { 0x07, HDA_INPUT, 2 }, |
| 4580 | { 0x07, HDA_INPUT, 3 }, |
| 4581 | { 0x07, HDA_INPUT, 4 }, |
| 4582 | { } /* end */ |
| 4583 | }; |
| 4584 | #endif |
| 4585 | |
| 4586 | /* |
| 4587 | * Pin config fixes |
| 4588 | */ |
| 4589 | enum { |
Takashi Iwai | ca8f042 | 2012-02-16 11:51:19 +0100 | [diff] [blame] | 4590 | ALC260_FIXUP_HP_DC5750, |
| 4591 | ALC260_FIXUP_HP_PIN_0F, |
| 4592 | ALC260_FIXUP_COEF, |
Takashi Iwai | 15317ab | 2012-02-16 12:02:53 +0100 | [diff] [blame] | 4593 | ALC260_FIXUP_GPIO1, |
Takashi Iwai | 20f7d92 | 2012-02-16 12:35:16 +0100 | [diff] [blame] | 4594 | ALC260_FIXUP_GPIO1_TOGGLE, |
| 4595 | ALC260_FIXUP_REPLACER, |
Takashi Iwai | 0a1c4fa | 2012-02-16 12:42:30 +0100 | [diff] [blame] | 4596 | ALC260_FIXUP_HP_B1900, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4597 | }; |
| 4598 | |
Takashi Iwai | 20f7d92 | 2012-02-16 12:35:16 +0100 | [diff] [blame] | 4599 | static void alc260_gpio1_automute(struct hda_codec *codec) |
| 4600 | { |
| 4601 | struct alc_spec *spec = codec->spec; |
| 4602 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, |
| 4603 | spec->hp_jack_present); |
| 4604 | } |
| 4605 | |
| 4606 | static void alc260_fixup_gpio1_toggle(struct hda_codec *codec, |
| 4607 | const struct alc_fixup *fix, int action) |
| 4608 | { |
| 4609 | struct alc_spec *spec = codec->spec; |
| 4610 | if (action == ALC_FIXUP_ACT_PROBE) { |
| 4611 | /* although the machine has only one output pin, we need to |
| 4612 | * toggle GPIO1 according to the jack state |
| 4613 | */ |
| 4614 | spec->automute_hook = alc260_gpio1_automute; |
| 4615 | spec->detect_hp = 1; |
| 4616 | spec->automute_speaker = 1; |
| 4617 | spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */ |
| 4618 | snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT); |
| 4619 | spec->unsol_event = alc_sku_unsol_event; |
| 4620 | add_verb(codec->spec, alc_gpio1_init_verbs); |
| 4621 | } |
| 4622 | } |
| 4623 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4624 | static const struct alc_fixup alc260_fixups[] = { |
Takashi Iwai | ca8f042 | 2012-02-16 11:51:19 +0100 | [diff] [blame] | 4625 | [ALC260_FIXUP_HP_DC5750] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4626 | .type = ALC_FIXUP_PINS, |
| 4627 | .v.pins = (const struct alc_pincfg[]) { |
| 4628 | { 0x11, 0x90130110 }, /* speaker */ |
| 4629 | { } |
| 4630 | } |
| 4631 | }, |
Takashi Iwai | ca8f042 | 2012-02-16 11:51:19 +0100 | [diff] [blame] | 4632 | [ALC260_FIXUP_HP_PIN_0F] = { |
| 4633 | .type = ALC_FIXUP_PINS, |
| 4634 | .v.pins = (const struct alc_pincfg[]) { |
| 4635 | { 0x0f, 0x01214000 }, /* HP */ |
| 4636 | { } |
| 4637 | } |
| 4638 | }, |
| 4639 | [ALC260_FIXUP_COEF] = { |
| 4640 | .type = ALC_FIXUP_VERBS, |
| 4641 | .v.verbs = (const struct hda_verb[]) { |
| 4642 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4643 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 }, |
| 4644 | { } |
| 4645 | }, |
| 4646 | .chained = true, |
| 4647 | .chain_id = ALC260_FIXUP_HP_PIN_0F, |
| 4648 | }, |
Takashi Iwai | 15317ab | 2012-02-16 12:02:53 +0100 | [diff] [blame] | 4649 | [ALC260_FIXUP_GPIO1] = { |
| 4650 | .type = ALC_FIXUP_VERBS, |
| 4651 | .v.verbs = alc_gpio1_init_verbs, |
| 4652 | }, |
Takashi Iwai | 20f7d92 | 2012-02-16 12:35:16 +0100 | [diff] [blame] | 4653 | [ALC260_FIXUP_GPIO1_TOGGLE] = { |
| 4654 | .type = ALC_FIXUP_FUNC, |
| 4655 | .v.func = alc260_fixup_gpio1_toggle, |
| 4656 | .chained = true, |
| 4657 | .chain_id = ALC260_FIXUP_HP_PIN_0F, |
| 4658 | }, |
| 4659 | [ALC260_FIXUP_REPLACER] = { |
| 4660 | .type = ALC_FIXUP_VERBS, |
| 4661 | .v.verbs = (const struct hda_verb[]) { |
| 4662 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4663 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, |
| 4664 | { } |
| 4665 | }, |
| 4666 | .chained = true, |
| 4667 | .chain_id = ALC260_FIXUP_GPIO1_TOGGLE, |
| 4668 | }, |
Takashi Iwai | 0a1c4fa | 2012-02-16 12:42:30 +0100 | [diff] [blame] | 4669 | [ALC260_FIXUP_HP_B1900] = { |
| 4670 | .type = ALC_FIXUP_FUNC, |
| 4671 | .v.func = alc260_fixup_gpio1_toggle, |
| 4672 | .chained = true, |
| 4673 | .chain_id = ALC260_FIXUP_COEF, |
| 4674 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4675 | }; |
| 4676 | |
| 4677 | static const struct snd_pci_quirk alc260_fixup_tbl[] = { |
Takashi Iwai | 15317ab | 2012-02-16 12:02:53 +0100 | [diff] [blame] | 4678 | SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1), |
Takashi Iwai | ca8f042 | 2012-02-16 11:51:19 +0100 | [diff] [blame] | 4679 | SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF), |
Takashi Iwai | 15317ab | 2012-02-16 12:02:53 +0100 | [diff] [blame] | 4680 | SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1), |
Takashi Iwai | ca8f042 | 2012-02-16 11:51:19 +0100 | [diff] [blame] | 4681 | SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750), |
Takashi Iwai | 0a1c4fa | 2012-02-16 12:42:30 +0100 | [diff] [blame] | 4682 | SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900), |
Takashi Iwai | b1f5808 | 2012-02-16 12:45:03 +0100 | [diff] [blame] | 4683 | SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1), |
Takashi Iwai | 20f7d92 | 2012-02-16 12:35:16 +0100 | [diff] [blame] | 4684 | SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER), |
Takashi Iwai | ca8f042 | 2012-02-16 11:51:19 +0100 | [diff] [blame] | 4685 | SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4686 | {} |
| 4687 | }; |
| 4688 | |
| 4689 | /* |
| 4690 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4691 | static int patch_alc260(struct hda_codec *codec) |
| 4692 | { |
| 4693 | struct alc_spec *spec; |
Takashi Iwai | c3c2c9e | 2012-02-16 12:59:55 +0100 | [diff] [blame] | 4694 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4695 | |
| 4696 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4697 | if (spec == NULL) |
| 4698 | return -ENOMEM; |
| 4699 | |
| 4700 | codec->spec = spec; |
| 4701 | |
| 4702 | spec->mixer_nid = 0x07; |
| 4703 | |
Takashi Iwai | c3c2c9e | 2012-02-16 12:59:55 +0100 | [diff] [blame] | 4704 | alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); |
| 4705 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4706 | |
Takashi Iwai | c3c2c9e | 2012-02-16 12:59:55 +0100 | [diff] [blame] | 4707 | /* automatic parse from the BIOS config */ |
| 4708 | err = alc260_parse_auto_config(codec); |
| 4709 | if (err < 0) |
| 4710 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4711 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4712 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4713 | alc_auto_fill_adc_caps(codec); |
| 4714 | alc_rebuild_imux_for_auto_mic(codec); |
| 4715 | alc_remove_invalid_adc_nids(codec); |
| 4716 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4717 | |
| 4718 | if (!spec->no_analog && !spec->cap_mixer) |
| 4719 | set_capture_mixer(codec); |
| 4720 | |
| 4721 | if (!spec->no_analog) { |
| 4722 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4723 | if (err < 0) |
| 4724 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4725 | set_beep_amp(spec, 0x07, 0x05, HDA_INPUT); |
| 4726 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4727 | |
| 4728 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4729 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4730 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | c3c2c9e | 2012-02-16 12:59:55 +0100 | [diff] [blame] | 4731 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4732 | spec->shutup = alc_eapd_shutup; |
| 4733 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4734 | if (!spec->loopback.amplist) |
| 4735 | spec->loopback.amplist = alc260_loopbacks; |
| 4736 | #endif |
| 4737 | |
| 4738 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4739 | |
| 4740 | error: |
| 4741 | alc_free(codec); |
| 4742 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4743 | } |
| 4744 | |
| 4745 | |
| 4746 | /* |
| 4747 | * ALC882/883/885/888/889 support |
| 4748 | * |
| 4749 | * ALC882 is almost identical with ALC880 but has cleaner and more flexible |
| 4750 | * configuration. Each pin widget can choose any input DACs and a mixer. |
| 4751 | * Each ADC is connected from a mixer of all inputs. This makes possible |
| 4752 | * 6-channel independent captures. |
| 4753 | * |
| 4754 | * In addition, an independent DAC for the multi-playback (not used in this |
| 4755 | * driver yet). |
| 4756 | */ |
| 4757 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4758 | #define alc882_loopbacks alc880_loopbacks |
| 4759 | #endif |
| 4760 | |
| 4761 | /* |
| 4762 | * Pin config fixes |
| 4763 | */ |
| 4764 | enum { |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4765 | ALC882_FIXUP_ABIT_AW9D_MAX, |
| 4766 | ALC882_FIXUP_LENOVO_Y530, |
| 4767 | ALC882_FIXUP_PB_M5210, |
| 4768 | ALC882_FIXUP_ACER_ASPIRE_7736, |
| 4769 | ALC882_FIXUP_ASUS_W90V, |
| 4770 | ALC889_FIXUP_VAIO_TT, |
Takashi Iwai | 0e7cc2e | 2011-11-09 12:42:48 +0100 | [diff] [blame] | 4771 | ALC888_FIXUP_EEE1601, |
Takashi Iwai | 177943a3 | 2011-11-09 12:55:18 +0100 | [diff] [blame] | 4772 | ALC882_FIXUP_EAPD, |
Takashi Iwai | 7a6069b | 2011-11-09 15:22:01 +0100 | [diff] [blame] | 4773 | ALC883_FIXUP_EAPD, |
Takashi Iwai | 8812c4f | 2011-11-09 17:39:15 +0100 | [diff] [blame] | 4774 | ALC883_FIXUP_ACER_EAPD, |
Takashi Iwai | eb844d5 | 2011-11-09 18:03:07 +0100 | [diff] [blame] | 4775 | ALC882_FIXUP_GPIO3, |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 4776 | ALC889_FIXUP_COEF, |
| 4777 | ALC882_FIXUP_ASUS_W2JC, |
Takashi Iwai | c3e837b | 2011-11-10 16:01:47 +0100 | [diff] [blame] | 4778 | ALC882_FIXUP_ACER_ASPIRE_4930G, |
| 4779 | ALC882_FIXUP_ACER_ASPIRE_8930G, |
| 4780 | ALC882_FIXUP_ASPIRE_8930G_VERBS, |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 4781 | ALC885_FIXUP_MACPRO_GPIO, |
Takashi Iwai | 02a237b | 2012-02-13 15:25:07 +0100 | [diff] [blame] | 4782 | ALC889_FIXUP_DAC_ROUTE, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4783 | }; |
| 4784 | |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 4785 | static void alc889_fixup_coef(struct hda_codec *codec, |
| 4786 | const struct alc_fixup *fix, int action) |
| 4787 | { |
| 4788 | if (action != ALC_FIXUP_ACT_INIT) |
| 4789 | return; |
| 4790 | alc889_coef_init(codec); |
| 4791 | } |
| 4792 | |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 4793 | /* toggle speaker-output according to the hp-jack state */ |
| 4794 | static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted) |
| 4795 | { |
| 4796 | unsigned int gpiostate, gpiomask, gpiodir; |
| 4797 | |
| 4798 | gpiostate = snd_hda_codec_read(codec, codec->afg, 0, |
| 4799 | AC_VERB_GET_GPIO_DATA, 0); |
| 4800 | |
| 4801 | if (!muted) |
| 4802 | gpiostate |= (1 << pin); |
| 4803 | else |
| 4804 | gpiostate &= ~(1 << pin); |
| 4805 | |
| 4806 | gpiomask = snd_hda_codec_read(codec, codec->afg, 0, |
| 4807 | AC_VERB_GET_GPIO_MASK, 0); |
| 4808 | gpiomask |= (1 << pin); |
| 4809 | |
| 4810 | gpiodir = snd_hda_codec_read(codec, codec->afg, 0, |
| 4811 | AC_VERB_GET_GPIO_DIRECTION, 0); |
| 4812 | gpiodir |= (1 << pin); |
| 4813 | |
| 4814 | |
| 4815 | snd_hda_codec_write(codec, codec->afg, 0, |
| 4816 | AC_VERB_SET_GPIO_MASK, gpiomask); |
| 4817 | snd_hda_codec_write(codec, codec->afg, 0, |
| 4818 | AC_VERB_SET_GPIO_DIRECTION, gpiodir); |
| 4819 | |
| 4820 | msleep(1); |
| 4821 | |
| 4822 | snd_hda_codec_write(codec, codec->afg, 0, |
| 4823 | AC_VERB_SET_GPIO_DATA, gpiostate); |
| 4824 | } |
| 4825 | |
| 4826 | /* set up GPIO at initialization */ |
| 4827 | static void alc885_fixup_macpro_gpio(struct hda_codec *codec, |
| 4828 | const struct alc_fixup *fix, int action) |
| 4829 | { |
| 4830 | if (action != ALC_FIXUP_ACT_INIT) |
| 4831 | return; |
| 4832 | alc882_gpio_mute(codec, 0, 0); |
| 4833 | alc882_gpio_mute(codec, 1, 0); |
| 4834 | } |
| 4835 | |
Takashi Iwai | 02a237b | 2012-02-13 15:25:07 +0100 | [diff] [blame] | 4836 | /* Fix the connection of some pins for ALC889: |
| 4837 | * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't |
| 4838 | * work correctly (bko#42740) |
| 4839 | */ |
| 4840 | static void alc889_fixup_dac_route(struct hda_codec *codec, |
| 4841 | const struct alc_fixup *fix, int action) |
| 4842 | { |
| 4843 | if (action == ALC_FIXUP_ACT_PRE_PROBE) { |
| 4844 | hda_nid_t conn1[2] = { 0x0c, 0x0d }; |
| 4845 | hda_nid_t conn2[2] = { 0x0e, 0x0f }; |
| 4846 | snd_hda_override_conn_list(codec, 0x14, 2, conn1); |
| 4847 | snd_hda_override_conn_list(codec, 0x15, 2, conn1); |
| 4848 | snd_hda_override_conn_list(codec, 0x18, 2, conn2); |
| 4849 | snd_hda_override_conn_list(codec, 0x1a, 2, conn2); |
| 4850 | } |
| 4851 | } |
| 4852 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4853 | static const struct alc_fixup alc882_fixups[] = { |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4854 | [ALC882_FIXUP_ABIT_AW9D_MAX] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4855 | .type = ALC_FIXUP_PINS, |
| 4856 | .v.pins = (const struct alc_pincfg[]) { |
| 4857 | { 0x15, 0x01080104 }, /* side */ |
| 4858 | { 0x16, 0x01011012 }, /* rear */ |
| 4859 | { 0x17, 0x01016011 }, /* clfe */ |
| 4860 | { } |
| 4861 | } |
| 4862 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4863 | [ALC882_FIXUP_LENOVO_Y530] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4864 | .type = ALC_FIXUP_PINS, |
| 4865 | .v.pins = (const struct alc_pincfg[]) { |
| 4866 | { 0x15, 0x99130112 }, /* rear int speakers */ |
| 4867 | { 0x16, 0x99130111 }, /* subwoofer */ |
| 4868 | { } |
| 4869 | } |
| 4870 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4871 | [ALC882_FIXUP_PB_M5210] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4872 | .type = ALC_FIXUP_VERBS, |
| 4873 | .v.verbs = (const struct hda_verb[]) { |
| 4874 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, |
| 4875 | {} |
| 4876 | } |
| 4877 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4878 | [ALC882_FIXUP_ACER_ASPIRE_7736] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4879 | .type = ALC_FIXUP_SKU, |
| 4880 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
| 4881 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4882 | [ALC882_FIXUP_ASUS_W90V] = { |
Takashi Iwai | 5cdf745 | 2011-10-26 23:04:08 +0200 | [diff] [blame] | 4883 | .type = ALC_FIXUP_PINS, |
| 4884 | .v.pins = (const struct alc_pincfg[]) { |
| 4885 | { 0x16, 0x99130110 }, /* fix sequence for CLFE */ |
| 4886 | { } |
| 4887 | } |
| 4888 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4889 | [ALC889_FIXUP_VAIO_TT] = { |
| 4890 | .type = ALC_FIXUP_PINS, |
| 4891 | .v.pins = (const struct alc_pincfg[]) { |
| 4892 | { 0x17, 0x90170111 }, /* hidden surround speaker */ |
| 4893 | { } |
| 4894 | } |
| 4895 | }, |
Takashi Iwai | 0e7cc2e | 2011-11-09 12:42:48 +0100 | [diff] [blame] | 4896 | [ALC888_FIXUP_EEE1601] = { |
| 4897 | .type = ALC_FIXUP_VERBS, |
| 4898 | .v.verbs = (const struct hda_verb[]) { |
| 4899 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b }, |
| 4900 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 }, |
| 4901 | { } |
| 4902 | } |
Takashi Iwai | 177943a3 | 2011-11-09 12:55:18 +0100 | [diff] [blame] | 4903 | }, |
| 4904 | [ALC882_FIXUP_EAPD] = { |
| 4905 | .type = ALC_FIXUP_VERBS, |
| 4906 | .v.verbs = (const struct hda_verb[]) { |
| 4907 | /* change to EAPD mode */ |
| 4908 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4909 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 }, |
| 4910 | { } |
| 4911 | } |
| 4912 | }, |
Takashi Iwai | 7a6069b | 2011-11-09 15:22:01 +0100 | [diff] [blame] | 4913 | [ALC883_FIXUP_EAPD] = { |
| 4914 | .type = ALC_FIXUP_VERBS, |
| 4915 | .v.verbs = (const struct hda_verb[]) { |
| 4916 | /* change to EAPD mode */ |
| 4917 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4918 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, |
| 4919 | { } |
| 4920 | } |
| 4921 | }, |
Takashi Iwai | 8812c4f | 2011-11-09 17:39:15 +0100 | [diff] [blame] | 4922 | [ALC883_FIXUP_ACER_EAPD] = { |
| 4923 | .type = ALC_FIXUP_VERBS, |
| 4924 | .v.verbs = (const struct hda_verb[]) { |
| 4925 | /* eanable EAPD on Acer laptops */ |
| 4926 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4927 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, |
| 4928 | { } |
| 4929 | } |
| 4930 | }, |
Takashi Iwai | eb844d5 | 2011-11-09 18:03:07 +0100 | [diff] [blame] | 4931 | [ALC882_FIXUP_GPIO3] = { |
| 4932 | .type = ALC_FIXUP_VERBS, |
| 4933 | .v.verbs = alc_gpio3_init_verbs, |
| 4934 | }, |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 4935 | [ALC882_FIXUP_ASUS_W2JC] = { |
| 4936 | .type = ALC_FIXUP_VERBS, |
| 4937 | .v.verbs = alc_gpio1_init_verbs, |
| 4938 | .chained = true, |
| 4939 | .chain_id = ALC882_FIXUP_EAPD, |
| 4940 | }, |
| 4941 | [ALC889_FIXUP_COEF] = { |
| 4942 | .type = ALC_FIXUP_FUNC, |
| 4943 | .v.func = alc889_fixup_coef, |
| 4944 | }, |
Takashi Iwai | c3e837b | 2011-11-10 16:01:47 +0100 | [diff] [blame] | 4945 | [ALC882_FIXUP_ACER_ASPIRE_4930G] = { |
| 4946 | .type = ALC_FIXUP_PINS, |
| 4947 | .v.pins = (const struct alc_pincfg[]) { |
| 4948 | { 0x16, 0x99130111 }, /* CLFE speaker */ |
| 4949 | { 0x17, 0x99130112 }, /* surround speaker */ |
| 4950 | { } |
| 4951 | } |
| 4952 | }, |
| 4953 | [ALC882_FIXUP_ACER_ASPIRE_8930G] = { |
| 4954 | .type = ALC_FIXUP_PINS, |
| 4955 | .v.pins = (const struct alc_pincfg[]) { |
| 4956 | { 0x16, 0x99130111 }, /* CLFE speaker */ |
| 4957 | { 0x1b, 0x99130112 }, /* surround speaker */ |
| 4958 | { } |
| 4959 | }, |
| 4960 | .chained = true, |
| 4961 | .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS, |
| 4962 | }, |
| 4963 | [ALC882_FIXUP_ASPIRE_8930G_VERBS] = { |
| 4964 | /* additional init verbs for Acer Aspire 8930G */ |
| 4965 | .type = ALC_FIXUP_VERBS, |
| 4966 | .v.verbs = (const struct hda_verb[]) { |
| 4967 | /* Enable all DACs */ |
| 4968 | /* DAC DISABLE/MUTE 1? */ |
| 4969 | /* setting bits 1-5 disables DAC nids 0x02-0x06 |
| 4970 | * apparently. Init=0x38 */ |
| 4971 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 }, |
| 4972 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 }, |
| 4973 | /* DAC DISABLE/MUTE 2? */ |
| 4974 | /* some bit here disables the other DACs. |
| 4975 | * Init=0x4900 */ |
| 4976 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 }, |
| 4977 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 }, |
| 4978 | /* DMIC fix |
| 4979 | * This laptop has a stereo digital microphone. |
| 4980 | * The mics are only 1cm apart which makes the stereo |
| 4981 | * useless. However, either the mic or the ALC889 |
| 4982 | * makes the signal become a difference/sum signal |
| 4983 | * instead of standard stereo, which is annoying. |
| 4984 | * So instead we flip this bit which makes the |
| 4985 | * codec replicate the sum signal to both channels, |
| 4986 | * turning it into a normal mono mic. |
| 4987 | */ |
| 4988 | /* DMIC_CONTROL? Init value = 0x0001 */ |
| 4989 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b }, |
| 4990 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 }, |
| 4991 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4992 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, |
| 4993 | { } |
| 4994 | } |
| 4995 | }, |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 4996 | [ALC885_FIXUP_MACPRO_GPIO] = { |
| 4997 | .type = ALC_FIXUP_FUNC, |
| 4998 | .v.func = alc885_fixup_macpro_gpio, |
| 4999 | }, |
Takashi Iwai | 02a237b | 2012-02-13 15:25:07 +0100 | [diff] [blame] | 5000 | [ALC889_FIXUP_DAC_ROUTE] = { |
| 5001 | .type = ALC_FIXUP_FUNC, |
| 5002 | .v.func = alc889_fixup_dac_route, |
| 5003 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5004 | }; |
| 5005 | |
| 5006 | static const struct snd_pci_quirk alc882_fixup_tbl[] = { |
Takashi Iwai | 8812c4f | 2011-11-09 17:39:15 +0100 | [diff] [blame] | 5007 | SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD), |
| 5008 | SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD), |
| 5009 | SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD), |
| 5010 | SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD), |
| 5011 | SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD), |
| 5012 | SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD), |
Takashi Iwai | c3e837b | 2011-11-10 16:01:47 +0100 | [diff] [blame] | 5013 | SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G", |
| 5014 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
| 5015 | SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G", |
| 5016 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
| 5017 | SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G", |
| 5018 | ALC882_FIXUP_ACER_ASPIRE_8930G), |
| 5019 | SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G", |
| 5020 | ALC882_FIXUP_ACER_ASPIRE_8930G), |
| 5021 | SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G", |
| 5022 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
| 5023 | SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G", |
| 5024 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
| 5025 | SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G", |
| 5026 | ALC882_FIXUP_ACER_ASPIRE_4930G), |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 5027 | SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210), |
Takashi Iwai | 02a237b | 2012-02-13 15:25:07 +0100 | [diff] [blame] | 5028 | SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE), |
Takashi Iwai | ac9b1cd | 2011-11-09 17:45:55 +0100 | [diff] [blame] | 5029 | SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736), |
Takashi Iwai | 177943a3 | 2011-11-09 12:55:18 +0100 | [diff] [blame] | 5030 | SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD), |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 5031 | SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V), |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 5032 | SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC), |
Takashi Iwai | 0e7cc2e | 2011-11-09 12:42:48 +0100 | [diff] [blame] | 5033 | SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601), |
Takashi Iwai | ac9b1cd | 2011-11-09 17:45:55 +0100 | [diff] [blame] | 5034 | SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT), |
Takashi Iwai | 5671087 | 2011-11-14 17:42:11 +0100 | [diff] [blame] | 5035 | |
| 5036 | /* All Apple entries are in codec SSIDs */ |
| 5037 | SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO), |
| 5038 | SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO), |
| 5039 | SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO), |
| 5040 | SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD), |
| 5041 | SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO), |
| 5042 | |
Takashi Iwai | 7a6069b | 2011-11-09 15:22:01 +0100 | [diff] [blame] | 5043 | SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD), |
Takashi Iwai | eb844d5 | 2011-11-09 18:03:07 +0100 | [diff] [blame] | 5044 | SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3), |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 5045 | 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] | 5046 | SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD), |
| 5047 | SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD), |
Takashi Iwai | ac9b1cd | 2011-11-09 17:45:55 +0100 | [diff] [blame] | 5048 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530), |
Takashi Iwai | 68ef056 | 2011-11-09 18:24:44 +0100 | [diff] [blame] | 5049 | SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5050 | {} |
| 5051 | }; |
| 5052 | |
| 5053 | /* |
| 5054 | * BIOS auto configuration |
| 5055 | */ |
| 5056 | /* almost identical with ALC880 parser... */ |
| 5057 | static int alc882_parse_auto_config(struct hda_codec *codec) |
| 5058 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5059 | static const hda_nid_t alc882_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5060 | static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5061 | return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5062 | } |
| 5063 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5064 | /* |
| 5065 | */ |
| 5066 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 5067 | #include "alc882_quirks.c" |
| 5068 | #endif |
| 5069 | |
| 5070 | static int patch_alc882(struct hda_codec *codec) |
| 5071 | { |
| 5072 | struct alc_spec *spec; |
| 5073 | int err, board_config; |
| 5074 | |
| 5075 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5076 | if (spec == NULL) |
| 5077 | return -ENOMEM; |
| 5078 | |
| 5079 | codec->spec = spec; |
| 5080 | |
| 5081 | spec->mixer_nid = 0x0b; |
| 5082 | |
| 5083 | switch (codec->vendor_id) { |
| 5084 | case 0x10ec0882: |
| 5085 | case 0x10ec0885: |
| 5086 | break; |
| 5087 | default: |
| 5088 | /* ALC883 and variants */ |
| 5089 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); |
| 5090 | break; |
| 5091 | } |
| 5092 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5093 | err = alc_codec_rename_from_preset(codec); |
| 5094 | if (err < 0) |
| 5095 | goto error; |
| 5096 | |
Takashi Iwai | b253969 | 2011-11-14 17:32:17 +0100 | [diff] [blame] | 5097 | board_config = alc_board_config(codec, ALC882_MODEL_LAST, |
| 5098 | alc882_models, NULL); |
| 5099 | if (board_config < 0) |
| 5100 | board_config = alc_board_codec_sid_config(codec, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5101 | ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl); |
| 5102 | |
| 5103 | if (board_config < 0) { |
| 5104 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 5105 | codec->chip_name); |
| 5106 | board_config = ALC_MODEL_AUTO; |
| 5107 | } |
| 5108 | |
| 5109 | if (board_config == ALC_MODEL_AUTO) { |
| 5110 | alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups); |
| 5111 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 5112 | } |
| 5113 | |
| 5114 | alc_auto_parse_customize_define(codec); |
| 5115 | |
| 5116 | if (board_config == ALC_MODEL_AUTO) { |
| 5117 | /* automatic parse from the BIOS config */ |
| 5118 | err = alc882_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5119 | if (err < 0) |
| 5120 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5121 | } |
| 5122 | |
David Henningsson | fde48a1 | 2011-12-09 18:27:42 +0800 | [diff] [blame] | 5123 | if (board_config != ALC_MODEL_AUTO) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5124 | setup_preset(codec, &alc882_presets[board_config]); |
David Henningsson | fde48a1 | 2011-12-09 18:27:42 +0800 | [diff] [blame] | 5125 | spec->vmaster_nid = 0x0c; |
| 5126 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5127 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5128 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5129 | alc_auto_fill_adc_caps(codec); |
| 5130 | alc_rebuild_imux_for_auto_mic(codec); |
| 5131 | alc_remove_invalid_adc_nids(codec); |
| 5132 | } |
| 5133 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5134 | if (!spec->no_analog && !spec->cap_mixer) |
| 5135 | set_capture_mixer(codec); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5136 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5137 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 5138 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5139 | if (err < 0) |
| 5140 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5141 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5142 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5143 | |
| 5144 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5145 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5146 | codec->patch_ops = alc_patch_ops; |
| 5147 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 5148 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | f21d78e | 2012-01-19 12:10:29 +0100 | [diff] [blame] | 5149 | else |
| 5150 | codec->patch_ops.build_controls = __alc_build_controls; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5151 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5152 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5153 | if (!spec->loopback.amplist) |
| 5154 | spec->loopback.amplist = alc882_loopbacks; |
| 5155 | #endif |
| 5156 | |
| 5157 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5158 | |
| 5159 | error: |
| 5160 | alc_free(codec); |
| 5161 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5162 | } |
| 5163 | |
| 5164 | |
| 5165 | /* |
| 5166 | * ALC262 support |
| 5167 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5168 | static int alc262_parse_auto_config(struct hda_codec *codec) |
| 5169 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5170 | static const hda_nid_t alc262_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5171 | static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5172 | return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5173 | } |
| 5174 | |
| 5175 | /* |
| 5176 | * Pin config fixes |
| 5177 | */ |
| 5178 | enum { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 5179 | ALC262_FIXUP_FSC_H270, |
| 5180 | ALC262_FIXUP_HP_Z200, |
| 5181 | ALC262_FIXUP_TYAN, |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 5182 | ALC262_FIXUP_LENOVO_3000, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 5183 | ALC262_FIXUP_BENQ, |
| 5184 | ALC262_FIXUP_BENQ_T31, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5185 | }; |
| 5186 | |
| 5187 | static const struct alc_fixup alc262_fixups[] = { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 5188 | [ALC262_FIXUP_FSC_H270] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5189 | .type = ALC_FIXUP_PINS, |
| 5190 | .v.pins = (const struct alc_pincfg[]) { |
| 5191 | { 0x14, 0x99130110 }, /* speaker */ |
| 5192 | { 0x15, 0x0221142f }, /* front HP */ |
| 5193 | { 0x1b, 0x0121141f }, /* rear HP */ |
| 5194 | { } |
| 5195 | } |
| 5196 | }, |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 5197 | [ALC262_FIXUP_HP_Z200] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5198 | .type = ALC_FIXUP_PINS, |
| 5199 | .v.pins = (const struct alc_pincfg[]) { |
| 5200 | { 0x16, 0x99130120 }, /* internal speaker */ |
| 5201 | { } |
| 5202 | } |
| 5203 | }, |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 5204 | [ALC262_FIXUP_TYAN] = { |
| 5205 | .type = ALC_FIXUP_PINS, |
| 5206 | .v.pins = (const struct alc_pincfg[]) { |
| 5207 | { 0x14, 0x1993e1f0 }, /* int AUX */ |
| 5208 | { } |
| 5209 | } |
| 5210 | }, |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 5211 | [ALC262_FIXUP_LENOVO_3000] = { |
| 5212 | .type = ALC_FIXUP_VERBS, |
| 5213 | .v.verbs = (const struct hda_verb[]) { |
| 5214 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 5215 | {} |
| 5216 | }, |
| 5217 | .chained = true, |
| 5218 | .chain_id = ALC262_FIXUP_BENQ, |
| 5219 | }, |
| 5220 | [ALC262_FIXUP_BENQ] = { |
| 5221 | .type = ALC_FIXUP_VERBS, |
| 5222 | .v.verbs = (const struct hda_verb[]) { |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 5223 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 5224 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, |
| 5225 | {} |
| 5226 | } |
| 5227 | }, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 5228 | [ALC262_FIXUP_BENQ_T31] = { |
| 5229 | .type = ALC_FIXUP_VERBS, |
| 5230 | .v.verbs = (const struct hda_verb[]) { |
| 5231 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 5232 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, |
| 5233 | {} |
| 5234 | } |
| 5235 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5236 | }; |
| 5237 | |
| 5238 | static const struct snd_pci_quirk alc262_fixup_tbl[] = { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 5239 | SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200), |
Takashi Iwai | 3dcd3be | 2011-11-07 14:59:40 +0100 | [diff] [blame] | 5240 | SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ), |
| 5241 | SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ), |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 5242 | SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN), |
| 5243 | SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270), |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 5244 | SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000), |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 5245 | SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ), |
| 5246 | SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5247 | {} |
| 5248 | }; |
| 5249 | |
| 5250 | |
| 5251 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5252 | #define alc262_loopbacks alc880_loopbacks |
| 5253 | #endif |
| 5254 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5255 | /* |
| 5256 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5257 | static int patch_alc262(struct hda_codec *codec) |
| 5258 | { |
| 5259 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5260 | int err; |
| 5261 | |
| 5262 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5263 | if (spec == NULL) |
| 5264 | return -ENOMEM; |
| 5265 | |
| 5266 | codec->spec = spec; |
| 5267 | |
| 5268 | spec->mixer_nid = 0x0b; |
| 5269 | |
| 5270 | #if 0 |
| 5271 | /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is |
| 5272 | * under-run |
| 5273 | */ |
| 5274 | { |
| 5275 | int tmp; |
| 5276 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 5277 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 5278 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 5279 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80); |
| 5280 | } |
| 5281 | #endif |
| 5282 | alc_auto_parse_customize_define(codec); |
| 5283 | |
| 5284 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); |
| 5285 | |
Takashi Iwai | 42399f7 | 2011-11-07 17:18:44 +0100 | [diff] [blame] | 5286 | alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups); |
| 5287 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5288 | |
Takashi Iwai | 42399f7 | 2011-11-07 17:18:44 +0100 | [diff] [blame] | 5289 | /* automatic parse from the BIOS config */ |
| 5290 | err = alc262_parse_auto_config(codec); |
| 5291 | if (err < 0) |
| 5292 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5293 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5294 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5295 | alc_auto_fill_adc_caps(codec); |
| 5296 | alc_rebuild_imux_for_auto_mic(codec); |
| 5297 | alc_remove_invalid_adc_nids(codec); |
| 5298 | } |
| 5299 | |
| 5300 | if (!spec->no_analog && !spec->cap_mixer) |
| 5301 | set_capture_mixer(codec); |
| 5302 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5303 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 5304 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5305 | if (err < 0) |
| 5306 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5307 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5308 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5309 | |
| 5310 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5311 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5312 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 42399f7 | 2011-11-07 17:18:44 +0100 | [diff] [blame] | 5313 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5314 | spec->shutup = alc_eapd_shutup; |
| 5315 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5316 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5317 | if (!spec->loopback.amplist) |
| 5318 | spec->loopback.amplist = alc262_loopbacks; |
| 5319 | #endif |
| 5320 | |
| 5321 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5322 | |
| 5323 | error: |
| 5324 | alc_free(codec); |
| 5325 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5326 | } |
| 5327 | |
| 5328 | /* |
| 5329 | * ALC268 |
| 5330 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5331 | /* bind Beep switches of both NID 0x0f and 0x10 */ |
| 5332 | static const struct hda_bind_ctls alc268_bind_beep_sw = { |
| 5333 | .ops = &snd_hda_bind_sw, |
| 5334 | .values = { |
| 5335 | HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT), |
| 5336 | HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT), |
| 5337 | 0 |
| 5338 | }, |
| 5339 | }; |
| 5340 | |
| 5341 | static const struct snd_kcontrol_new alc268_beep_mixer[] = { |
| 5342 | HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT), |
| 5343 | HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw), |
| 5344 | { } |
| 5345 | }; |
| 5346 | |
| 5347 | /* set PCBEEP vol = 0, mute connections */ |
| 5348 | static const struct hda_verb alc268_beep_init_verbs[] = { |
| 5349 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5350 | {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 5351 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 5352 | { } |
| 5353 | }; |
| 5354 | |
| 5355 | /* |
| 5356 | * BIOS auto configuration |
| 5357 | */ |
| 5358 | static int alc268_parse_auto_config(struct hda_codec *codec) |
| 5359 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5360 | static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5361 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5362 | int err = alc_parse_auto_config(codec, NULL, alc268_ssids); |
| 5363 | if (err > 0) { |
| 5364 | if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { |
| 5365 | add_mixer(spec, alc268_beep_mixer); |
| 5366 | add_verb(spec, alc268_beep_init_verbs); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5367 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5368 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5369 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5370 | } |
| 5371 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5372 | /* |
| 5373 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5374 | static int patch_alc268(struct hda_codec *codec) |
| 5375 | { |
| 5376 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5377 | int i, has_beep, err; |
| 5378 | |
| 5379 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5380 | if (spec == NULL) |
| 5381 | return -ENOMEM; |
| 5382 | |
| 5383 | codec->spec = spec; |
| 5384 | |
| 5385 | /* ALC268 has no aa-loopback mixer */ |
| 5386 | |
Takashi Iwai | 6ebb805 | 2011-08-16 15:15:40 +0200 | [diff] [blame] | 5387 | /* automatic parse from the BIOS config */ |
| 5388 | err = alc268_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5389 | if (err < 0) |
| 5390 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5391 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5392 | has_beep = 0; |
| 5393 | for (i = 0; i < spec->num_mixers; i++) { |
| 5394 | if (spec->mixers[i] == alc268_beep_mixer) { |
| 5395 | has_beep = 1; |
| 5396 | break; |
| 5397 | } |
| 5398 | } |
| 5399 | |
| 5400 | if (has_beep) { |
| 5401 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5402 | if (err < 0) |
| 5403 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5404 | if (!query_amp_caps(codec, 0x1d, HDA_INPUT)) |
| 5405 | /* override the amp caps for beep generator */ |
| 5406 | snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT, |
| 5407 | (0x0c << AC_AMPCAP_OFFSET_SHIFT) | |
| 5408 | (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 5409 | (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 5410 | (0 << AC_AMPCAP_MUTE_SHIFT)); |
| 5411 | } |
| 5412 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5413 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5414 | alc_auto_fill_adc_caps(codec); |
| 5415 | alc_rebuild_imux_for_auto_mic(codec); |
| 5416 | alc_remove_invalid_adc_nids(codec); |
| 5417 | } |
| 5418 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5419 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5420 | set_capture_mixer(codec); |
| 5421 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5422 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 6ebb805 | 2011-08-16 15:15:40 +0200 | [diff] [blame] | 5423 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5424 | spec->shutup = alc_eapd_shutup; |
| 5425 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5426 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5427 | |
| 5428 | error: |
| 5429 | alc_free(codec); |
| 5430 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | /* |
| 5434 | * ALC269 |
| 5435 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5436 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5437 | #define alc269_loopbacks alc880_loopbacks |
| 5438 | #endif |
| 5439 | |
| 5440 | static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { |
| 5441 | .substreams = 1, |
| 5442 | .channels_min = 2, |
| 5443 | .channels_max = 8, |
| 5444 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
| 5445 | /* NID is set in alc_build_pcms */ |
| 5446 | .ops = { |
| 5447 | .open = alc_playback_pcm_open, |
| 5448 | .prepare = alc_playback_pcm_prepare, |
| 5449 | .cleanup = alc_playback_pcm_cleanup |
| 5450 | }, |
| 5451 | }; |
| 5452 | |
| 5453 | static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { |
| 5454 | .substreams = 1, |
| 5455 | .channels_min = 2, |
| 5456 | .channels_max = 2, |
| 5457 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
| 5458 | /* NID is set in alc_build_pcms */ |
| 5459 | }; |
| 5460 | |
| 5461 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5462 | static int alc269_mic2_for_mute_led(struct hda_codec *codec) |
| 5463 | { |
| 5464 | switch (codec->subsystem_id) { |
| 5465 | case 0x103c1586: |
| 5466 | return 1; |
| 5467 | } |
| 5468 | return 0; |
| 5469 | } |
| 5470 | |
| 5471 | static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid) |
| 5472 | { |
| 5473 | /* update mute-LED according to the speaker mute state */ |
| 5474 | if (nid == 0x01 || nid == 0x14) { |
| 5475 | int pinval; |
| 5476 | if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) & |
| 5477 | HDA_AMP_MUTE) |
| 5478 | pinval = 0x24; |
| 5479 | else |
| 5480 | pinval = 0x20; |
| 5481 | /* mic2 vref pin is used for mute LED control */ |
| 5482 | snd_hda_codec_update_cache(codec, 0x19, 0, |
| 5483 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 5484 | pinval); |
| 5485 | } |
| 5486 | return alc_check_power_status(codec, nid); |
| 5487 | } |
| 5488 | #endif /* CONFIG_SND_HDA_POWER_SAVE */ |
| 5489 | |
| 5490 | /* different alc269-variants */ |
| 5491 | enum { |
| 5492 | ALC269_TYPE_ALC269VA, |
| 5493 | ALC269_TYPE_ALC269VB, |
| 5494 | ALC269_TYPE_ALC269VC, |
| 5495 | }; |
| 5496 | |
| 5497 | /* |
| 5498 | * BIOS auto configuration |
| 5499 | */ |
| 5500 | static int alc269_parse_auto_config(struct hda_codec *codec) |
| 5501 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5502 | static const hda_nid_t alc269_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5503 | static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 }; |
| 5504 | static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5505 | struct alc_spec *spec = codec->spec; |
| 5506 | const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ? |
| 5507 | alc269va_ssids : alc269_ssids; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5508 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5509 | return alc_parse_auto_config(codec, alc269_ignore, ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5510 | } |
| 5511 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5512 | static void alc269_toggle_power_output(struct hda_codec *codec, int power_up) |
| 5513 | { |
| 5514 | int val = alc_read_coef_idx(codec, 0x04); |
| 5515 | if (power_up) |
| 5516 | val |= 1 << 11; |
| 5517 | else |
| 5518 | val &= ~(1 << 11); |
| 5519 | alc_write_coef_idx(codec, 0x04, val); |
| 5520 | } |
| 5521 | |
| 5522 | static void alc269_shutup(struct hda_codec *codec) |
| 5523 | { |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5524 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5525 | alc269_toggle_power_output(codec, 0); |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5526 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5527 | alc269_toggle_power_output(codec, 0); |
| 5528 | msleep(150); |
| 5529 | } |
| 5530 | } |
| 5531 | |
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 | static int alc269_resume(struct hda_codec *codec) |
| 5534 | { |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5535 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5536 | alc269_toggle_power_output(codec, 0); |
| 5537 | msleep(150); |
| 5538 | } |
| 5539 | |
| 5540 | codec->patch_ops.init(codec); |
| 5541 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5542 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5543 | alc269_toggle_power_output(codec, 1); |
| 5544 | msleep(200); |
| 5545 | } |
| 5546 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5547 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5548 | alc269_toggle_power_output(codec, 1); |
| 5549 | |
| 5550 | snd_hda_codec_resume_amp(codec); |
| 5551 | snd_hda_codec_resume_cache(codec); |
| 5552 | hda_call_check_power_status(codec, 0x01); |
| 5553 | return 0; |
| 5554 | } |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 5555 | #endif /* CONFIG_PM */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5556 | |
| 5557 | static void alc269_fixup_hweq(struct hda_codec *codec, |
| 5558 | const struct alc_fixup *fix, int action) |
| 5559 | { |
| 5560 | int coef; |
| 5561 | |
| 5562 | if (action != ALC_FIXUP_ACT_INIT) |
| 5563 | return; |
| 5564 | coef = alc_read_coef_idx(codec, 0x1e); |
| 5565 | alc_write_coef_idx(codec, 0x1e, coef | 0x80); |
| 5566 | } |
| 5567 | |
| 5568 | static void alc271_fixup_dmic(struct hda_codec *codec, |
| 5569 | const struct alc_fixup *fix, int action) |
| 5570 | { |
| 5571 | static const struct hda_verb verbs[] = { |
| 5572 | {0x20, AC_VERB_SET_COEF_INDEX, 0x0d}, |
| 5573 | {0x20, AC_VERB_SET_PROC_COEF, 0x4000}, |
| 5574 | {} |
| 5575 | }; |
| 5576 | unsigned int cfg; |
| 5577 | |
| 5578 | if (strcmp(codec->chip_name, "ALC271X")) |
| 5579 | return; |
| 5580 | cfg = snd_hda_codec_get_pincfg(codec, 0x12); |
| 5581 | if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED) |
| 5582 | snd_hda_sequence_write(codec, verbs); |
| 5583 | } |
| 5584 | |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 5585 | static void alc269_fixup_pcm_44k(struct hda_codec *codec, |
| 5586 | const struct alc_fixup *fix, int action) |
| 5587 | { |
| 5588 | struct alc_spec *spec = codec->spec; |
| 5589 | |
| 5590 | if (action != ALC_FIXUP_ACT_PROBE) |
| 5591 | return; |
| 5592 | |
| 5593 | /* Due to a hardware problem on Lenovo Ideadpad, we need to |
| 5594 | * fix the sample rate of analog I/O to 44.1kHz |
| 5595 | */ |
| 5596 | spec->stream_analog_playback = &alc269_44k_pcm_analog_playback; |
| 5597 | spec->stream_analog_capture = &alc269_44k_pcm_analog_capture; |
| 5598 | } |
| 5599 | |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 5600 | static void alc269_fixup_stereo_dmic(struct hda_codec *codec, |
| 5601 | const struct alc_fixup *fix, int action) |
| 5602 | { |
| 5603 | int coef; |
| 5604 | |
| 5605 | if (action != ALC_FIXUP_ACT_INIT) |
| 5606 | return; |
| 5607 | /* The digital-mic unit sends PDM (differential signal) instead of |
| 5608 | * the standard PCM, thus you can't record a valid mono stream as is. |
| 5609 | * Below is a workaround specific to ALC269 to control the dmic |
| 5610 | * signal source as mono. |
| 5611 | */ |
| 5612 | coef = alc_read_coef_idx(codec, 0x07); |
| 5613 | alc_write_coef_idx(codec, 0x07, coef | 0x80); |
| 5614 | } |
| 5615 | |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5616 | static void alc269_quanta_automute(struct hda_codec *codec) |
| 5617 | { |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 5618 | update_outputs(codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5619 | |
| 5620 | snd_hda_codec_write(codec, 0x20, 0, |
| 5621 | AC_VERB_SET_COEF_INDEX, 0x0c); |
| 5622 | snd_hda_codec_write(codec, 0x20, 0, |
| 5623 | AC_VERB_SET_PROC_COEF, 0x680); |
| 5624 | |
| 5625 | snd_hda_codec_write(codec, 0x20, 0, |
| 5626 | AC_VERB_SET_COEF_INDEX, 0x0c); |
| 5627 | snd_hda_codec_write(codec, 0x20, 0, |
| 5628 | AC_VERB_SET_PROC_COEF, 0x480); |
| 5629 | } |
| 5630 | |
| 5631 | static void alc269_fixup_quanta_mute(struct hda_codec *codec, |
| 5632 | const struct alc_fixup *fix, int action) |
| 5633 | { |
| 5634 | struct alc_spec *spec = codec->spec; |
| 5635 | if (action != ALC_FIXUP_ACT_PROBE) |
| 5636 | return; |
| 5637 | spec->automute_hook = alc269_quanta_automute; |
| 5638 | } |
| 5639 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5640 | enum { |
| 5641 | ALC269_FIXUP_SONY_VAIO, |
| 5642 | ALC275_FIXUP_SONY_VAIO_GPIO2, |
| 5643 | ALC269_FIXUP_DELL_M101Z, |
| 5644 | ALC269_FIXUP_SKU_IGNORE, |
| 5645 | ALC269_FIXUP_ASUS_G73JW, |
| 5646 | ALC269_FIXUP_LENOVO_EAPD, |
| 5647 | ALC275_FIXUP_SONY_HWEQ, |
| 5648 | ALC271_FIXUP_DMIC, |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 5649 | ALC269_FIXUP_PCM_44K, |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 5650 | ALC269_FIXUP_STEREO_DMIC, |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5651 | ALC269_FIXUP_QUANTA_MUTE, |
| 5652 | ALC269_FIXUP_LIFEBOOK, |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5653 | ALC269_FIXUP_AMIC, |
| 5654 | ALC269_FIXUP_DMIC, |
| 5655 | ALC269VB_FIXUP_AMIC, |
| 5656 | ALC269VB_FIXUP_DMIC, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5657 | }; |
| 5658 | |
| 5659 | static const struct alc_fixup alc269_fixups[] = { |
| 5660 | [ALC269_FIXUP_SONY_VAIO] = { |
| 5661 | .type = ALC_FIXUP_VERBS, |
| 5662 | .v.verbs = (const struct hda_verb[]) { |
| 5663 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD}, |
| 5664 | {} |
| 5665 | } |
| 5666 | }, |
| 5667 | [ALC275_FIXUP_SONY_VAIO_GPIO2] = { |
| 5668 | .type = ALC_FIXUP_VERBS, |
| 5669 | .v.verbs = (const struct hda_verb[]) { |
| 5670 | {0x01, AC_VERB_SET_GPIO_MASK, 0x04}, |
| 5671 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04}, |
| 5672 | {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, |
| 5673 | { } |
| 5674 | }, |
| 5675 | .chained = true, |
| 5676 | .chain_id = ALC269_FIXUP_SONY_VAIO |
| 5677 | }, |
| 5678 | [ALC269_FIXUP_DELL_M101Z] = { |
| 5679 | .type = ALC_FIXUP_VERBS, |
| 5680 | .v.verbs = (const struct hda_verb[]) { |
| 5681 | /* Enables internal speaker */ |
| 5682 | {0x20, AC_VERB_SET_COEF_INDEX, 13}, |
| 5683 | {0x20, AC_VERB_SET_PROC_COEF, 0x4040}, |
| 5684 | {} |
| 5685 | } |
| 5686 | }, |
| 5687 | [ALC269_FIXUP_SKU_IGNORE] = { |
| 5688 | .type = ALC_FIXUP_SKU, |
| 5689 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
| 5690 | }, |
| 5691 | [ALC269_FIXUP_ASUS_G73JW] = { |
| 5692 | .type = ALC_FIXUP_PINS, |
| 5693 | .v.pins = (const struct alc_pincfg[]) { |
| 5694 | { 0x17, 0x99130111 }, /* subwoofer */ |
| 5695 | { } |
| 5696 | } |
| 5697 | }, |
| 5698 | [ALC269_FIXUP_LENOVO_EAPD] = { |
| 5699 | .type = ALC_FIXUP_VERBS, |
| 5700 | .v.verbs = (const struct hda_verb[]) { |
| 5701 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, |
| 5702 | {} |
| 5703 | } |
| 5704 | }, |
| 5705 | [ALC275_FIXUP_SONY_HWEQ] = { |
| 5706 | .type = ALC_FIXUP_FUNC, |
| 5707 | .v.func = alc269_fixup_hweq, |
| 5708 | .chained = true, |
| 5709 | .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2 |
| 5710 | }, |
| 5711 | [ALC271_FIXUP_DMIC] = { |
| 5712 | .type = ALC_FIXUP_FUNC, |
| 5713 | .v.func = alc271_fixup_dmic, |
| 5714 | }, |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 5715 | [ALC269_FIXUP_PCM_44K] = { |
| 5716 | .type = ALC_FIXUP_FUNC, |
| 5717 | .v.func = alc269_fixup_pcm_44k, |
| 5718 | }, |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 5719 | [ALC269_FIXUP_STEREO_DMIC] = { |
| 5720 | .type = ALC_FIXUP_FUNC, |
| 5721 | .v.func = alc269_fixup_stereo_dmic, |
| 5722 | }, |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5723 | [ALC269_FIXUP_QUANTA_MUTE] = { |
| 5724 | .type = ALC_FIXUP_FUNC, |
| 5725 | .v.func = alc269_fixup_quanta_mute, |
| 5726 | }, |
| 5727 | [ALC269_FIXUP_LIFEBOOK] = { |
| 5728 | .type = ALC_FIXUP_PINS, |
| 5729 | .v.pins = (const struct alc_pincfg[]) { |
| 5730 | { 0x1a, 0x2101103f }, /* dock line-out */ |
| 5731 | { 0x1b, 0x23a11040 }, /* dock mic-in */ |
| 5732 | { } |
| 5733 | }, |
| 5734 | .chained = true, |
| 5735 | .chain_id = ALC269_FIXUP_QUANTA_MUTE |
| 5736 | }, |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5737 | [ALC269_FIXUP_AMIC] = { |
| 5738 | .type = ALC_FIXUP_PINS, |
| 5739 | .v.pins = (const struct alc_pincfg[]) { |
| 5740 | { 0x14, 0x99130110 }, /* speaker */ |
| 5741 | { 0x15, 0x0121401f }, /* HP out */ |
| 5742 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5743 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 5744 | { } |
| 5745 | }, |
| 5746 | }, |
| 5747 | [ALC269_FIXUP_DMIC] = { |
| 5748 | .type = ALC_FIXUP_PINS, |
| 5749 | .v.pins = (const struct alc_pincfg[]) { |
| 5750 | { 0x12, 0x99a3092f }, /* int-mic */ |
| 5751 | { 0x14, 0x99130110 }, /* speaker */ |
| 5752 | { 0x15, 0x0121401f }, /* HP out */ |
| 5753 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5754 | { } |
| 5755 | }, |
| 5756 | }, |
| 5757 | [ALC269VB_FIXUP_AMIC] = { |
| 5758 | .type = ALC_FIXUP_PINS, |
| 5759 | .v.pins = (const struct alc_pincfg[]) { |
| 5760 | { 0x14, 0x99130110 }, /* speaker */ |
| 5761 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5762 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 5763 | { 0x21, 0x0121401f }, /* HP out */ |
| 5764 | { } |
| 5765 | }, |
| 5766 | }, |
David Henningsson | 2267ea9 | 2012-01-03 08:45:56 +0100 | [diff] [blame] | 5767 | [ALC269VB_FIXUP_DMIC] = { |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5768 | .type = ALC_FIXUP_PINS, |
| 5769 | .v.pins = (const struct alc_pincfg[]) { |
| 5770 | { 0x12, 0x99a3092f }, /* int-mic */ |
| 5771 | { 0x14, 0x99130110 }, /* speaker */ |
| 5772 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5773 | { 0x21, 0x0121401f }, /* HP out */ |
| 5774 | { } |
| 5775 | }, |
| 5776 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5777 | }; |
| 5778 | |
| 5779 | static const struct snd_pci_quirk alc269_fixup_tbl[] = { |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 5780 | SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW), |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 5781 | SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC), |
| 5782 | SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC), |
| 5783 | SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC), |
| 5784 | SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), |
| 5785 | SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5786 | SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2), |
| 5787 | SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), |
| 5788 | SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), |
| 5789 | SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO), |
| 5790 | SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z), |
| 5791 | SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC), |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5792 | SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5793 | SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE), |
| 5794 | SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE), |
| 5795 | SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE), |
| 5796 | SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE), |
| 5797 | SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE), |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5798 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE), |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 5799 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5800 | SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD), |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5801 | |
Takashi Iwai | a7f3eed | 2012-02-16 13:03:18 +0100 | [diff] [blame] | 5802 | #if 0 |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5803 | /* Below is a quirk table taken from the old code. |
| 5804 | * Basically the device should work as is without the fixup table. |
| 5805 | * If BIOS doesn't give a proper info, enable the corresponding |
| 5806 | * fixup entry. |
| 5807 | */ |
| 5808 | SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A", |
| 5809 | ALC269_FIXUP_AMIC), |
| 5810 | SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC), |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5811 | SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC), |
| 5812 | SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC), |
| 5813 | SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC), |
| 5814 | SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC), |
| 5815 | SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC), |
| 5816 | SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC), |
| 5817 | SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC), |
| 5818 | SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC), |
| 5819 | SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC), |
| 5820 | SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC), |
| 5821 | SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC), |
| 5822 | SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC), |
| 5823 | SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC), |
| 5824 | SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC), |
| 5825 | SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC), |
| 5826 | SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC), |
| 5827 | SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC), |
| 5828 | SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC), |
| 5829 | SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC), |
| 5830 | SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC), |
| 5831 | SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC), |
| 5832 | SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC), |
| 5833 | SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC), |
| 5834 | SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC), |
| 5835 | SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC), |
| 5836 | SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC), |
| 5837 | SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC), |
| 5838 | SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC), |
| 5839 | SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC), |
| 5840 | SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC), |
| 5841 | SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC), |
| 5842 | SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC), |
| 5843 | SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC), |
| 5844 | SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC), |
| 5845 | SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC), |
| 5846 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC), |
| 5847 | SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC), |
| 5848 | SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC), |
| 5849 | #endif |
| 5850 | {} |
| 5851 | }; |
| 5852 | |
| 5853 | static const struct alc_model_fixup alc269_fixup_models[] = { |
| 5854 | {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"}, |
| 5855 | {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"}, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5856 | {} |
| 5857 | }; |
| 5858 | |
| 5859 | |
| 5860 | static int alc269_fill_coef(struct hda_codec *codec) |
| 5861 | { |
| 5862 | int val; |
| 5863 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5864 | if ((alc_get_coef0(codec) & 0x00ff) < 0x015) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5865 | alc_write_coef_idx(codec, 0xf, 0x960b); |
| 5866 | alc_write_coef_idx(codec, 0xe, 0x8817); |
| 5867 | } |
| 5868 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5869 | if ((alc_get_coef0(codec) & 0x00ff) == 0x016) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5870 | alc_write_coef_idx(codec, 0xf, 0x960b); |
| 5871 | alc_write_coef_idx(codec, 0xe, 0x8814); |
| 5872 | } |
| 5873 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5874 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5875 | val = alc_read_coef_idx(codec, 0x04); |
| 5876 | /* Power up output pin */ |
| 5877 | alc_write_coef_idx(codec, 0x04, val | (1<<11)); |
| 5878 | } |
| 5879 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5880 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5881 | val = alc_read_coef_idx(codec, 0xd); |
| 5882 | if ((val & 0x0c00) >> 10 != 0x1) { |
| 5883 | /* Capless ramp up clock control */ |
| 5884 | alc_write_coef_idx(codec, 0xd, val | (1<<10)); |
| 5885 | } |
| 5886 | val = alc_read_coef_idx(codec, 0x17); |
| 5887 | if ((val & 0x01c0) >> 6 != 0x4) { |
| 5888 | /* Class D power on reset */ |
| 5889 | alc_write_coef_idx(codec, 0x17, val | (1<<7)); |
| 5890 | } |
| 5891 | } |
| 5892 | |
| 5893 | val = alc_read_coef_idx(codec, 0xd); /* Class D */ |
| 5894 | alc_write_coef_idx(codec, 0xd, val | (1<<14)); |
| 5895 | |
| 5896 | val = alc_read_coef_idx(codec, 0x4); /* HP */ |
| 5897 | alc_write_coef_idx(codec, 0x4, val | (1<<11)); |
| 5898 | |
| 5899 | return 0; |
| 5900 | } |
| 5901 | |
| 5902 | /* |
| 5903 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5904 | static int patch_alc269(struct hda_codec *codec) |
| 5905 | { |
| 5906 | struct alc_spec *spec; |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5907 | int err = 0; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5908 | |
| 5909 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5910 | if (spec == NULL) |
| 5911 | return -ENOMEM; |
| 5912 | |
| 5913 | codec->spec = spec; |
| 5914 | |
| 5915 | spec->mixer_nid = 0x0b; |
| 5916 | |
| 5917 | alc_auto_parse_customize_define(codec); |
| 5918 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5919 | err = alc_codec_rename_from_preset(codec); |
| 5920 | if (err < 0) |
| 5921 | goto error; |
| 5922 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5923 | if (codec->vendor_id == 0x10ec0269) { |
| 5924 | spec->codec_variant = ALC269_TYPE_ALC269VA; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5925 | switch (alc_get_coef0(codec) & 0x00f0) { |
| 5926 | case 0x0010: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5927 | if (codec->bus->pci->subsystem_vendor == 0x1025 && |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5928 | spec->cdefine.platform_type == 1) |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5929 | err = alc_codec_rename(codec, "ALC271X"); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5930 | spec->codec_variant = ALC269_TYPE_ALC269VB; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5931 | break; |
| 5932 | case 0x0020: |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5933 | if (codec->bus->pci->subsystem_vendor == 0x17aa && |
| 5934 | codec->bus->pci->subsystem_device == 0x21f3) |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5935 | err = alc_codec_rename(codec, "ALC3202"); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5936 | spec->codec_variant = ALC269_TYPE_ALC269VC; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5937 | break; |
| 5938 | default: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5939 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5940 | } |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5941 | if (err < 0) |
| 5942 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5943 | alc269_fill_coef(codec); |
| 5944 | } |
| 5945 | |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5946 | alc_pick_fixup(codec, alc269_fixup_models, |
| 5947 | alc269_fixup_tbl, alc269_fixups); |
| 5948 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5949 | |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5950 | /* automatic parse from the BIOS config */ |
| 5951 | err = alc269_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5952 | if (err < 0) |
| 5953 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5954 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5955 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5956 | alc_auto_fill_adc_caps(codec); |
| 5957 | alc_rebuild_imux_for_auto_mic(codec); |
| 5958 | alc_remove_invalid_adc_nids(codec); |
| 5959 | } |
| 5960 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5961 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5962 | set_capture_mixer(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5963 | |
| 5964 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 5965 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5966 | if (err < 0) |
| 5967 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5968 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5969 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5970 | |
| 5971 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5972 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5973 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 5974 | #ifdef CONFIG_PM |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5975 | codec->patch_ops.resume = alc269_resume; |
| 5976 | #endif |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5977 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5978 | spec->shutup = alc269_shutup; |
| 5979 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5980 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5981 | if (!spec->loopback.amplist) |
| 5982 | spec->loopback.amplist = alc269_loopbacks; |
| 5983 | if (alc269_mic2_for_mute_led(codec)) |
| 5984 | codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps; |
| 5985 | #endif |
| 5986 | |
| 5987 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5988 | |
| 5989 | error: |
| 5990 | alc_free(codec); |
| 5991 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5992 | } |
| 5993 | |
| 5994 | /* |
| 5995 | * ALC861 |
| 5996 | */ |
| 5997 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5998 | static int alc861_parse_auto_config(struct hda_codec *codec) |
| 5999 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6000 | static const hda_nid_t alc861_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6001 | static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 }; |
| 6002 | return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6003 | } |
| 6004 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6005 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 6006 | static const struct hda_amp_list alc861_loopbacks[] = { |
| 6007 | { 0x15, HDA_INPUT, 0 }, |
| 6008 | { 0x15, HDA_INPUT, 1 }, |
| 6009 | { 0x15, HDA_INPUT, 2 }, |
| 6010 | { 0x15, HDA_INPUT, 3 }, |
| 6011 | { } /* end */ |
| 6012 | }; |
| 6013 | #endif |
| 6014 | |
| 6015 | |
| 6016 | /* Pin config fixes */ |
| 6017 | enum { |
Takashi Iwai | e652f4c | 2012-02-13 11:56:25 +0100 | [diff] [blame] | 6018 | ALC861_FIXUP_FSC_AMILO_PI1505, |
| 6019 | ALC861_FIXUP_AMP_VREF_0F, |
| 6020 | ALC861_FIXUP_NO_JACK_DETECT, |
| 6021 | ALC861_FIXUP_ASUS_A6RP, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6022 | }; |
| 6023 | |
Takashi Iwai | 31150f2 | 2012-01-30 10:54:08 +0100 | [diff] [blame] | 6024 | /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */ |
| 6025 | static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec, |
| 6026 | const struct alc_fixup *fix, int action) |
| 6027 | { |
| 6028 | struct alc_spec *spec = codec->spec; |
| 6029 | unsigned int val; |
| 6030 | |
| 6031 | if (action != ALC_FIXUP_ACT_INIT) |
| 6032 | return; |
| 6033 | val = snd_hda_codec_read(codec, 0x0f, 0, |
| 6034 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 6035 | if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))) |
| 6036 | val |= AC_PINCTL_IN_EN; |
| 6037 | val |= AC_PINCTL_VREF_50; |
| 6038 | snd_hda_codec_write(codec, 0x0f, 0, |
| 6039 | AC_VERB_SET_PIN_WIDGET_CONTROL, val); |
| 6040 | spec->keep_vref_in_automute = 1; |
| 6041 | } |
| 6042 | |
Takashi Iwai | e652f4c | 2012-02-13 11:56:25 +0100 | [diff] [blame] | 6043 | /* suppress the jack-detection */ |
| 6044 | static void alc_fixup_no_jack_detect(struct hda_codec *codec, |
| 6045 | const struct alc_fixup *fix, int action) |
| 6046 | { |
| 6047 | if (action == ALC_FIXUP_ACT_PRE_PROBE) |
| 6048 | codec->no_jack_detect = 1; |
| 6049 | } |
| 6050 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6051 | static const struct alc_fixup alc861_fixups[] = { |
Takashi Iwai | e652f4c | 2012-02-13 11:56:25 +0100 | [diff] [blame] | 6052 | [ALC861_FIXUP_FSC_AMILO_PI1505] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6053 | .type = ALC_FIXUP_PINS, |
| 6054 | .v.pins = (const struct alc_pincfg[]) { |
| 6055 | { 0x0b, 0x0221101f }, /* HP */ |
| 6056 | { 0x0f, 0x90170310 }, /* speaker */ |
| 6057 | { } |
| 6058 | } |
| 6059 | }, |
Takashi Iwai | e652f4c | 2012-02-13 11:56:25 +0100 | [diff] [blame] | 6060 | [ALC861_FIXUP_AMP_VREF_0F] = { |
Takashi Iwai | 31150f2 | 2012-01-30 10:54:08 +0100 | [diff] [blame] | 6061 | .type = ALC_FIXUP_FUNC, |
| 6062 | .v.func = alc861_fixup_asus_amp_vref_0f, |
Takashi Iwai | 3b25eb6 | 2012-01-25 09:55:46 +0100 | [diff] [blame] | 6063 | }, |
Takashi Iwai | e652f4c | 2012-02-13 11:56:25 +0100 | [diff] [blame] | 6064 | [ALC861_FIXUP_NO_JACK_DETECT] = { |
| 6065 | .type = ALC_FIXUP_FUNC, |
| 6066 | .v.func = alc_fixup_no_jack_detect, |
| 6067 | }, |
| 6068 | [ALC861_FIXUP_ASUS_A6RP] = { |
| 6069 | .type = ALC_FIXUP_FUNC, |
| 6070 | .v.func = alc861_fixup_asus_amp_vref_0f, |
| 6071 | .chained = true, |
| 6072 | .chain_id = ALC861_FIXUP_NO_JACK_DETECT, |
| 6073 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6074 | }; |
| 6075 | |
| 6076 | static const struct snd_pci_quirk alc861_fixup_tbl[] = { |
Takashi Iwai | e652f4c | 2012-02-13 11:56:25 +0100 | [diff] [blame] | 6077 | SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP), |
| 6078 | SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F), |
| 6079 | SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT), |
| 6080 | SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F), |
| 6081 | SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F), |
| 6082 | SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6083 | {} |
| 6084 | }; |
| 6085 | |
| 6086 | /* |
| 6087 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6088 | static int patch_alc861(struct hda_codec *codec) |
| 6089 | { |
| 6090 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6091 | int err; |
| 6092 | |
| 6093 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 6094 | if (spec == NULL) |
| 6095 | return -ENOMEM; |
| 6096 | |
| 6097 | codec->spec = spec; |
| 6098 | |
| 6099 | spec->mixer_nid = 0x15; |
| 6100 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 6101 | alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); |
| 6102 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6103 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 6104 | /* automatic parse from the BIOS config */ |
| 6105 | err = alc861_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6106 | if (err < 0) |
| 6107 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6108 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 6109 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6110 | alc_auto_fill_adc_caps(codec); |
| 6111 | alc_rebuild_imux_for_auto_mic(codec); |
| 6112 | alc_remove_invalid_adc_nids(codec); |
| 6113 | } |
| 6114 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6115 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6116 | set_capture_mixer(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6117 | |
| 6118 | if (!spec->no_analog) { |
| 6119 | err = snd_hda_attach_beep_device(codec, 0x23); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6120 | if (err < 0) |
| 6121 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6122 | set_beep_amp(spec, 0x23, 0, HDA_OUTPUT); |
| 6123 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6124 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6125 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 6126 | |
| 6127 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 6128 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6129 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 6130 | spec->power_hook = alc_power_eapd; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6131 | if (!spec->loopback.amplist) |
| 6132 | spec->loopback.amplist = alc861_loopbacks; |
| 6133 | #endif |
| 6134 | |
| 6135 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6136 | |
| 6137 | error: |
| 6138 | alc_free(codec); |
| 6139 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6140 | } |
| 6141 | |
| 6142 | /* |
| 6143 | * ALC861-VD support |
| 6144 | * |
| 6145 | * Based on ALC882 |
| 6146 | * |
| 6147 | * In addition, an independent DAC |
| 6148 | */ |
| 6149 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 6150 | #define alc861vd_loopbacks alc880_loopbacks |
| 6151 | #endif |
| 6152 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6153 | static int alc861vd_parse_auto_config(struct hda_codec *codec) |
| 6154 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6155 | static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6156 | static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 6157 | return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6158 | } |
| 6159 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6160 | enum { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 6161 | ALC660VD_FIX_ASUS_GPIO1, |
| 6162 | ALC861VD_FIX_DALLAS, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6163 | }; |
| 6164 | |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 6165 | /* exclude VREF80 */ |
| 6166 | static void alc861vd_fixup_dallas(struct hda_codec *codec, |
| 6167 | const struct alc_fixup *fix, int action) |
| 6168 | { |
| 6169 | if (action == ALC_FIXUP_ACT_PRE_PROBE) { |
| 6170 | snd_hda_override_pin_caps(codec, 0x18, 0x00001714); |
| 6171 | snd_hda_override_pin_caps(codec, 0x19, 0x0000171c); |
| 6172 | } |
| 6173 | } |
| 6174 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6175 | static const struct alc_fixup alc861vd_fixups[] = { |
| 6176 | [ALC660VD_FIX_ASUS_GPIO1] = { |
| 6177 | .type = ALC_FIXUP_VERBS, |
| 6178 | .v.verbs = (const struct hda_verb[]) { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 6179 | /* reset GPIO1 */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6180 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, |
| 6181 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, |
| 6182 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, |
| 6183 | { } |
| 6184 | } |
| 6185 | }, |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 6186 | [ALC861VD_FIX_DALLAS] = { |
| 6187 | .type = ALC_FIXUP_FUNC, |
| 6188 | .v.func = alc861vd_fixup_dallas, |
| 6189 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6190 | }; |
| 6191 | |
| 6192 | static const struct snd_pci_quirk alc861vd_fixup_tbl[] = { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 6193 | SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6194 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1), |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 6195 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6196 | {} |
| 6197 | }; |
| 6198 | |
| 6199 | static const struct hda_verb alc660vd_eapd_verbs[] = { |
| 6200 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2}, |
| 6201 | {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2}, |
| 6202 | { } |
| 6203 | }; |
| 6204 | |
| 6205 | /* |
| 6206 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6207 | static int patch_alc861vd(struct hda_codec *codec) |
| 6208 | { |
| 6209 | struct alc_spec *spec; |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 6210 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6211 | |
| 6212 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 6213 | if (spec == NULL) |
| 6214 | return -ENOMEM; |
| 6215 | |
| 6216 | codec->spec = spec; |
| 6217 | |
| 6218 | spec->mixer_nid = 0x0b; |
| 6219 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 6220 | alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); |
| 6221 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6222 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 6223 | /* automatic parse from the BIOS config */ |
| 6224 | err = alc861vd_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6225 | if (err < 0) |
| 6226 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6227 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6228 | if (codec->vendor_id == 0x10ec0660) { |
| 6229 | /* always turn on EAPD */ |
| 6230 | add_verb(spec, alc660vd_eapd_verbs); |
| 6231 | } |
| 6232 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 6233 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6234 | alc_auto_fill_adc_caps(codec); |
| 6235 | alc_rebuild_imux_for_auto_mic(codec); |
| 6236 | alc_remove_invalid_adc_nids(codec); |
| 6237 | } |
| 6238 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6239 | if (!spec->no_analog && !spec->cap_mixer) |
| 6240 | set_capture_mixer(codec); |
| 6241 | |
| 6242 | if (!spec->no_analog) { |
| 6243 | err = snd_hda_attach_beep_device(codec, 0x23); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6244 | if (err < 0) |
| 6245 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6246 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 6247 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6248 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6249 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 6250 | |
| 6251 | codec->patch_ops = alc_patch_ops; |
| 6252 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 6253 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6254 | spec->shutup = alc_eapd_shutup; |
| 6255 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 6256 | if (!spec->loopback.amplist) |
| 6257 | spec->loopback.amplist = alc861vd_loopbacks; |
| 6258 | #endif |
| 6259 | |
| 6260 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6261 | |
| 6262 | error: |
| 6263 | alc_free(codec); |
| 6264 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6265 | } |
| 6266 | |
| 6267 | /* |
| 6268 | * ALC662 support |
| 6269 | * |
| 6270 | * ALC662 is almost identical with ALC880 but has cleaner and more flexible |
| 6271 | * configuration. Each pin widget can choose any input DACs and a mixer. |
| 6272 | * Each ADC is connected from a mixer of all inputs. This makes possible |
| 6273 | * 6-channel independent captures. |
| 6274 | * |
| 6275 | * In addition, an independent DAC for the multi-playback (not used in this |
| 6276 | * driver yet). |
| 6277 | */ |
| 6278 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 6279 | #define alc662_loopbacks alc880_loopbacks |
| 6280 | #endif |
| 6281 | |
| 6282 | /* |
| 6283 | * BIOS auto configuration |
| 6284 | */ |
| 6285 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6286 | static int alc662_parse_auto_config(struct hda_codec *codec) |
| 6287 | { |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 6288 | static const hda_nid_t alc662_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6289 | static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 }; |
| 6290 | static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 6291 | const hda_nid_t *ssids; |
Takashi Iwai | ee979a14 | 2008-09-02 15:42:20 +0200 | [diff] [blame] | 6292 | |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 6293 | if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 || |
| 6294 | codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670) |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6295 | ssids = alc663_ssids; |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 6296 | else |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6297 | ssids = alc662_ssids; |
| 6298 | return alc_parse_auto_config(codec, alc662_ignore, ssids); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6299 | } |
| 6300 | |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 6301 | static void alc272_fixup_mario(struct hda_codec *codec, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 6302 | const struct alc_fixup *fix, int action) |
Takashi Iwai | 6fc398c | 2011-01-13 14:36:37 +0100 | [diff] [blame] | 6303 | { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 6304 | if (action != ALC_FIXUP_ACT_PROBE) |
Takashi Iwai | 6fc398c | 2011-01-13 14:36:37 +0100 | [diff] [blame] | 6305 | return; |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 6306 | if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT, |
| 6307 | (0x3b << AC_AMPCAP_OFFSET_SHIFT) | |
| 6308 | (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 6309 | (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 6310 | (0 << AC_AMPCAP_MUTE_SHIFT))) |
| 6311 | printk(KERN_WARNING |
| 6312 | "hda_codec: failed to override amp caps for NID 0x2\n"); |
| 6313 | } |
| 6314 | |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6315 | enum { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 6316 | ALC662_FIXUP_ASPIRE, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6317 | ALC662_FIXUP_IDEAPAD, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 6318 | ALC272_FIXUP_MARIO, |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 6319 | ALC662_FIXUP_CZC_P10T, |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 6320 | ALC662_FIXUP_SKU_IGNORE, |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 6321 | ALC662_FIXUP_HP_RP5800, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6322 | ALC662_FIXUP_ASUS_MODE1, |
| 6323 | ALC662_FIXUP_ASUS_MODE2, |
| 6324 | ALC662_FIXUP_ASUS_MODE3, |
| 6325 | ALC662_FIXUP_ASUS_MODE4, |
| 6326 | ALC662_FIXUP_ASUS_MODE5, |
| 6327 | ALC662_FIXUP_ASUS_MODE6, |
| 6328 | ALC662_FIXUP_ASUS_MODE7, |
| 6329 | ALC662_FIXUP_ASUS_MODE8, |
Takashi Iwai | 1565cc3 | 2012-02-13 12:03:25 +0100 | [diff] [blame] | 6330 | ALC662_FIXUP_NO_JACK_DETECT, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6331 | }; |
| 6332 | |
| 6333 | static const struct alc_fixup alc662_fixups[] = { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 6334 | [ALC662_FIXUP_ASPIRE] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 6335 | .type = ALC_FIXUP_PINS, |
| 6336 | .v.pins = (const struct alc_pincfg[]) { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 6337 | { 0x15, 0x99130112 }, /* subwoofer */ |
| 6338 | { } |
| 6339 | } |
| 6340 | }, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6341 | [ALC662_FIXUP_IDEAPAD] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 6342 | .type = ALC_FIXUP_PINS, |
| 6343 | .v.pins = (const struct alc_pincfg[]) { |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6344 | { 0x17, 0x99130112 }, /* subwoofer */ |
| 6345 | { } |
| 6346 | } |
| 6347 | }, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 6348 | [ALC272_FIXUP_MARIO] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 6349 | .type = ALC_FIXUP_FUNC, |
| 6350 | .v.func = alc272_fixup_mario, |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 6351 | }, |
| 6352 | [ALC662_FIXUP_CZC_P10T] = { |
| 6353 | .type = ALC_FIXUP_VERBS, |
| 6354 | .v.verbs = (const struct hda_verb[]) { |
| 6355 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, |
| 6356 | {} |
| 6357 | } |
| 6358 | }, |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 6359 | [ALC662_FIXUP_SKU_IGNORE] = { |
| 6360 | .type = ALC_FIXUP_SKU, |
| 6361 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
Takashi Iwai | c6b3587 | 2011-03-28 12:05:31 +0200 | [diff] [blame] | 6362 | }, |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 6363 | [ALC662_FIXUP_HP_RP5800] = { |
| 6364 | .type = ALC_FIXUP_PINS, |
| 6365 | .v.pins = (const struct alc_pincfg[]) { |
| 6366 | { 0x14, 0x0221201f }, /* HP out */ |
| 6367 | { } |
| 6368 | }, |
| 6369 | .chained = true, |
| 6370 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6371 | }, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6372 | [ALC662_FIXUP_ASUS_MODE1] = { |
| 6373 | .type = ALC_FIXUP_PINS, |
| 6374 | .v.pins = (const struct alc_pincfg[]) { |
| 6375 | { 0x14, 0x99130110 }, /* speaker */ |
| 6376 | { 0x18, 0x01a19c20 }, /* mic */ |
| 6377 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 6378 | { 0x21, 0x0121401f }, /* HP out */ |
| 6379 | { } |
| 6380 | }, |
| 6381 | .chained = true, |
| 6382 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6383 | }, |
| 6384 | [ALC662_FIXUP_ASUS_MODE2] = { |
Takashi Iwai | 2996bdb | 2011-08-18 16:02:24 +0200 | [diff] [blame] | 6385 | .type = ALC_FIXUP_PINS, |
| 6386 | .v.pins = (const struct alc_pincfg[]) { |
| 6387 | { 0x14, 0x99130110 }, /* speaker */ |
| 6388 | { 0x18, 0x01a19820 }, /* mic */ |
| 6389 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 6390 | { 0x1b, 0x0121401f }, /* HP out */ |
| 6391 | { } |
| 6392 | }, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6393 | .chained = true, |
| 6394 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6395 | }, |
| 6396 | [ALC662_FIXUP_ASUS_MODE3] = { |
| 6397 | .type = ALC_FIXUP_PINS, |
| 6398 | .v.pins = (const struct alc_pincfg[]) { |
| 6399 | { 0x14, 0x99130110 }, /* speaker */ |
| 6400 | { 0x15, 0x0121441f }, /* HP */ |
| 6401 | { 0x18, 0x01a19840 }, /* mic */ |
| 6402 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 6403 | { 0x21, 0x01211420 }, /* HP2 */ |
| 6404 | { } |
| 6405 | }, |
| 6406 | .chained = true, |
| 6407 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6408 | }, |
| 6409 | [ALC662_FIXUP_ASUS_MODE4] = { |
| 6410 | .type = ALC_FIXUP_PINS, |
| 6411 | .v.pins = (const struct alc_pincfg[]) { |
| 6412 | { 0x14, 0x99130110 }, /* speaker */ |
| 6413 | { 0x16, 0x99130111 }, /* speaker */ |
| 6414 | { 0x18, 0x01a19840 }, /* mic */ |
| 6415 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 6416 | { 0x21, 0x0121441f }, /* HP */ |
| 6417 | { } |
| 6418 | }, |
| 6419 | .chained = true, |
| 6420 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6421 | }, |
| 6422 | [ALC662_FIXUP_ASUS_MODE5] = { |
| 6423 | .type = ALC_FIXUP_PINS, |
| 6424 | .v.pins = (const struct alc_pincfg[]) { |
| 6425 | { 0x14, 0x99130110 }, /* speaker */ |
| 6426 | { 0x15, 0x0121441f }, /* HP */ |
| 6427 | { 0x16, 0x99130111 }, /* speaker */ |
| 6428 | { 0x18, 0x01a19840 }, /* mic */ |
| 6429 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 6430 | { } |
| 6431 | }, |
| 6432 | .chained = true, |
| 6433 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6434 | }, |
| 6435 | [ALC662_FIXUP_ASUS_MODE6] = { |
| 6436 | .type = ALC_FIXUP_PINS, |
| 6437 | .v.pins = (const struct alc_pincfg[]) { |
| 6438 | { 0x14, 0x99130110 }, /* speaker */ |
| 6439 | { 0x15, 0x01211420 }, /* HP2 */ |
| 6440 | { 0x18, 0x01a19840 }, /* mic */ |
| 6441 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 6442 | { 0x1b, 0x0121441f }, /* HP */ |
| 6443 | { } |
| 6444 | }, |
| 6445 | .chained = true, |
| 6446 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6447 | }, |
| 6448 | [ALC662_FIXUP_ASUS_MODE7] = { |
| 6449 | .type = ALC_FIXUP_PINS, |
| 6450 | .v.pins = (const struct alc_pincfg[]) { |
| 6451 | { 0x14, 0x99130110 }, /* speaker */ |
| 6452 | { 0x17, 0x99130111 }, /* speaker */ |
| 6453 | { 0x18, 0x01a19840 }, /* mic */ |
| 6454 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 6455 | { 0x1b, 0x01214020 }, /* HP */ |
| 6456 | { 0x21, 0x0121401f }, /* HP */ |
| 6457 | { } |
| 6458 | }, |
| 6459 | .chained = true, |
| 6460 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 6461 | }, |
| 6462 | [ALC662_FIXUP_ASUS_MODE8] = { |
| 6463 | .type = ALC_FIXUP_PINS, |
| 6464 | .v.pins = (const struct alc_pincfg[]) { |
| 6465 | { 0x14, 0x99130110 }, /* speaker */ |
| 6466 | { 0x12, 0x99a30970 }, /* int-mic */ |
| 6467 | { 0x15, 0x01214020 }, /* HP */ |
| 6468 | { 0x17, 0x99130111 }, /* speaker */ |
| 6469 | { 0x18, 0x01a19840 }, /* mic */ |
| 6470 | { 0x21, 0x0121401f }, /* HP */ |
| 6471 | { } |
| 6472 | }, |
| 6473 | .chained = true, |
| 6474 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
Takashi Iwai | 2996bdb | 2011-08-18 16:02:24 +0200 | [diff] [blame] | 6475 | }, |
Takashi Iwai | 1565cc3 | 2012-02-13 12:03:25 +0100 | [diff] [blame] | 6476 | [ALC662_FIXUP_NO_JACK_DETECT] = { |
| 6477 | .type = ALC_FIXUP_FUNC, |
| 6478 | .v.func = alc_fixup_no_jack_detect, |
| 6479 | }, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6480 | }; |
| 6481 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 6482 | static const struct snd_pci_quirk alc662_fixup_tbl[] = { |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6483 | SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2), |
David Henningsson | a6c47a8 | 2011-02-10 15:39:19 +0100 | [diff] [blame] | 6484 | SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE), |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 6485 | SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE), |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 6486 | SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE), |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 6487 | SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), |
Takashi Iwai | 1565cc3 | 2012-02-13 12:03:25 +0100 | [diff] [blame] | 6488 | SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT), |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6489 | SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2), |
Daniel T Chen | a0e90ac | 2010-11-20 10:20:35 -0500 | [diff] [blame] | 6490 | SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD), |
Valentine Sinitsyn | d411858 | 2010-10-01 22:24:08 +0600 | [diff] [blame] | 6491 | SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD), |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6492 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD), |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 6493 | SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T), |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6494 | |
| 6495 | #if 0 |
| 6496 | /* Below is a quirk table taken from the old code. |
| 6497 | * Basically the device should work as is without the fixup table. |
| 6498 | * If BIOS doesn't give a proper info, enable the corresponding |
| 6499 | * fixup entry. |
| 6500 | */ |
| 6501 | SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1), |
| 6502 | SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3), |
| 6503 | SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1), |
| 6504 | SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3), |
| 6505 | SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 6506 | SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6507 | SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 6508 | SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1), |
| 6509 | SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1), |
| 6510 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6511 | SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7), |
| 6512 | SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7), |
| 6513 | SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8), |
| 6514 | SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3), |
| 6515 | SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1), |
| 6516 | SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6517 | SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2), |
| 6518 | SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1), |
| 6519 | SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6520 | SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 6521 | SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 6522 | SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6523 | SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1), |
| 6524 | SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3), |
| 6525 | SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2), |
| 6526 | SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6527 | SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5), |
| 6528 | SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 6529 | SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6530 | SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1), |
| 6531 | SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6532 | SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6533 | SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3), |
| 6534 | SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3), |
| 6535 | SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1), |
| 6536 | SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1), |
| 6537 | SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1), |
| 6538 | SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1), |
| 6539 | SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1), |
| 6540 | SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 6541 | SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2), |
| 6542 | SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1), |
| 6543 | SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 6544 | SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3), |
| 6545 | SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1), |
| 6546 | SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1), |
| 6547 | SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1), |
| 6548 | SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2), |
| 6549 | SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 6550 | SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4), |
| 6551 | #endif |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6552 | {} |
| 6553 | }; |
| 6554 | |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 6555 | static const struct alc_model_fixup alc662_fixup_models[] = { |
| 6556 | {.id = ALC272_FIXUP_MARIO, .name = "mario"}, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6557 | {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"}, |
| 6558 | {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"}, |
| 6559 | {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"}, |
| 6560 | {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"}, |
| 6561 | {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"}, |
| 6562 | {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"}, |
| 6563 | {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"}, |
| 6564 | {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"}, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 6565 | {} |
| 6566 | }; |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6567 | |
| 6568 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 6569 | /* |
| 6570 | */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6571 | static int patch_alc662(struct hda_codec *codec) |
| 6572 | { |
| 6573 | struct alc_spec *spec; |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 6574 | int err = 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6575 | |
| 6576 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 6577 | if (!spec) |
| 6578 | return -ENOMEM; |
| 6579 | |
| 6580 | codec->spec = spec; |
| 6581 | |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 6582 | spec->mixer_nid = 0x0b; |
| 6583 | |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 6584 | /* handle multiple HPs as is */ |
| 6585 | spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; |
| 6586 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 6587 | alc_auto_parse_customize_define(codec); |
| 6588 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 6589 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
| 6590 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6591 | err = alc_codec_rename_from_preset(codec); |
| 6592 | if (err < 0) |
| 6593 | goto error; |
| 6594 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 6595 | if ((alc_get_coef0(codec) & (1 << 14)) && |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6596 | codec->bus->pci->subsystem_vendor == 0x1025 && |
| 6597 | spec->cdefine.platform_type == 1) { |
| 6598 | if (alc_codec_rename(codec, "ALC272X") < 0) |
| 6599 | goto error; |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 6600 | } |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 6601 | |
Takashi Iwai | b9c5106 | 2011-08-24 18:08:07 +0200 | [diff] [blame] | 6602 | alc_pick_fixup(codec, alc662_fixup_models, |
| 6603 | alc662_fixup_tbl, alc662_fixups); |
| 6604 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 6605 | /* automatic parse from the BIOS config */ |
| 6606 | err = alc662_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6607 | if (err < 0) |
| 6608 | goto error; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6609 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 6610 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 6611 | alc_auto_fill_adc_caps(codec); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 6612 | alc_rebuild_imux_for_auto_mic(codec); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 6613 | alc_remove_invalid_adc_nids(codec); |
Takashi Iwai | dd70469 | 2009-08-11 08:45:11 +0200 | [diff] [blame] | 6614 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6615 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6616 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | b59bdf3 | 2009-08-11 09:47:30 +0200 | [diff] [blame] | 6617 | set_capture_mixer(codec); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 6618 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6619 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 6620 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6621 | if (err < 0) |
| 6622 | goto error; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 6623 | switch (codec->vendor_id) { |
| 6624 | case 0x10ec0662: |
| 6625 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 6626 | break; |
| 6627 | case 0x10ec0272: |
| 6628 | case 0x10ec0663: |
| 6629 | case 0x10ec0665: |
| 6630 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
| 6631 | break; |
| 6632 | case 0x10ec0273: |
| 6633 | set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT); |
| 6634 | break; |
| 6635 | } |
Kailang Yang | cec27c8 | 2010-02-04 14:18:18 +0100 | [diff] [blame] | 6636 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 6637 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 6638 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 6639 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6640 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | b9c5106 | 2011-08-24 18:08:07 +0200 | [diff] [blame] | 6641 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1c716153 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 6642 | spec->shutup = alc_eapd_shutup; |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 6643 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 6644 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 6645 | if (!spec->loopback.amplist) |
| 6646 | spec->loopback.amplist = alc662_loopbacks; |
| 6647 | #endif |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6648 | |
| 6649 | return 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6650 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6651 | error: |
| 6652 | alc_free(codec); |
| 6653 | return err; |
Kailang Yang | b478b99 | 2011-05-18 11:51:15 +0200 | [diff] [blame] | 6654 | } |
| 6655 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6656 | /* |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6657 | * ALC680 support |
| 6658 | */ |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6659 | |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6660 | static int alc680_parse_auto_config(struct hda_codec *codec) |
| 6661 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6662 | return alc_parse_auto_config(codec, NULL, NULL); |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6663 | } |
| 6664 | |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6665 | /* |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6666 | */ |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6667 | static int patch_alc680(struct hda_codec *codec) |
| 6668 | { |
| 6669 | struct alc_spec *spec; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6670 | int err; |
| 6671 | |
| 6672 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 6673 | if (spec == NULL) |
| 6674 | return -ENOMEM; |
| 6675 | |
| 6676 | codec->spec = spec; |
| 6677 | |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 6678 | /* ALC680 has no aa-loopback mixer */ |
| 6679 | |
Takashi Iwai | 1ebec5f | 2011-08-15 13:21:48 +0200 | [diff] [blame] | 6680 | /* automatic parse from the BIOS config */ |
| 6681 | err = alc680_parse_auto_config(codec); |
| 6682 | if (err < 0) { |
| 6683 | alc_free(codec); |
| 6684 | return err; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6685 | } |
| 6686 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 6687 | if (!spec->no_analog && !spec->cap_mixer) |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6688 | set_capture_mixer(codec); |
| 6689 | |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6690 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 1ebec5f | 2011-08-15 13:21:48 +0200 | [diff] [blame] | 6691 | spec->init_hook = alc_auto_init_std; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6692 | |
| 6693 | return 0; |
| 6694 | } |
| 6695 | |
| 6696 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6697 | * patch entries |
| 6698 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 6699 | static const struct hda_codec_preset snd_hda_preset_realtek[] = { |
Kailang Yang | 296f033 | 2011-05-18 11:52:36 +0200 | [diff] [blame] | 6700 | { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6701 | { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 }, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 6702 | { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 }, |
Kailang Yang | f6a9224 | 2007-12-13 16:52:54 +0100 | [diff] [blame] | 6703 | { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 }, |
Kailang Yang | a361d84 | 2007-06-05 12:30:55 +0200 | [diff] [blame] | 6704 | { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 }, |
Kailang Yang | f6a9224 | 2007-12-13 16:52:54 +0100 | [diff] [blame] | 6705 | { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 }, |
Kailang Yang | ebb83ee | 2009-12-17 12:23:00 +0100 | [diff] [blame] | 6706 | { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 }, |
Kailang Yang | 01afd41 | 2008-10-15 11:22:09 +0200 | [diff] [blame] | 6707 | { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 }, |
Kailang Yang | ebb83ee | 2009-12-17 12:23:00 +0100 | [diff] [blame] | 6708 | { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 }, |
Kailang Yang | 296f033 | 2011-05-18 11:52:36 +0200 | [diff] [blame] | 6709 | { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 6710 | { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660", |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6711 | .patch = patch_alc861 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 6712 | { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd }, |
| 6713 | { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 }, |
| 6714 | { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd }, |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6715 | { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 6716 | .patch = patch_alc882 }, |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 6717 | { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1", |
| 6718 | .patch = patch_alc662 }, |
David Henningsson | cc667a7 | 2011-10-18 14:07:51 +0200 | [diff] [blame] | 6719 | { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3", |
| 6720 | .patch = patch_alc662 }, |
Kailang Yang | 6dda9f4 | 2008-05-27 12:05:31 +0200 | [diff] [blame] | 6721 | { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 }, |
Kailang Yang | cec27c8 | 2010-02-04 14:18:18 +0100 | [diff] [blame] | 6722 | { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 }, |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 6723 | { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 }, |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 6724 | { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 6725 | { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6726 | { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 6727 | { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 }, |
Clive Messer | 669faba | 2008-09-30 15:49:13 +0200 | [diff] [blame] | 6728 | { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 6729 | .patch = patch_alc882 }, |
Takashi Iwai | cb308f9 | 2008-04-16 14:13:29 +0200 | [diff] [blame] | 6730 | { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 6731 | .patch = patch_alc882 }, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 6732 | { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6733 | { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 }, |
Kailang Yang | 4442608 | 2008-10-15 11:18:05 +0200 | [diff] [blame] | 6734 | { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 6735 | .patch = patch_alc882 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6736 | { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 }, |
Takashi Iwai | 4953550a | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 6737 | { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 }, |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 6738 | { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 6739 | { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6740 | {} /* terminator */ |
| 6741 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 6742 | |
| 6743 | MODULE_ALIAS("snd-hda-codec-id:10ec*"); |
| 6744 | |
| 6745 | MODULE_LICENSE("GPL"); |
| 6746 | MODULE_DESCRIPTION("Realtek HD-audio codec"); |
| 6747 | |
| 6748 | static struct hda_codec_preset_list realtek_list = { |
| 6749 | .preset = snd_hda_preset_realtek, |
| 6750 | .owner = THIS_MODULE, |
| 6751 | }; |
| 6752 | |
| 6753 | static int __init patch_realtek_init(void) |
| 6754 | { |
| 6755 | return snd_hda_add_codec_preset(&realtek_list); |
| 6756 | } |
| 6757 | |
| 6758 | static void __exit patch_realtek_exit(void) |
| 6759 | { |
| 6760 | snd_hda_delete_codec_preset(&realtek_list); |
| 6761 | } |
| 6762 | |
| 6763 | module_init(patch_realtek_init) |
| 6764 | module_exit(patch_realtek_exit) |