Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Universal Interface for Intel High Definition Audio Codec |
| 3 | * |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4 | * HD audio interface patch for Realtek ALC codecs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 6 | * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw> |
| 7 | * PeiSen Hou <pshou@realtek.com.tw> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Takashi Iwai <tiwai@suse.de> |
Jonathan Woithe | 7cf51e4 | 2006-02-09 12:01:26 +0100 | [diff] [blame] | 9 | * Jonathan Woithe <jwoithe@physics.adelaide.edu.au> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * This driver is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This driver is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | */ |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/init.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/pci.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 30 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <sound/core.h> |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 32 | #include <sound/jack.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "hda_codec.h" |
| 34 | #include "hda_local.h" |
Kusanagi Kouichi | 680cd53 | 2009-02-05 00:00:58 +0900 | [diff] [blame] | 35 | #include "hda_beep.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 37 | /* unsol event tags */ |
| 38 | #define ALC_FRONT_EVENT 0x01 |
| 39 | #define ALC_DCVOL_EVENT 0x02 |
| 40 | #define ALC_HP_EVENT 0x04 |
| 41 | #define ALC_MIC_EVENT 0x08 |
Takashi Iwai | d4a86d8 | 2010-06-23 17:51:26 +0200 | [diff] [blame] | 42 | |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 43 | /* for GPIO Poll */ |
| 44 | #define GPIO_MASK 0x03 |
| 45 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 46 | /* extra amp-initialization sequence types */ |
| 47 | enum { |
| 48 | ALC_INIT_NONE, |
| 49 | ALC_INIT_DEFAULT, |
| 50 | ALC_INIT_GPIO1, |
| 51 | ALC_INIT_GPIO2, |
| 52 | ALC_INIT_GPIO3, |
| 53 | }; |
| 54 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 55 | struct alc_customize_define { |
| 56 | unsigned int sku_cfg; |
| 57 | unsigned char port_connectivity; |
| 58 | unsigned char check_sum; |
| 59 | unsigned char customization; |
| 60 | unsigned char external_amp; |
| 61 | unsigned int enable_pcbeep:1; |
| 62 | unsigned int platform_type:1; |
| 63 | unsigned int swap:1; |
| 64 | unsigned int override:1; |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 65 | unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */ |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 66 | }; |
| 67 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 68 | struct alc_fixup; |
| 69 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 70 | struct alc_multi_io { |
| 71 | hda_nid_t pin; /* multi-io widget pin NID */ |
| 72 | hda_nid_t dac; /* DAC to be connected */ |
| 73 | unsigned int ctl_in; /* cached input-pin control value */ |
| 74 | }; |
| 75 | |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 76 | enum { |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 77 | ALC_AUTOMUTE_PIN, /* change the pin control */ |
| 78 | ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */ |
| 79 | ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */ |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | struct alc_spec { |
| 83 | /* codec parameterization */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 84 | const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | unsigned int num_mixers; |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 86 | const struct snd_kcontrol_new *cap_mixer; /* capture mixer */ |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 87 | unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Takashi Iwai | 2d9c648 | 2009-10-13 08:06:55 +0200 | [diff] [blame] | 89 | const struct hda_verb *init_verbs[10]; /* initialization verbs |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 90 | * don't forget NULL |
| 91 | * termination! |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 92 | */ |
| 93 | unsigned int num_init_verbs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Takashi Iwai | aa563af | 2009-07-31 10:05:11 +0200 | [diff] [blame] | 95 | char stream_name_analog[32]; /* analog PCM stream */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 96 | const struct hda_pcm_stream *stream_analog_playback; |
| 97 | const struct hda_pcm_stream *stream_analog_capture; |
| 98 | const struct hda_pcm_stream *stream_analog_alt_playback; |
| 99 | const struct hda_pcm_stream *stream_analog_alt_capture; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Takashi Iwai | aa563af | 2009-07-31 10:05:11 +0200 | [diff] [blame] | 101 | char stream_name_digital[32]; /* digital PCM stream */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 102 | const struct hda_pcm_stream *stream_digital_playback; |
| 103 | const struct hda_pcm_stream *stream_digital_capture; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | /* playback */ |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 106 | struct hda_multi_out multiout; /* playback set-up |
| 107 | * max_channels, dacs must be set |
| 108 | * dig_out_nid and hp_nid are optional |
| 109 | */ |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 110 | hda_nid_t alt_dac_nid; |
Takashi Iwai | 6a05ac4 | 2009-02-13 11:19:09 +0100 | [diff] [blame] | 111 | hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */ |
Takashi Iwai | 8c44198 | 2009-01-20 18:30:20 +0100 | [diff] [blame] | 112 | int dig_out_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | /* capture */ |
| 115 | unsigned int num_adc_nids; |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 116 | const hda_nid_t *adc_nids; |
| 117 | const hda_nid_t *capsrc_nids; |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 118 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 119 | hda_nid_t mixer_nid; /* analog-mixer NID */ |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 120 | DECLARE_BITMAP(vol_ctls, 0x20 << 1); |
| 121 | DECLARE_BITMAP(sw_ctls, 0x20 << 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 123 | /* capture setup for dynamic dual-adc switch */ |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 124 | hda_nid_t cur_adc; |
| 125 | unsigned int cur_adc_stream_tag; |
| 126 | unsigned int cur_adc_format; |
| 127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | /* capture source */ |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 129 | unsigned int num_mux_defs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | const struct hda_input_mux *input_mux; |
| 131 | unsigned int cur_mux[3]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 132 | hda_nid_t ext_mic_pin; |
| 133 | hda_nid_t dock_mic_pin; |
| 134 | hda_nid_t int_mic_pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | /* channel model */ |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 137 | const struct hda_channel_mode *channel_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | int num_channel_mode; |
Takashi Iwai | 4e195a7 | 2006-07-28 14:47:34 +0200 | [diff] [blame] | 139 | int need_dac_fix; |
Hector Martin | 3b315d7 | 2009-06-02 10:54:19 +0200 | [diff] [blame] | 140 | int const_channel_count; |
| 141 | int ext_channel_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
| 143 | /* PCM information */ |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 144 | struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */ |
Takashi Iwai | 41e41f1 | 2005-06-08 14:48:49 +0200 | [diff] [blame] | 145 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 146 | /* dynamic controls, init_verbs and input_mux */ |
| 147 | struct auto_pin_cfg autocfg; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 148 | struct alc_customize_define cdefine; |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 149 | struct snd_array kctls; |
Herton Ronaldo Krzesinski | 61b9b9b | 2009-01-28 09:16:33 -0200 | [diff] [blame] | 150 | struct hda_input_mux private_imux[3]; |
Takashi Iwai | 41923e4 | 2007-10-22 17:20:10 +0200 | [diff] [blame] | 151 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | 4953550 | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 152 | hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS]; |
| 153 | hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 154 | hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS]; |
| 155 | unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS]; |
| 156 | int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */ |
Takashi Iwai | 834be88 | 2006-03-01 14:16:17 +0100 | [diff] [blame] | 157 | |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 158 | /* hooks */ |
| 159 | void (*init_hook)(struct hda_codec *codec); |
| 160 | void (*unsol_event)(struct hda_codec *codec, unsigned int res); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 161 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 162 | void (*power_hook)(struct hda_codec *codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 163 | #endif |
Takashi Iwai | 1c71615 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 164 | void (*shutup)(struct hda_codec *codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 165 | void (*automute_hook)(struct hda_codec *codec); |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 166 | |
Takashi Iwai | 834be88 | 2006-03-01 14:16:17 +0100 | [diff] [blame] | 167 | /* for pin sensing */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 168 | unsigned int hp_jack_present:1; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 169 | unsigned int line_jack_present:1; |
Takashi Iwai | e942796 | 2011-04-28 15:46:07 +0200 | [diff] [blame] | 170 | unsigned int master_mute:1; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 171 | unsigned int auto_mic:1; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 172 | unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 173 | unsigned int automute_speaker:1; /* automute speaker outputs */ |
| 174 | unsigned int automute_lo:1; /* automute LO outputs */ |
| 175 | unsigned int detect_hp:1; /* Headphone detection enabled */ |
| 176 | unsigned int detect_lo:1; /* Line-out detection enabled */ |
| 177 | unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */ |
| 178 | unsigned int automute_lo_possible:1; /* there are line outs and HP */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 179 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 180 | /* other flags */ |
| 181 | unsigned int no_analog :1; /* digital I/O only */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 182 | unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */ |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 183 | unsigned int single_input_src:1; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 184 | unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */ |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 185 | unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */ |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 186 | unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */ |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 187 | |
| 188 | /* auto-mute control */ |
| 189 | int automute_mode; |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 190 | hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 191 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 192 | int init_amp; |
Takashi Iwai | d433a67 | 2010-09-20 15:11:54 +0200 | [diff] [blame] | 193 | int codec_variant; /* flag for other variants */ |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 194 | |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 195 | /* for virtual master */ |
| 196 | hda_nid_t vmaster_nid; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 197 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 198 | struct hda_loopback_check loopback; |
| 199 | #endif |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 200 | |
| 201 | /* for PLL fix */ |
| 202 | hda_nid_t pll_nid; |
| 203 | unsigned int pll_coef_idx, pll_coef_bit; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 204 | unsigned int coef0; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 205 | |
| 206 | /* fix-up list */ |
| 207 | int fixup_id; |
| 208 | const struct alc_fixup *fixup_list; |
| 209 | const char *fixup_name; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 210 | |
| 211 | /* multi-io */ |
| 212 | int multi_ios; |
| 213 | struct alc_multi_io multi_io[4]; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 214 | |
| 215 | /* bind volumes */ |
| 216 | struct snd_array bind_ctls; |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 217 | }; |
| 218 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 219 | #define ALC_MODEL_AUTO 0 /* common for all chips */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 221 | static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, |
| 222 | int dir, unsigned int bits) |
| 223 | { |
| 224 | if (!nid) |
| 225 | return false; |
| 226 | if (get_wcaps(codec, nid) & (1 << (dir + 1))) |
| 227 | if (query_amp_caps(codec, nid, dir) & bits) |
| 228 | return true; |
| 229 | return false; |
| 230 | } |
| 231 | |
| 232 | #define nid_has_mute(codec, nid, dir) \ |
| 233 | check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE) |
| 234 | #define nid_has_volume(codec, nid, dir) \ |
| 235 | check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS) |
| 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | /* |
| 238 | * input MUX handling |
| 239 | */ |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 240 | static int alc_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 241 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
| 243 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 244 | struct alc_spec *spec = codec->spec; |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 245 | unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id); |
| 246 | if (mux_idx >= spec->num_mux_defs) |
| 247 | mux_idx = 0; |
Takashi Iwai | 5311114 | 2010-03-08 12:13:07 +0100 | [diff] [blame] | 248 | if (!spec->input_mux[mux_idx].num_items && mux_idx > 0) |
| 249 | mux_idx = 0; |
Jonathan Woithe | a1e8d2d | 2006-03-28 12:47:09 +0200 | [diff] [blame] | 250 | return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 253 | static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 254 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
| 256 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 257 | struct alc_spec *spec = codec->spec; |
| 258 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 259 | |
| 260 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
| 261 | return 0; |
| 262 | } |
| 263 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 264 | 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] | 265 | { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 266 | struct alc_spec *spec = codec->spec; |
| 267 | hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]]; |
| 268 | |
| 269 | if (spec->cur_adc && spec->cur_adc != new_adc) { |
| 270 | /* stream is running, let's swap the current ADC */ |
| 271 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); |
| 272 | spec->cur_adc = new_adc; |
| 273 | snd_hda_codec_setup_stream(codec, new_adc, |
| 274 | spec->cur_adc_stream_tag, 0, |
| 275 | spec->cur_adc_format); |
| 276 | return true; |
| 277 | } |
| 278 | return false; |
| 279 | } |
| 280 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 281 | static void call_update_outputs(struct hda_codec *codec); |
| 282 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 283 | /* select the given imux item; either unmute exclusively or select the route */ |
| 284 | static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx, |
| 285 | unsigned int idx, bool force) |
| 286 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 288 | const struct hda_input_mux *imux; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 289 | unsigned int mux_idx; |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 290 | int i, type, num_conns; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 291 | hda_nid_t nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 293 | mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; |
| 294 | imux = &spec->input_mux[mux_idx]; |
Takashi Iwai | 5311114 | 2010-03-08 12:13:07 +0100 | [diff] [blame] | 295 | if (!imux->num_items && mux_idx > 0) |
| 296 | imux = &spec->input_mux[0]; |
Takashi Iwai | cd896c3 | 2008-11-18 12:36:33 +0100 | [diff] [blame] | 297 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 298 | if (idx >= imux->num_items) |
| 299 | idx = imux->num_items - 1; |
| 300 | if (spec->cur_mux[adc_idx] == idx && !force) |
| 301 | return 0; |
| 302 | spec->cur_mux[adc_idx] = idx; |
| 303 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 304 | /* for shared I/O, change the pin-control accordingly */ |
| 305 | if (spec->shared_mic_hp) { |
| 306 | /* NOTE: this assumes that there are only two inputs, the |
| 307 | * first is the real internal mic and the second is HP jack. |
| 308 | */ |
| 309 | snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0, |
| 310 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 311 | spec->cur_mux[adc_idx] ? |
| 312 | PIN_VREF80 : PIN_HP); |
| 313 | spec->automute_speaker = !spec->cur_mux[adc_idx]; |
| 314 | call_update_outputs(codec); |
| 315 | } |
| 316 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 317 | if (spec->dyn_adc_switch) { |
| 318 | alc_dyn_adc_pcm_resetup(codec, idx); |
| 319 | adc_idx = spec->dyn_adc_idx[idx]; |
| 320 | } |
| 321 | |
| 322 | nid = spec->capsrc_nids ? |
| 323 | spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx]; |
| 324 | |
| 325 | /* no selection? */ |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 326 | num_conns = snd_hda_get_conn_list(codec, nid, NULL); |
| 327 | if (num_conns <= 1) |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 328 | return 1; |
| 329 | |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 330 | type = get_wcaps_type(get_wcaps(codec, nid)); |
Takashi Iwai | 0169b6b | 2009-06-22 10:50:19 +0200 | [diff] [blame] | 331 | if (type == AC_WID_AUD_MIX) { |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 332 | /* Matrix-mixer style (e.g. ALC882) */ |
Takashi Iwai | dccc181 | 2011-11-08 07:52:19 +0100 | [diff] [blame] | 333 | int active = imux->items[idx].index; |
| 334 | for (i = 0; i < num_conns; i++) { |
| 335 | unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE; |
| 336 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i, |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 337 | HDA_AMP_MUTE, v); |
| 338 | } |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 339 | } else { |
| 340 | /* MUX style (e.g. ALC880) */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 341 | snd_hda_codec_write_cache(codec, nid, 0, |
| 342 | AC_VERB_SET_CONNECT_SEL, |
| 343 | imux->items[idx].index); |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 344 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 345 | return 1; |
| 346 | } |
| 347 | |
| 348 | static int alc_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 349 | struct snd_ctl_elem_value *ucontrol) |
| 350 | { |
| 351 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 352 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 353 | return alc_mux_select(codec, adc_idx, |
| 354 | ucontrol->value.enumerated.item[0], false); |
Takashi Iwai | 54cbc9a | 2008-10-31 15:24:04 +0100 | [diff] [blame] | 355 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | /* |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 358 | * set up the input pin config (depending on the given auto-pin type) |
| 359 | */ |
| 360 | static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid, |
| 361 | int auto_pin_type) |
| 362 | { |
| 363 | unsigned int val = PIN_IN; |
| 364 | |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 365 | if (auto_pin_type == AUTO_PIN_MIC) { |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 366 | unsigned int pincap; |
Takashi Iwai | 954a29c | 2010-07-30 10:55:44 +0200 | [diff] [blame] | 367 | unsigned int oldval; |
| 368 | oldval = snd_hda_codec_read(codec, nid, 0, |
| 369 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
Takashi Iwai | 1327a32 | 2009-03-23 13:07:47 +0100 | [diff] [blame] | 370 | pincap = snd_hda_query_pin_caps(codec, nid); |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 371 | pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; |
Takashi Iwai | 954a29c | 2010-07-30 10:55:44 +0200 | [diff] [blame] | 372 | /* if the default pin setup is vref50, we give it priority */ |
| 373 | if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50) |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 374 | val = PIN_VREF80; |
Takashi Iwai | 461c6c3 | 2009-05-25 08:06:02 +0200 | [diff] [blame] | 375 | else if (pincap & AC_PINCAP_VREF_50) |
| 376 | val = PIN_VREF50; |
| 377 | else if (pincap & AC_PINCAP_VREF_100) |
| 378 | val = PIN_VREF100; |
| 379 | else if (pincap & AC_PINCAP_VREF_GRD) |
| 380 | val = PIN_VREFGRD; |
Takashi Iwai | 23f0c04 | 2009-02-26 13:03:58 +0100 | [diff] [blame] | 381 | } |
| 382 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val); |
| 383 | } |
| 384 | |
| 385 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 386 | * Append the given mixer and verb elements for the later use |
| 387 | * The mixer array is referred in build_controls(), and init_verbs are |
| 388 | * called in init(). |
Takashi Iwai | d88897e | 2008-10-31 15:01:37 +0100 | [diff] [blame] | 389 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 390 | 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] | 391 | { |
| 392 | if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers))) |
| 393 | return; |
| 394 | spec->mixers[spec->num_mixers++] = mix; |
| 395 | } |
| 396 | |
| 397 | static void add_verb(struct alc_spec *spec, const struct hda_verb *verb) |
| 398 | { |
| 399 | if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs))) |
| 400 | return; |
| 401 | spec->init_verbs[spec->num_init_verbs++] = verb; |
| 402 | } |
| 403 | |
| 404 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 405 | * GPIO setup tables, used in initialization |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 406 | */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 407 | /* Enable GPIO mask and set output */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 408 | static const struct hda_verb alc_gpio1_init_verbs[] = { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 409 | {0x01, AC_VERB_SET_GPIO_MASK, 0x01}, |
| 410 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, |
| 411 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, |
| 412 | { } |
| 413 | }; |
| 414 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 415 | static const struct hda_verb alc_gpio2_init_verbs[] = { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 416 | {0x01, AC_VERB_SET_GPIO_MASK, 0x02}, |
| 417 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02}, |
| 418 | {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, |
| 419 | { } |
| 420 | }; |
| 421 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 422 | static const struct hda_verb alc_gpio3_init_verbs[] = { |
Kailang Yang | bdd148a | 2007-05-08 15:19:08 +0200 | [diff] [blame] | 423 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, |
| 424 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03}, |
| 425 | {0x01, AC_VERB_SET_GPIO_DATA, 0x03}, |
| 426 | { } |
| 427 | }; |
| 428 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 429 | /* |
| 430 | * Fix hardware PLL issue |
| 431 | * On some codecs, the analog PLL gating control must be off while |
| 432 | * the default value is 1. |
| 433 | */ |
| 434 | static void alc_fix_pll(struct hda_codec *codec) |
| 435 | { |
| 436 | struct alc_spec *spec = codec->spec; |
| 437 | unsigned int val; |
| 438 | |
| 439 | if (!spec->pll_nid) |
| 440 | return; |
| 441 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, |
| 442 | spec->pll_coef_idx); |
| 443 | val = snd_hda_codec_read(codec, spec->pll_nid, 0, |
| 444 | AC_VERB_GET_PROC_COEF, 0); |
| 445 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, |
| 446 | spec->pll_coef_idx); |
| 447 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF, |
| 448 | val & ~(1 << spec->pll_coef_bit)); |
| 449 | } |
| 450 | |
| 451 | static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid, |
| 452 | unsigned int coef_idx, unsigned int coef_bit) |
| 453 | { |
| 454 | struct alc_spec *spec = codec->spec; |
| 455 | spec->pll_nid = nid; |
| 456 | spec->pll_coef_idx = coef_idx; |
| 457 | spec->pll_coef_bit = coef_bit; |
| 458 | alc_fix_pll(codec); |
| 459 | } |
| 460 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 461 | /* |
| 462 | * Jack-reporting via input-jack layer |
| 463 | */ |
| 464 | |
| 465 | /* initialization of jacks; currently checks only a few known pins */ |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 466 | static int alc_init_jacks(struct hda_codec *codec) |
| 467 | { |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 468 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 469 | struct alc_spec *spec = codec->spec; |
| 470 | int err; |
| 471 | unsigned int hp_nid = spec->autocfg.hp_pins[0]; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 472 | unsigned int mic_nid = spec->ext_mic_pin; |
| 473 | unsigned int dock_nid = spec->dock_mic_pin; |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 474 | |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 475 | if (hp_nid) { |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 476 | err = snd_hda_input_jack_add(codec, hp_nid, |
| 477 | SND_JACK_HEADPHONE, NULL); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 478 | if (err < 0) |
| 479 | return err; |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 480 | snd_hda_input_jack_report(codec, hp_nid); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 481 | } |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 482 | |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 483 | if (mic_nid) { |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 484 | err = snd_hda_input_jack_add(codec, mic_nid, |
| 485 | SND_JACK_MICROPHONE, NULL); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 486 | if (err < 0) |
| 487 | return err; |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 488 | snd_hda_input_jack_report(codec, mic_nid); |
Takashi Iwai | 265a024 | 2010-09-21 11:26:21 +0200 | [diff] [blame] | 489 | } |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 490 | if (dock_nid) { |
| 491 | err = snd_hda_input_jack_add(codec, dock_nid, |
| 492 | SND_JACK_MICROPHONE, NULL); |
| 493 | if (err < 0) |
| 494 | return err; |
| 495 | snd_hda_input_jack_report(codec, dock_nid); |
| 496 | } |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 497 | #endif /* CONFIG_SND_HDA_INPUT_JACK */ |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 498 | return 0; |
| 499 | } |
Kailang Yang | 9ad0e49 | 2010-09-14 23:22:00 +0200 | [diff] [blame] | 500 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 501 | /* |
| 502 | * Jack detections for HP auto-mute and mic-switch |
| 503 | */ |
| 504 | |
| 505 | /* check each pin in the given array; returns true if any of them is plugged */ |
| 506 | 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] | 507 | { |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 508 | int i, present = 0; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 509 | |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 510 | for (i = 0; i < num_pins; i++) { |
| 511 | hda_nid_t nid = pins[i]; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 512 | if (!nid) |
| 513 | break; |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 514 | snd_hda_input_jack_report(codec, nid); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 515 | present |= snd_hda_jack_detect(codec, nid); |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 516 | } |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 517 | return present; |
| 518 | } |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 519 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 520 | /* standard HP/line-out auto-mute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 521 | 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] | 522 | bool mute, bool hp_out) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 523 | { |
| 524 | struct alc_spec *spec = codec->spec; |
| 525 | unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0; |
Takashi Iwai | e942796 | 2011-04-28 15:46:07 +0200 | [diff] [blame] | 526 | unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 527 | int i; |
| 528 | |
| 529 | for (i = 0; i < num_pins; i++) { |
| 530 | hda_nid_t nid = pins[i]; |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 531 | if (!nid) |
| 532 | break; |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 533 | switch (spec->automute_mode) { |
| 534 | case ALC_AUTOMUTE_PIN: |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 535 | snd_hda_codec_write(codec, nid, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 536 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 537 | pin_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 538 | break; |
| 539 | case ALC_AUTOMUTE_AMP: |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 540 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 541 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 542 | break; |
| 543 | case ALC_AUTOMUTE_MIXER: |
| 544 | nid = spec->automute_mixer_nid[i]; |
| 545 | if (!nid) |
| 546 | break; |
| 547 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 548 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 549 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1, |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 550 | HDA_AMP_MUTE, mute_bits); |
Takashi Iwai | 3b8510c | 2011-04-28 14:03:24 +0200 | [diff] [blame] | 551 | break; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 552 | } |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 553 | } |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 554 | } |
| 555 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 556 | /* Toggle outputs muting */ |
| 557 | static void update_outputs(struct hda_codec *codec) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 558 | { |
| 559 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 560 | int on; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 561 | |
Takashi Iwai | c0a2026 | 2011-06-10 15:28:15 +0200 | [diff] [blame] | 562 | /* Control HP pins/amps depending on master_mute state; |
| 563 | * in general, HP pins/amps control should be enabled in all cases, |
| 564 | * but currently set only for master_mute, just to be safe |
| 565 | */ |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 566 | if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */ |
| 567 | do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins), |
Takashi Iwai | c0a2026 | 2011-06-10 15:28:15 +0200 | [diff] [blame] | 568 | spec->autocfg.hp_pins, spec->master_mute, true); |
| 569 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 570 | if (!spec->automute_speaker) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 571 | on = 0; |
| 572 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 573 | on = spec->hp_jack_present | spec->line_jack_present; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 574 | on |= spec->master_mute; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 575 | do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins), |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 576 | spec->autocfg.speaker_pins, on, false); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 577 | |
| 578 | /* toggle line-out mutes if needed, too */ |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 579 | /* if LO is a copy of either HP or Speaker, don't need to handle it */ |
| 580 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] || |
| 581 | spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0]) |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 582 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 583 | if (!spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 584 | on = 0; |
| 585 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 586 | on = spec->hp_jack_present; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 587 | on |= spec->master_mute; |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 588 | do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 589 | spec->autocfg.line_out_pins, on, false); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 590 | } |
| 591 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 592 | static void call_update_outputs(struct hda_codec *codec) |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 593 | { |
| 594 | struct alc_spec *spec = codec->spec; |
| 595 | if (spec->automute_hook) |
| 596 | spec->automute_hook(codec); |
| 597 | else |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 598 | update_outputs(codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 599 | } |
| 600 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 601 | /* standard HP-automute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 602 | static void alc_hp_automute(struct hda_codec *codec) |
| 603 | { |
| 604 | struct alc_spec *spec = codec->spec; |
| 605 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 606 | spec->hp_jack_present = |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 607 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins), |
| 608 | spec->autocfg.hp_pins); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 609 | if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo)) |
Takashi Iwai | 3c715a9 | 2011-08-23 12:41:09 +0200 | [diff] [blame] | 610 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 611 | call_update_outputs(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 612 | } |
| 613 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 614 | /* standard line-out-automute helper */ |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 615 | static void alc_line_automute(struct hda_codec *codec) |
| 616 | { |
| 617 | struct alc_spec *spec = codec->spec; |
| 618 | |
Takashi Iwai | e0d32e3 | 2011-09-26 15:19:55 +0200 | [diff] [blame] | 619 | /* check LO jack only when it's different from HP */ |
| 620 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0]) |
| 621 | return; |
| 622 | |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 623 | spec->line_jack_present = |
| 624 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
| 625 | spec->autocfg.line_out_pins); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 626 | if (!spec->automute_speaker || !spec->detect_lo) |
Takashi Iwai | 3c715a9 | 2011-08-23 12:41:09 +0200 | [diff] [blame] | 627 | return; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 628 | call_update_outputs(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 629 | } |
| 630 | |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 631 | #define get_connection_index(codec, mux, nid) \ |
| 632 | snd_hda_get_conn_index(codec, mux, nid, 0) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 633 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 634 | /* standard mic auto-switch helper */ |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 635 | static void alc_mic_automute(struct hda_codec *codec) |
| 636 | { |
| 637 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 638 | hda_nid_t *pins = spec->imux_pins; |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 639 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 640 | if (!spec->auto_mic || !spec->auto_mic_valid_imux) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 641 | return; |
| 642 | if (snd_BUG_ON(!spec->adc_nids)) |
| 643 | return; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 644 | 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] | 645 | return; |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 646 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 647 | if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx])) |
| 648 | alc_mux_select(codec, 0, spec->ext_mic_idx, false); |
| 649 | else if (spec->dock_mic_idx >= 0 && |
| 650 | snd_hda_jack_detect(codec, pins[spec->dock_mic_idx])) |
| 651 | alc_mux_select(codec, 0, spec->dock_mic_idx, false); |
| 652 | else |
| 653 | alc_mux_select(codec, 0, spec->int_mic_idx, false); |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 654 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 655 | snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]); |
| 656 | if (spec->dock_mic_idx >= 0) |
| 657 | snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 658 | } |
| 659 | |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 660 | /* unsolicited event for HP jack sensing */ |
| 661 | static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res) |
| 662 | { |
| 663 | if (codec->vendor_id == 0x10ec0880) |
| 664 | res >>= 28; |
| 665 | else |
| 666 | res >>= 26; |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 667 | switch (res) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 668 | case ALC_HP_EVENT: |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 669 | alc_hp_automute(codec); |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 670 | break; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 671 | case ALC_FRONT_EVENT: |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 672 | alc_line_automute(codec); |
| 673 | break; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 674 | case ALC_MIC_EVENT: |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 675 | alc_mic_automute(codec); |
Takashi Iwai | a9fd4f3 | 2009-05-08 15:57:59 +0200 | [diff] [blame] | 676 | break; |
| 677 | } |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 678 | } |
| 679 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 680 | /* call init functions of standard auto-mute helpers */ |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 681 | static void alc_inithook(struct hda_codec *codec) |
| 682 | { |
Takashi Iwai | d922b51 | 2011-04-28 12:18:53 +0200 | [diff] [blame] | 683 | alc_hp_automute(codec); |
Takashi Iwai | e6a5e1b | 2011-04-28 14:41:52 +0200 | [diff] [blame] | 684 | alc_line_automute(codec); |
Kailang Yang | 7fb0d78 | 2008-10-15 11:12:35 +0200 | [diff] [blame] | 685 | alc_mic_automute(codec); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 686 | } |
| 687 | |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 688 | /* additional initialization for ALC888 variants */ |
| 689 | static void alc888_coef_init(struct hda_codec *codec) |
| 690 | { |
| 691 | unsigned int tmp; |
| 692 | |
| 693 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0); |
| 694 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 695 | 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] | 696 | if ((tmp & 0xf0) == 0x20) |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 697 | /* alc888S-VC */ |
| 698 | snd_hda_codec_read(codec, 0x20, 0, |
| 699 | AC_VERB_SET_PROC_COEF, 0x830); |
| 700 | else |
| 701 | /* alc888-VB */ |
| 702 | snd_hda_codec_read(codec, 0x20, 0, |
| 703 | AC_VERB_SET_PROC_COEF, 0x3030); |
| 704 | } |
| 705 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 706 | /* additional initialization for ALC889 variants */ |
Jaroslav Kysela | 87a8c37 | 2009-07-23 10:58:29 +0200 | [diff] [blame] | 707 | static void alc889_coef_init(struct hda_codec *codec) |
| 708 | { |
| 709 | unsigned int tmp; |
| 710 | |
| 711 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 712 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 713 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 714 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010); |
| 715 | } |
| 716 | |
Takashi Iwai | 3fb4a50 | 2010-01-19 15:46:37 +0100 | [diff] [blame] | 717 | /* turn on/off EAPD control (only if available) */ |
| 718 | static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on) |
| 719 | { |
| 720 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) |
| 721 | return; |
| 722 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) |
| 723 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE, |
| 724 | on ? 2 : 0); |
| 725 | } |
| 726 | |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 727 | /* turn on/off EAPD controls of the codec */ |
| 728 | static void alc_auto_setup_eapd(struct hda_codec *codec, bool on) |
| 729 | { |
| 730 | /* We currently only handle front, HP */ |
Takashi Iwai | 39fa84e | 2011-06-27 15:28:57 +0200 | [diff] [blame] | 731 | static hda_nid_t pins[] = { |
| 732 | 0x0f, 0x10, 0x14, 0x15, 0 |
| 733 | }; |
| 734 | hda_nid_t *p; |
| 735 | for (p = pins; *p; p++) |
| 736 | set_eapd(codec, *p, on); |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 737 | } |
| 738 | |
Takashi Iwai | 1c71615 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 739 | /* generic shutup callback; |
| 740 | * just turning off EPAD and a little pause for avoiding pop-noise |
| 741 | */ |
| 742 | static void alc_eapd_shutup(struct hda_codec *codec) |
| 743 | { |
| 744 | alc_auto_setup_eapd(codec, false); |
| 745 | msleep(200); |
| 746 | } |
| 747 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 748 | /* generic EAPD initialization */ |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 749 | static void alc_auto_init_amp(struct hda_codec *codec, int type) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 750 | { |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 751 | unsigned int tmp; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 752 | |
Takashi Iwai | 39fa84e | 2011-06-27 15:28:57 +0200 | [diff] [blame] | 753 | alc_auto_setup_eapd(codec, true); |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 754 | switch (type) { |
| 755 | case ALC_INIT_GPIO1: |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 756 | snd_hda_sequence_write(codec, alc_gpio1_init_verbs); |
| 757 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 758 | case ALC_INIT_GPIO2: |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 759 | snd_hda_sequence_write(codec, alc_gpio2_init_verbs); |
| 760 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 761 | case ALC_INIT_GPIO3: |
Kailang Yang | bdd148a | 2007-05-08 15:19:08 +0200 | [diff] [blame] | 762 | snd_hda_sequence_write(codec, alc_gpio3_init_verbs); |
| 763 | break; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 764 | case ALC_INIT_DEFAULT: |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 765 | switch (codec->vendor_id) { |
| 766 | case 0x10ec0260: |
| 767 | snd_hda_codec_write(codec, 0x1a, 0, |
| 768 | AC_VERB_SET_COEF_INDEX, 7); |
| 769 | tmp = snd_hda_codec_read(codec, 0x1a, 0, |
| 770 | AC_VERB_GET_PROC_COEF, 0); |
| 771 | snd_hda_codec_write(codec, 0x1a, 0, |
| 772 | AC_VERB_SET_COEF_INDEX, 7); |
| 773 | snd_hda_codec_write(codec, 0x1a, 0, |
| 774 | AC_VERB_SET_PROC_COEF, |
| 775 | tmp | 0x2010); |
| 776 | break; |
| 777 | case 0x10ec0262: |
| 778 | case 0x10ec0880: |
| 779 | case 0x10ec0882: |
| 780 | case 0x10ec0883: |
| 781 | case 0x10ec0885: |
Takashi Iwai | 4a5a4c5 | 2009-02-06 12:46:59 +0100 | [diff] [blame] | 782 | case 0x10ec0887: |
Takashi Iwai | 20b67dd | 2011-03-23 22:54:32 +0100 | [diff] [blame] | 783 | /*case 0x10ec0889:*/ /* this causes an SPDIF problem */ |
Jaroslav Kysela | 87a8c37 | 2009-07-23 10:58:29 +0200 | [diff] [blame] | 784 | alc889_coef_init(codec); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 785 | break; |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 786 | case 0x10ec0888: |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 787 | alc888_coef_init(codec); |
Kailang Yang | f9423e7 | 2008-05-27 12:32:25 +0200 | [diff] [blame] | 788 | break; |
Takashi Iwai | 0aea778 | 2010-01-25 15:44:11 +0100 | [diff] [blame] | 789 | #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] | 790 | case 0x10ec0267: |
| 791 | case 0x10ec0268: |
| 792 | snd_hda_codec_write(codec, 0x20, 0, |
| 793 | AC_VERB_SET_COEF_INDEX, 7); |
| 794 | tmp = snd_hda_codec_read(codec, 0x20, 0, |
| 795 | AC_VERB_GET_PROC_COEF, 0); |
| 796 | snd_hda_codec_write(codec, 0x20, 0, |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 797 | AC_VERB_SET_COEF_INDEX, 7); |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 798 | snd_hda_codec_write(codec, 0x20, 0, |
| 799 | AC_VERB_SET_PROC_COEF, |
| 800 | tmp | 0x3000); |
| 801 | break; |
Takashi Iwai | 0aea778 | 2010-01-25 15:44:11 +0100 | [diff] [blame] | 802 | #endif /* XXX */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 803 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 804 | break; |
| 805 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 806 | } |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 807 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 808 | /* |
| 809 | * Auto-Mute mode mixer enum support |
| 810 | */ |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 811 | static int alc_automute_mode_info(struct snd_kcontrol *kcontrol, |
| 812 | struct snd_ctl_elem_info *uinfo) |
| 813 | { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 814 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 815 | struct alc_spec *spec = codec->spec; |
| 816 | static const char * const texts2[] = { |
| 817 | "Disabled", "Enabled" |
| 818 | }; |
| 819 | static const char * const texts3[] = { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 820 | "Disabled", "Speaker Only", "Line-Out+Speaker" |
| 821 | }; |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 822 | const char * const *texts; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 823 | |
| 824 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 825 | uinfo->count = 1; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 826 | if (spec->automute_speaker_possible && spec->automute_lo_possible) { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 827 | uinfo->value.enumerated.items = 3; |
| 828 | texts = texts3; |
| 829 | } else { |
| 830 | uinfo->value.enumerated.items = 2; |
| 831 | texts = texts2; |
| 832 | } |
| 833 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 834 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 835 | strcpy(uinfo->value.enumerated.name, |
| 836 | texts[uinfo->value.enumerated.item]); |
| 837 | return 0; |
| 838 | } |
| 839 | |
| 840 | static int alc_automute_mode_get(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; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 845 | unsigned int val = 0; |
| 846 | if (spec->automute_speaker) |
| 847 | val++; |
| 848 | if (spec->automute_lo) |
| 849 | val++; |
| 850 | |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 851 | ucontrol->value.enumerated.item[0] = val; |
| 852 | return 0; |
| 853 | } |
| 854 | |
| 855 | static int alc_automute_mode_put(struct snd_kcontrol *kcontrol, |
| 856 | struct snd_ctl_elem_value *ucontrol) |
| 857 | { |
| 858 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 859 | struct alc_spec *spec = codec->spec; |
| 860 | |
| 861 | switch (ucontrol->value.enumerated.item[0]) { |
| 862 | case 0: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 863 | if (!spec->automute_speaker && !spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 864 | return 0; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 865 | spec->automute_speaker = 0; |
| 866 | spec->automute_lo = 0; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 867 | break; |
| 868 | case 1: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 869 | if (spec->automute_speaker_possible) { |
| 870 | if (!spec->automute_lo && spec->automute_speaker) |
| 871 | return 0; |
| 872 | spec->automute_speaker = 1; |
| 873 | spec->automute_lo = 0; |
| 874 | } else if (spec->automute_lo_possible) { |
| 875 | if (spec->automute_lo) |
| 876 | return 0; |
| 877 | spec->automute_lo = 1; |
| 878 | } else |
| 879 | return -EINVAL; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 880 | break; |
| 881 | case 2: |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 882 | if (!spec->automute_lo_possible || !spec->automute_speaker_possible) |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 883 | return -EINVAL; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 884 | if (spec->automute_speaker && spec->automute_lo) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 885 | return 0; |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 886 | spec->automute_speaker = 1; |
| 887 | spec->automute_lo = 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 888 | break; |
| 889 | default: |
| 890 | return -EINVAL; |
| 891 | } |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 892 | call_update_outputs(codec); |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 893 | return 1; |
| 894 | } |
| 895 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 896 | static const struct snd_kcontrol_new alc_automute_mode_enum = { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 897 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 898 | .name = "Auto-Mute Mode", |
| 899 | .info = alc_automute_mode_info, |
| 900 | .get = alc_automute_mode_get, |
| 901 | .put = alc_automute_mode_put, |
| 902 | }; |
| 903 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 904 | static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec) |
| 905 | { |
| 906 | snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32); |
| 907 | return snd_array_new(&spec->kctls); |
| 908 | } |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 909 | |
| 910 | static int alc_add_automute_mode_enum(struct hda_codec *codec) |
| 911 | { |
| 912 | struct alc_spec *spec = codec->spec; |
| 913 | struct snd_kcontrol_new *knew; |
| 914 | |
| 915 | knew = alc_kcontrol_new(spec); |
| 916 | if (!knew) |
| 917 | return -ENOMEM; |
| 918 | *knew = alc_automute_mode_enum; |
| 919 | knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL); |
| 920 | if (!knew->name) |
| 921 | return -ENOMEM; |
| 922 | return 0; |
| 923 | } |
| 924 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 925 | /* |
| 926 | * Check the availability of HP/line-out auto-mute; |
| 927 | * Set up appropriately if really supported |
| 928 | */ |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 929 | static void alc_init_automute(struct hda_codec *codec) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 930 | { |
| 931 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 932 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 1daf5f4 | 2011-04-28 17:57:46 +0200 | [diff] [blame] | 933 | int present = 0; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 934 | int i; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 935 | |
Takashi Iwai | 1daf5f4 | 2011-04-28 17:57:46 +0200 | [diff] [blame] | 936 | if (cfg->hp_pins[0]) |
| 937 | present++; |
| 938 | if (cfg->line_out_pins[0]) |
| 939 | present++; |
| 940 | if (cfg->speaker_pins[0]) |
| 941 | present++; |
| 942 | if (present < 2) /* need two different output types */ |
| 943 | return; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 944 | |
Takashi Iwai | c48a8fb | 2011-07-27 16:41:57 +0200 | [diff] [blame] | 945 | if (!cfg->speaker_pins[0] && |
| 946 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 947 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 948 | sizeof(cfg->speaker_pins)); |
| 949 | cfg->speaker_outs = cfg->line_outs; |
| 950 | } |
| 951 | |
Takashi Iwai | c48a8fb | 2011-07-27 16:41:57 +0200 | [diff] [blame] | 952 | if (!cfg->hp_pins[0] && |
| 953 | cfg->line_out_type == AUTO_PIN_HP_OUT) { |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 954 | memcpy(cfg->hp_pins, cfg->line_out_pins, |
| 955 | sizeof(cfg->hp_pins)); |
| 956 | cfg->hp_outs = cfg->line_outs; |
| 957 | } |
| 958 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 959 | spec->automute_mode = ALC_AUTOMUTE_PIN; |
| 960 | |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 961 | for (i = 0; i < cfg->hp_outs; i++) { |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 962 | hda_nid_t nid = cfg->hp_pins[i]; |
Takashi Iwai | 06dec22 | 2011-05-17 10:00:16 +0200 | [diff] [blame] | 963 | if (!is_jack_detectable(codec, nid)) |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 964 | continue; |
Takashi Iwai | bb35feb | 2010-09-08 15:30:49 +0200 | [diff] [blame] | 965 | snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n", |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 966 | nid); |
| 967 | snd_hda_codec_write_cache(codec, nid, 0, |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 968 | AC_VERB_SET_UNSOLICITED_ENABLE, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 969 | AC_USRSP_EN | ALC_HP_EVENT); |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 970 | spec->detect_hp = 1; |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 971 | } |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 972 | |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 973 | if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) { |
| 974 | if (cfg->speaker_outs) |
| 975 | for (i = 0; i < cfg->line_outs; i++) { |
| 976 | hda_nid_t nid = cfg->line_out_pins[i]; |
| 977 | if (!is_jack_detectable(codec, nid)) |
| 978 | continue; |
| 979 | snd_printdd("realtek: Enable Line-Out " |
| 980 | "auto-muting on NID 0x%x\n", nid); |
| 981 | snd_hda_codec_write_cache(codec, nid, 0, |
| 982 | AC_VERB_SET_UNSOLICITED_ENABLE, |
| 983 | AC_USRSP_EN | ALC_FRONT_EVENT); |
| 984 | spec->detect_lo = 1; |
| 985 | } |
| 986 | spec->automute_lo_possible = spec->detect_hp; |
| 987 | } |
| 988 | |
| 989 | spec->automute_speaker_possible = cfg->speaker_outs && |
| 990 | (spec->detect_hp || spec->detect_lo); |
| 991 | |
| 992 | spec->automute_lo = spec->automute_lo_possible; |
| 993 | spec->automute_speaker = spec->automute_speaker_possible; |
| 994 | |
| 995 | if (spec->automute_speaker_possible || spec->automute_lo_possible) { |
Takashi Iwai | ae8a60a | 2011-04-28 18:09:52 +0200 | [diff] [blame] | 996 | /* create a control for automute mode */ |
| 997 | alc_add_automute_mode_enum(codec); |
| 998 | spec->unsol_event = alc_sku_unsol_event; |
| 999 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1000 | } |
| 1001 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1002 | /* return the position of NID in the list, or -1 if not found */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1003 | static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 1004 | { |
| 1005 | int i; |
| 1006 | for (i = 0; i < nums; i++) |
| 1007 | if (list[i] == nid) |
| 1008 | return i; |
| 1009 | return -1; |
| 1010 | } |
| 1011 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1012 | /* check whether dynamic ADC-switching is available */ |
| 1013 | static bool alc_check_dyn_adc_switch(struct hda_codec *codec) |
| 1014 | { |
| 1015 | struct alc_spec *spec = codec->spec; |
| 1016 | struct hda_input_mux *imux = &spec->private_imux[0]; |
| 1017 | int i, n, idx; |
| 1018 | hda_nid_t cap, pin; |
| 1019 | |
| 1020 | if (imux != spec->input_mux) /* no dynamic imux? */ |
| 1021 | return false; |
| 1022 | |
| 1023 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 1024 | cap = spec->private_capsrc_nids[n]; |
| 1025 | for (i = 0; i < imux->num_items; i++) { |
| 1026 | pin = spec->imux_pins[i]; |
| 1027 | if (!pin) |
| 1028 | return false; |
| 1029 | if (get_connection_index(codec, cap, pin) < 0) |
| 1030 | break; |
| 1031 | } |
| 1032 | if (i >= imux->num_items) |
Takashi Iwai | 268ff6f | 2011-07-08 14:37:35 +0200 | [diff] [blame] | 1033 | return true; /* no ADC-switch is needed */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | for (i = 0; i < imux->num_items; i++) { |
| 1037 | pin = spec->imux_pins[i]; |
| 1038 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 1039 | cap = spec->private_capsrc_nids[n]; |
| 1040 | idx = get_connection_index(codec, cap, pin); |
| 1041 | if (idx >= 0) { |
| 1042 | imux->items[i].index = idx; |
| 1043 | spec->dyn_adc_idx[i] = n; |
| 1044 | break; |
| 1045 | } |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | snd_printdd("realtek: enabling ADC switching\n"); |
| 1050 | spec->dyn_adc_switch = 1; |
| 1051 | return true; |
| 1052 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1053 | |
| 1054 | /* rebuild imux for matching with the given auto-mic pins (if not yet) */ |
| 1055 | static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec) |
| 1056 | { |
| 1057 | struct alc_spec *spec = codec->spec; |
| 1058 | struct hda_input_mux *imux; |
| 1059 | static char * const texts[3] = { |
| 1060 | "Mic", "Internal Mic", "Dock Mic" |
| 1061 | }; |
| 1062 | int i; |
| 1063 | |
| 1064 | if (!spec->auto_mic) |
| 1065 | return false; |
| 1066 | imux = &spec->private_imux[0]; |
| 1067 | if (spec->input_mux == imux) |
| 1068 | return true; |
| 1069 | spec->imux_pins[0] = spec->ext_mic_pin; |
| 1070 | spec->imux_pins[1] = spec->int_mic_pin; |
| 1071 | spec->imux_pins[2] = spec->dock_mic_pin; |
| 1072 | for (i = 0; i < 3; i++) { |
| 1073 | strcpy(imux->items[i].label, texts[i]); |
| 1074 | if (spec->imux_pins[i]) |
| 1075 | imux->num_items = i + 1; |
| 1076 | } |
| 1077 | spec->num_mux_defs = 1; |
| 1078 | spec->input_mux = imux; |
| 1079 | return true; |
| 1080 | } |
| 1081 | |
| 1082 | /* check whether all auto-mic pins are valid; setup indices if OK */ |
| 1083 | static bool alc_auto_mic_check_imux(struct hda_codec *codec) |
| 1084 | { |
| 1085 | struct alc_spec *spec = codec->spec; |
| 1086 | const struct hda_input_mux *imux; |
| 1087 | |
| 1088 | if (!spec->auto_mic) |
| 1089 | return false; |
| 1090 | if (spec->auto_mic_valid_imux) |
| 1091 | return true; /* already checked */ |
| 1092 | |
| 1093 | /* fill up imux indices */ |
| 1094 | if (!alc_check_dyn_adc_switch(codec)) { |
| 1095 | spec->auto_mic = 0; |
| 1096 | return false; |
| 1097 | } |
| 1098 | |
| 1099 | imux = spec->input_mux; |
| 1100 | spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin, |
| 1101 | spec->imux_pins, imux->num_items); |
| 1102 | spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin, |
| 1103 | spec->imux_pins, imux->num_items); |
| 1104 | spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin, |
| 1105 | spec->imux_pins, imux->num_items); |
| 1106 | if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) { |
| 1107 | spec->auto_mic = 0; |
| 1108 | return false; /* no corresponding imux */ |
| 1109 | } |
| 1110 | |
| 1111 | snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0, |
| 1112 | AC_VERB_SET_UNSOLICITED_ENABLE, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1113 | AC_USRSP_EN | ALC_MIC_EVENT); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1114 | if (spec->dock_mic_pin) |
| 1115 | snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0, |
| 1116 | AC_VERB_SET_UNSOLICITED_ENABLE, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1117 | AC_USRSP_EN | ALC_MIC_EVENT); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1118 | |
| 1119 | spec->auto_mic_valid_imux = 1; |
| 1120 | spec->auto_mic = 1; |
| 1121 | return true; |
| 1122 | } |
| 1123 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1124 | /* |
| 1125 | * Check the availability of auto-mic switch; |
| 1126 | * Set up if really supported |
| 1127 | */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1128 | static void alc_init_auto_mic(struct hda_codec *codec) |
| 1129 | { |
| 1130 | struct alc_spec *spec = codec->spec; |
| 1131 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1132 | hda_nid_t fixed, ext, dock; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1133 | int i; |
| 1134 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 1135 | if (spec->shared_mic_hp) |
| 1136 | return; /* no auto-mic for the shared I/O */ |
| 1137 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1138 | spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1; |
| 1139 | |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1140 | fixed = ext = dock = 0; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 1141 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1142 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1143 | unsigned int defcfg; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1144 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1145 | switch (snd_hda_get_input_pin_attr(defcfg)) { |
| 1146 | case INPUT_PIN_ATTR_INT: |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1147 | if (fixed) |
| 1148 | return; /* already occupied */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1149 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 1150 | return; /* invalid type */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1151 | fixed = nid; |
| 1152 | break; |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1153 | case INPUT_PIN_ATTR_UNUSED: |
| 1154 | return; /* invalid entry */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1155 | case INPUT_PIN_ATTR_DOCK: |
| 1156 | if (dock) |
| 1157 | return; /* already occupied */ |
| 1158 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) |
| 1159 | return; /* invalid type */ |
| 1160 | dock = nid; |
| 1161 | break; |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 1162 | default: |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1163 | if (ext) |
| 1164 | return; /* already occupied */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1165 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 1166 | return; /* invalid type */ |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1167 | ext = nid; |
| 1168 | break; |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1169 | } |
| 1170 | } |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1171 | if (!ext && dock) { |
| 1172 | ext = dock; |
| 1173 | dock = 0; |
| 1174 | } |
Takashi Iwai | eaa9b3a | 2010-01-17 13:09:33 +0100 | [diff] [blame] | 1175 | if (!ext || !fixed) |
| 1176 | return; |
Takashi Iwai | e35d9d6 | 2011-05-17 11:28:16 +0200 | [diff] [blame] | 1177 | if (!is_jack_detectable(codec, ext)) |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1178 | return; /* no unsol support */ |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1179 | if (dock && !is_jack_detectable(codec, dock)) |
| 1180 | return; /* no unsol support */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1181 | |
| 1182 | /* check imux indices */ |
| 1183 | spec->ext_mic_pin = ext; |
| 1184 | spec->int_mic_pin = fixed; |
| 1185 | spec->dock_mic_pin = dock; |
| 1186 | |
| 1187 | spec->auto_mic = 1; |
| 1188 | if (!alc_auto_mic_check_imux(codec)) |
| 1189 | return; |
| 1190 | |
Takashi Iwai | 8ed99d9 | 2011-05-17 12:05:02 +0200 | [diff] [blame] | 1191 | snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n", |
| 1192 | ext, fixed, dock); |
Takashi Iwai | 6c81949 | 2009-08-10 18:47:44 +0200 | [diff] [blame] | 1193 | spec->unsol_event = alc_sku_unsol_event; |
| 1194 | } |
| 1195 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1196 | /* check the availabilities of auto-mute and auto-mic switches */ |
| 1197 | static void alc_auto_check_switches(struct hda_codec *codec) |
| 1198 | { |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 1199 | alc_init_automute(codec); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1200 | alc_init_auto_mic(codec); |
| 1201 | } |
| 1202 | |
| 1203 | /* |
| 1204 | * Realtek SSID verification |
| 1205 | */ |
| 1206 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1207 | /* Could be any non-zero and even value. When used as fixup, tells |
| 1208 | * the driver to ignore any present sku defines. |
| 1209 | */ |
| 1210 | #define ALC_FIXUP_SKU_IGNORE (2) |
| 1211 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1212 | static int alc_auto_parse_customize_define(struct hda_codec *codec) |
| 1213 | { |
| 1214 | unsigned int ass, tmp, i; |
Takashi Iwai | 7fb5622 | 2010-03-22 17:09:47 +0100 | [diff] [blame] | 1215 | unsigned nid = 0; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1216 | struct alc_spec *spec = codec->spec; |
| 1217 | |
Takashi Iwai | b6cbe51 | 2010-07-28 17:43:36 +0200 | [diff] [blame] | 1218 | spec->cdefine.enable_pcbeep = 1; /* assume always enabled */ |
| 1219 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1220 | if (spec->cdefine.fixup) { |
| 1221 | ass = spec->cdefine.sku_cfg; |
| 1222 | if (ass == ALC_FIXUP_SKU_IGNORE) |
| 1223 | return -1; |
| 1224 | goto do_sku; |
| 1225 | } |
| 1226 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1227 | ass = codec->subsystem_id & 0xffff; |
Takashi Iwai | b6cbe51 | 2010-07-28 17:43:36 +0200 | [diff] [blame] | 1228 | if (ass != codec->bus->pci->subsystem_device && (ass & 1)) |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 1229 | goto do_sku; |
| 1230 | |
| 1231 | nid = 0x1d; |
| 1232 | if (codec->vendor_id == 0x10ec0260) |
| 1233 | nid = 0x17; |
| 1234 | ass = snd_hda_codec_get_pincfg(codec, nid); |
| 1235 | |
| 1236 | if (!(ass & 1)) { |
| 1237 | printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n", |
| 1238 | codec->chip_name, ass); |
| 1239 | return -1; |
| 1240 | } |
| 1241 | |
| 1242 | /* check sum */ |
| 1243 | tmp = 0; |
| 1244 | for (i = 1; i < 16; i++) { |
| 1245 | if ((ass >> i) & 1) |
| 1246 | tmp++; |
| 1247 | } |
| 1248 | if (((ass >> 16) & 0xf) != tmp) |
| 1249 | return -1; |
| 1250 | |
| 1251 | spec->cdefine.port_connectivity = ass >> 30; |
| 1252 | spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20; |
| 1253 | spec->cdefine.check_sum = (ass >> 16) & 0xf; |
| 1254 | spec->cdefine.customization = ass >> 8; |
| 1255 | do_sku: |
| 1256 | spec->cdefine.sku_cfg = ass; |
| 1257 | spec->cdefine.external_amp = (ass & 0x38) >> 3; |
| 1258 | spec->cdefine.platform_type = (ass & 0x4) >> 2; |
| 1259 | spec->cdefine.swap = (ass & 0x2) >> 1; |
| 1260 | spec->cdefine.override = ass & 0x1; |
| 1261 | |
| 1262 | snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n", |
| 1263 | nid, spec->cdefine.sku_cfg); |
| 1264 | snd_printd("SKU: port_connectivity=0x%x\n", |
| 1265 | spec->cdefine.port_connectivity); |
| 1266 | snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep); |
| 1267 | snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum); |
| 1268 | snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization); |
| 1269 | snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp); |
| 1270 | snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type); |
| 1271 | snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap); |
| 1272 | snd_printd("SKU: override=0x%x\n", spec->cdefine.override); |
| 1273 | |
| 1274 | return 0; |
| 1275 | } |
| 1276 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1277 | /* return true if the given NID is found in the list */ |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1278 | static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 1279 | { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1280 | return find_idx_in_nid_list(nid, list, nums) >= 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1281 | } |
| 1282 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1283 | /* check subsystem ID and set up device-specific initialization; |
| 1284 | * return 1 if initialized, 0 if invalid SSID |
| 1285 | */ |
| 1286 | /* 32-bit subsystem ID for BIOS loading in HD Audio codec. |
| 1287 | * 31 ~ 16 : Manufacture ID |
| 1288 | * 15 ~ 8 : SKU ID |
| 1289 | * 7 ~ 0 : Assembly ID |
| 1290 | * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36 |
| 1291 | */ |
| 1292 | static int alc_subsystem_id(struct hda_codec *codec, |
| 1293 | hda_nid_t porta, hda_nid_t porte, |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1294 | hda_nid_t portd, hda_nid_t porti) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1295 | { |
| 1296 | unsigned int ass, tmp, i; |
| 1297 | unsigned nid; |
| 1298 | struct alc_spec *spec = codec->spec; |
| 1299 | |
David Henningsson | 9062291 | 2010-10-14 14:50:18 +0200 | [diff] [blame] | 1300 | if (spec->cdefine.fixup) { |
| 1301 | ass = spec->cdefine.sku_cfg; |
| 1302 | if (ass == ALC_FIXUP_SKU_IGNORE) |
| 1303 | return 0; |
| 1304 | goto do_sku; |
| 1305 | } |
| 1306 | |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1307 | ass = codec->subsystem_id & 0xffff; |
| 1308 | if ((ass != codec->bus->pci->subsystem_device) && (ass & 1)) |
| 1309 | goto do_sku; |
| 1310 | |
| 1311 | /* invalid SSID, check the special NID pin defcfg instead */ |
| 1312 | /* |
Sasha Alexandr | def319f | 2009-06-16 16:00:15 -0400 | [diff] [blame] | 1313 | * 31~30 : port connectivity |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1314 | * 29~21 : reserve |
| 1315 | * 20 : PCBEEP input |
| 1316 | * 19~16 : Check sum (15:1) |
| 1317 | * 15~1 : Custom |
| 1318 | * 0 : override |
| 1319 | */ |
| 1320 | nid = 0x1d; |
| 1321 | if (codec->vendor_id == 0x10ec0260) |
| 1322 | nid = 0x17; |
| 1323 | ass = snd_hda_codec_get_pincfg(codec, nid); |
| 1324 | snd_printd("realtek: No valid SSID, " |
| 1325 | "checking pincfg 0x%08x for NID 0x%x\n", |
Takashi Iwai | cb6605c | 2009-04-28 13:03:19 +0200 | [diff] [blame] | 1326 | ass, nid); |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1327 | if (!(ass & 1)) |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1328 | return 0; |
| 1329 | if ((ass >> 30) != 1) /* no physical connection */ |
| 1330 | return 0; |
| 1331 | |
| 1332 | /* check sum */ |
| 1333 | tmp = 0; |
| 1334 | for (i = 1; i < 16; i++) { |
| 1335 | if ((ass >> i) & 1) |
| 1336 | tmp++; |
| 1337 | } |
| 1338 | if (((ass >> 16) & 0xf) != tmp) |
| 1339 | return 0; |
| 1340 | do_sku: |
| 1341 | snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n", |
| 1342 | ass & 0xffff, codec->vendor_id); |
| 1343 | /* |
| 1344 | * 0 : override |
| 1345 | * 1 : Swap Jack |
| 1346 | * 2 : 0 --> Desktop, 1 --> Laptop |
| 1347 | * 3~5 : External Amplifier control |
| 1348 | * 7~6 : Reserved |
| 1349 | */ |
| 1350 | tmp = (ass & 0x38) >> 3; /* external Amp control */ |
| 1351 | switch (tmp) { |
| 1352 | case 1: |
| 1353 | spec->init_amp = ALC_INIT_GPIO1; |
| 1354 | break; |
| 1355 | case 3: |
| 1356 | spec->init_amp = ALC_INIT_GPIO2; |
| 1357 | break; |
| 1358 | case 7: |
| 1359 | spec->init_amp = ALC_INIT_GPIO3; |
| 1360 | break; |
| 1361 | case 5: |
Takashi Iwai | 5a8cfb4 | 2010-11-26 17:11:18 +0100 | [diff] [blame] | 1362 | default: |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1363 | spec->init_amp = ALC_INIT_DEFAULT; |
| 1364 | break; |
| 1365 | } |
| 1366 | |
| 1367 | /* is laptop or Desktop and enable the function "Mute internal speaker |
| 1368 | * when the external headphone out jack is plugged" |
| 1369 | */ |
| 1370 | if (!(ass & 0x8000)) |
| 1371 | return 1; |
| 1372 | /* |
| 1373 | * 10~8 : Jack location |
| 1374 | * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered |
| 1375 | * 14~13: Resvered |
| 1376 | * 15 : 1 --> enable the function "Mute internal speaker |
| 1377 | * when the external headphone out jack is plugged" |
| 1378 | */ |
Takashi Iwai | 5fe6e01 | 2011-09-26 10:41:21 +0200 | [diff] [blame] | 1379 | if (!spec->autocfg.hp_pins[0] && |
| 1380 | !(spec->autocfg.line_out_pins[0] && |
| 1381 | spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) { |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1382 | hda_nid_t nid; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1383 | tmp = (ass >> 11) & 0x3; /* HP to chassis */ |
| 1384 | if (tmp == 0) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1385 | nid = porta; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1386 | else if (tmp == 1) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1387 | nid = porte; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1388 | else if (tmp == 2) |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1389 | nid = portd; |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 1390 | else if (tmp == 3) |
| 1391 | nid = porti; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1392 | else |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1393 | return 1; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 1394 | if (found_in_nid_list(nid, spec->autocfg.line_out_pins, |
| 1395 | spec->autocfg.line_outs)) |
| 1396 | return 1; |
Takashi Iwai | 01d4825 | 2009-10-06 13:21:54 +0200 | [diff] [blame] | 1397 | spec->autocfg.hp_pins[0] = nid; |
Kailang Yang | c9b5800 | 2007-10-16 14:30:01 +0200 | [diff] [blame] | 1398 | } |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1399 | return 1; |
| 1400 | } |
Kailang Yang | ea1fb29 | 2008-08-26 12:58:38 +0200 | [diff] [blame] | 1401 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 1402 | /* Check the validity of ALC subsystem-id |
| 1403 | * ports contains an array of 4 pin NIDs for port-A, E, D and I */ |
| 1404 | 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] | 1405 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 1406 | 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] | 1407 | struct alc_spec *spec = codec->spec; |
| 1408 | snd_printd("realtek: " |
| 1409 | "Enable default setup for auto mode as fallback\n"); |
| 1410 | spec->init_amp = ALC_INIT_DEFAULT; |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 1411 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1412 | } |
Takashi Iwai | 1a1455d | 2011-04-28 17:36:18 +0200 | [diff] [blame] | 1413 | |
Takashi Iwai | 41e41f1 | 2005-06-08 14:48:49 +0200 | [diff] [blame] | 1414 | /* |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1415 | * Fix-up pin default configurations and add default verbs |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1416 | */ |
| 1417 | |
| 1418 | struct alc_pincfg { |
| 1419 | hda_nid_t nid; |
| 1420 | u32 val; |
| 1421 | }; |
| 1422 | |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1423 | struct alc_model_fixup { |
| 1424 | const int id; |
| 1425 | const char *name; |
| 1426 | }; |
| 1427 | |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1428 | struct alc_fixup { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1429 | int type; |
Takashi Iwai | 361fe6e | 2011-01-14 09:55:32 +0100 | [diff] [blame] | 1430 | bool chained; |
| 1431 | int chain_id; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1432 | union { |
| 1433 | unsigned int sku; |
| 1434 | const struct alc_pincfg *pins; |
| 1435 | const struct hda_verb *verbs; |
| 1436 | void (*func)(struct hda_codec *codec, |
| 1437 | const struct alc_fixup *fix, |
| 1438 | int action); |
| 1439 | } v; |
Takashi Iwai | f8f25ba | 2009-10-06 08:31:29 +0200 | [diff] [blame] | 1440 | }; |
| 1441 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1442 | enum { |
| 1443 | ALC_FIXUP_INVALID, |
| 1444 | ALC_FIXUP_SKU, |
| 1445 | ALC_FIXUP_PINS, |
| 1446 | ALC_FIXUP_VERBS, |
| 1447 | ALC_FIXUP_FUNC, |
| 1448 | }; |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1449 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1450 | enum { |
| 1451 | ALC_FIXUP_ACT_PRE_PROBE, |
| 1452 | ALC_FIXUP_ACT_PROBE, |
Takashi Iwai | 5870112 | 2011-01-13 15:41:45 +0100 | [diff] [blame] | 1453 | ALC_FIXUP_ACT_INIT, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1454 | }; |
| 1455 | |
| 1456 | static void alc_apply_fixup(struct hda_codec *codec, int action) |
| 1457 | { |
| 1458 | struct alc_spec *spec = codec->spec; |
| 1459 | int id = spec->fixup_id; |
Takashi Iwai | aa1d0c5 | 2011-01-19 17:27:58 +0100 | [diff] [blame] | 1460 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1461 | const char *modelname = spec->fixup_name; |
Takashi Iwai | aa1d0c5 | 2011-01-19 17:27:58 +0100 | [diff] [blame] | 1462 | #endif |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1463 | int depth = 0; |
| 1464 | |
| 1465 | if (!spec->fixup_list) |
| 1466 | return; |
| 1467 | |
| 1468 | while (id >= 0) { |
| 1469 | const struct alc_fixup *fix = spec->fixup_list + id; |
| 1470 | const struct alc_pincfg *cfg; |
| 1471 | |
| 1472 | switch (fix->type) { |
| 1473 | case ALC_FIXUP_SKU: |
| 1474 | if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku) |
| 1475 | break;; |
| 1476 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1477 | "Apply sku override for %s\n", |
| 1478 | codec->chip_name, modelname); |
| 1479 | spec->cdefine.sku_cfg = fix->v.sku; |
| 1480 | spec->cdefine.fixup = 1; |
| 1481 | break; |
| 1482 | case ALC_FIXUP_PINS: |
| 1483 | cfg = fix->v.pins; |
| 1484 | if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg) |
| 1485 | break; |
| 1486 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1487 | "Apply pincfg for %s\n", |
| 1488 | codec->chip_name, modelname); |
| 1489 | for (; cfg->nid; cfg++) |
| 1490 | snd_hda_codec_set_pincfg(codec, cfg->nid, |
| 1491 | cfg->val); |
| 1492 | break; |
| 1493 | case ALC_FIXUP_VERBS: |
| 1494 | if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs) |
| 1495 | break; |
| 1496 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1497 | "Apply fix-verbs for %s\n", |
| 1498 | codec->chip_name, modelname); |
| 1499 | add_verb(codec->spec, fix->v.verbs); |
| 1500 | break; |
| 1501 | case ALC_FIXUP_FUNC: |
| 1502 | if (!fix->v.func) |
| 1503 | break; |
| 1504 | snd_printdd(KERN_INFO "hda_codec: %s: " |
| 1505 | "Apply fix-func for %s\n", |
| 1506 | codec->chip_name, modelname); |
| 1507 | fix->v.func(codec, fix, action); |
| 1508 | break; |
| 1509 | default: |
| 1510 | snd_printk(KERN_ERR "hda_codec: %s: " |
| 1511 | "Invalid fixup type %d\n", |
| 1512 | codec->chip_name, fix->type); |
| 1513 | break; |
| 1514 | } |
Takashi Iwai | 24af2b1 | 2011-05-02 13:55:36 +0200 | [diff] [blame] | 1515 | if (!fix->chained) |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1516 | break; |
| 1517 | if (++depth > 10) |
| 1518 | break; |
Takashi Iwai | 24af2b1 | 2011-05-02 13:55:36 +0200 | [diff] [blame] | 1519 | id = fix->chain_id; |
Takashi Iwai | 9d57883 | 2010-11-22 13:29:19 +0100 | [diff] [blame] | 1520 | } |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1521 | } |
| 1522 | |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1523 | static void alc_pick_fixup(struct hda_codec *codec, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1524 | const struct alc_model_fixup *models, |
| 1525 | const struct snd_pci_quirk *quirk, |
| 1526 | const struct alc_fixup *fixlist) |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1527 | { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1528 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 596830e | 2011-11-09 15:06:45 +0100 | [diff] [blame^] | 1529 | const struct snd_pci_quirk *q; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1530 | int id = -1; |
| 1531 | const char *name = NULL; |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1532 | |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1533 | if (codec->modelname && models) { |
| 1534 | while (models->name) { |
| 1535 | if (!strcmp(codec->modelname, models->name)) { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1536 | id = models->id; |
| 1537 | name = models->name; |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1538 | break; |
| 1539 | } |
| 1540 | models++; |
| 1541 | } |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1542 | } |
| 1543 | if (id < 0) { |
Takashi Iwai | 596830e | 2011-11-09 15:06:45 +0100 | [diff] [blame^] | 1544 | q = snd_pci_quirk_lookup(codec->bus->pci, quirk); |
| 1545 | if (q) { |
| 1546 | id = q->value; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1547 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
Takashi Iwai | 596830e | 2011-11-09 15:06:45 +0100 | [diff] [blame^] | 1548 | name = q->name; |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1549 | #endif |
| 1550 | } |
| 1551 | } |
Takashi Iwai | 596830e | 2011-11-09 15:06:45 +0100 | [diff] [blame^] | 1552 | if (id < 0) { |
| 1553 | for (q = quirk; q->subvendor; q++) { |
| 1554 | unsigned int vendorid = |
| 1555 | q->subdevice | (q->subvendor << 16); |
| 1556 | if (vendorid == codec->subsystem_id) { |
| 1557 | id = q->value; |
| 1558 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
| 1559 | name = q->name; |
| 1560 | #endif |
| 1561 | break; |
| 1562 | } |
| 1563 | } |
| 1564 | } |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 1565 | |
| 1566 | spec->fixup_id = id; |
| 1567 | if (id >= 0) { |
| 1568 | spec->fixup_list = fixlist; |
| 1569 | spec->fixup_name = name; |
Todd Broch | e1eb5f1 | 2010-12-06 11:19:51 -0800 | [diff] [blame] | 1570 | } |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1571 | } |
| 1572 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1573 | /* |
| 1574 | * COEF access helper functions |
| 1575 | */ |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 1576 | static int alc_read_coef_idx(struct hda_codec *codec, |
| 1577 | unsigned int coef_idx) |
| 1578 | { |
| 1579 | unsigned int val; |
| 1580 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, |
| 1581 | coef_idx); |
| 1582 | val = snd_hda_codec_read(codec, 0x20, 0, |
| 1583 | AC_VERB_GET_PROC_COEF, 0); |
| 1584 | return val; |
| 1585 | } |
| 1586 | |
Kailang Yang | 977ddd6 | 2010-09-15 10:02:29 +0200 | [diff] [blame] | 1587 | static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx, |
| 1588 | unsigned int coef_val) |
| 1589 | { |
| 1590 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, |
| 1591 | coef_idx); |
| 1592 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, |
| 1593 | coef_val); |
| 1594 | } |
| 1595 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 1596 | /* a special bypass for COEF 0; read the cached value at the second time */ |
| 1597 | static unsigned int alc_get_coef0(struct hda_codec *codec) |
| 1598 | { |
| 1599 | struct alc_spec *spec = codec->spec; |
| 1600 | if (!spec->coef0) |
| 1601 | spec->coef0 = alc_read_coef_idx(codec, 0); |
| 1602 | return spec->coef0; |
| 1603 | } |
| 1604 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1605 | /* |
| 1606 | * Digital I/O handling |
| 1607 | */ |
| 1608 | |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1609 | /* set right pin controls for digital I/O */ |
| 1610 | static void alc_auto_init_digital(struct hda_codec *codec) |
| 1611 | { |
| 1612 | struct alc_spec *spec = codec->spec; |
| 1613 | int i; |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 1614 | hda_nid_t pin, dac; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1615 | |
| 1616 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
| 1617 | pin = spec->autocfg.dig_out_pins[i]; |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 1618 | if (!pin) |
| 1619 | continue; |
| 1620 | snd_hda_codec_write(codec, pin, 0, |
| 1621 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); |
| 1622 | if (!i) |
| 1623 | dac = spec->multiout.dig_out_nid; |
| 1624 | else |
| 1625 | dac = spec->slave_dig_outs[i - 1]; |
| 1626 | if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP)) |
| 1627 | continue; |
| 1628 | snd_hda_codec_write(codec, dac, 0, |
| 1629 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 1630 | AMP_OUT_UNMUTE); |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1631 | } |
| 1632 | pin = spec->autocfg.dig_in_pin; |
| 1633 | if (pin) |
| 1634 | snd_hda_codec_write(codec, pin, 0, |
| 1635 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1636 | PIN_IN); |
| 1637 | } |
| 1638 | |
| 1639 | /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */ |
| 1640 | static void alc_auto_parse_digital(struct hda_codec *codec) |
| 1641 | { |
| 1642 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1643 | int i, err, nums; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1644 | hda_nid_t dig_nid; |
| 1645 | |
| 1646 | /* support multiple SPDIFs; the secondary is set up as a slave */ |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1647 | nums = 0; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1648 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1649 | hda_nid_t conn[4]; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1650 | err = snd_hda_get_connections(codec, |
| 1651 | spec->autocfg.dig_out_pins[i], |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1652 | conn, ARRAY_SIZE(conn)); |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1653 | if (err <= 0) |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1654 | continue; |
Takashi Iwai | a926757 | 2011-07-07 15:12:55 +0200 | [diff] [blame] | 1655 | dig_nid = conn[0]; /* assume the first element is audio-out */ |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1656 | if (!nums) { |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1657 | spec->multiout.dig_out_nid = dig_nid; |
| 1658 | spec->dig_out_type = spec->autocfg.dig_out_type[0]; |
| 1659 | } else { |
| 1660 | spec->multiout.slave_dig_outs = spec->slave_dig_outs; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1661 | if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1) |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1662 | break; |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1663 | spec->slave_dig_outs[nums - 1] = dig_nid; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1664 | } |
Takashi Iwai | 51e4152 | 2011-11-03 16:54:06 +0100 | [diff] [blame] | 1665 | nums++; |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | if (spec->autocfg.dig_in_pin) { |
Takashi Iwai | 01fdf18 | 2010-09-24 09:09:42 +0200 | [diff] [blame] | 1669 | dig_nid = codec->start_nid; |
| 1670 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { |
| 1671 | unsigned int wcaps = get_wcaps(codec, dig_nid); |
| 1672 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
| 1673 | continue; |
| 1674 | if (!(wcaps & AC_WCAP_DIGITAL)) |
| 1675 | continue; |
| 1676 | if (!(wcaps & AC_WCAP_CONN_LIST)) |
| 1677 | continue; |
| 1678 | err = get_connection_index(codec, dig_nid, |
| 1679 | spec->autocfg.dig_in_pin); |
| 1680 | if (err >= 0) { |
| 1681 | spec->dig_in_nid = dig_nid; |
| 1682 | break; |
| 1683 | } |
| 1684 | } |
Takashi Iwai | 757899a | 2010-07-30 10:48:14 +0200 | [diff] [blame] | 1685 | } |
| 1686 | } |
| 1687 | |
Takashi Iwai | f95474e | 2007-07-10 00:47:43 +0200 | [diff] [blame] | 1688 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 1689 | * capture mixer elements |
Vincent Petry | ef8ef5f | 2008-11-23 11:31:41 +0800 | [diff] [blame] | 1690 | */ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1691 | static int alc_cap_vol_info(struct snd_kcontrol *kcontrol, |
| 1692 | struct snd_ctl_elem_info *uinfo) |
| 1693 | { |
| 1694 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1695 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1696 | unsigned long val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1697 | int err; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1698 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1699 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1700 | if (spec->vol_in_capsrc) |
| 1701 | val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT); |
| 1702 | else |
| 1703 | val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT); |
| 1704 | kcontrol->private_value = val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1705 | err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo); |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1706 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1707 | return err; |
| 1708 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1710 | static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, |
| 1711 | unsigned int size, unsigned int __user *tlv) |
| 1712 | { |
| 1713 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1714 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1715 | unsigned long val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1716 | int err; |
| 1717 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1718 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1719 | if (spec->vol_in_capsrc) |
| 1720 | val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT); |
| 1721 | else |
| 1722 | val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT); |
| 1723 | kcontrol->private_value = val; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1724 | err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv); |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1725 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1726 | return err; |
| 1727 | } |
| 1728 | |
| 1729 | typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol, |
| 1730 | struct snd_ctl_elem_value *ucontrol); |
| 1731 | |
| 1732 | static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol, |
| 1733 | struct snd_ctl_elem_value *ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1734 | getput_call_t func, bool check_adc_switch) |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1735 | { |
| 1736 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1737 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1738 | int i, err = 0; |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1739 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1740 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1741 | if (check_adc_switch && spec->dyn_adc_switch) { |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1742 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 1743 | kcontrol->private_value = |
| 1744 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], |
| 1745 | 3, 0, HDA_INPUT); |
| 1746 | err = func(kcontrol, ucontrol); |
| 1747 | if (err < 0) |
| 1748 | goto error; |
| 1749 | } |
| 1750 | } else { |
| 1751 | i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 1752 | if (spec->vol_in_capsrc) |
| 1753 | kcontrol->private_value = |
| 1754 | HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i], |
| 1755 | 3, 0, HDA_OUTPUT); |
| 1756 | else |
| 1757 | kcontrol->private_value = |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 1758 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], |
| 1759 | 3, 0, HDA_INPUT); |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1760 | err = func(kcontrol, ucontrol); |
| 1761 | } |
| 1762 | error: |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1763 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1764 | return err; |
| 1765 | } |
| 1766 | |
| 1767 | static int alc_cap_vol_get(struct snd_kcontrol *kcontrol, |
| 1768 | struct snd_ctl_elem_value *ucontrol) |
| 1769 | { |
| 1770 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1771 | snd_hda_mixer_amp_volume_get, false); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | static int alc_cap_vol_put(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_volume_put, true); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | /* capture mixer elements */ |
| 1782 | #define alc_cap_sw_info snd_ctl_boolean_stereo_info |
| 1783 | |
| 1784 | static int alc_cap_sw_get(struct snd_kcontrol *kcontrol, |
| 1785 | struct snd_ctl_elem_value *ucontrol) |
| 1786 | { |
| 1787 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1788 | snd_hda_mixer_amp_switch_get, false); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | static int alc_cap_sw_put(struct snd_kcontrol *kcontrol, |
| 1792 | struct snd_ctl_elem_value *ucontrol) |
| 1793 | { |
| 1794 | return alc_cap_getput_caller(kcontrol, ucontrol, |
Takashi Iwai | 9c7a083 | 2011-07-07 09:25:54 +0200 | [diff] [blame] | 1795 | snd_hda_mixer_amp_switch_put, true); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1796 | } |
| 1797 | |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1798 | #define _DEFINE_CAPMIX(num) \ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1799 | { \ |
| 1800 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1801 | .name = "Capture Switch", \ |
| 1802 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \ |
| 1803 | .count = num, \ |
| 1804 | .info = alc_cap_sw_info, \ |
| 1805 | .get = alc_cap_sw_get, \ |
| 1806 | .put = alc_cap_sw_put, \ |
| 1807 | }, \ |
| 1808 | { \ |
| 1809 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1810 | .name = "Capture Volume", \ |
| 1811 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \ |
| 1812 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ |
| 1813 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \ |
| 1814 | .count = num, \ |
| 1815 | .info = alc_cap_vol_info, \ |
| 1816 | .get = alc_cap_vol_get, \ |
| 1817 | .put = alc_cap_vol_put, \ |
| 1818 | .tlv = { .c = alc_cap_vol_tlv }, \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | #define _DEFINE_CAPSRC(num) \ |
Takashi Iwai | 3c3e989 | 2008-10-31 17:48:56 +0100 | [diff] [blame] | 1822 | { \ |
| 1823 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1824 | /* .name = "Capture Source", */ \ |
| 1825 | .name = "Input Source", \ |
| 1826 | .count = num, \ |
| 1827 | .info = alc_mux_enum_info, \ |
| 1828 | .get = alc_mux_enum_get, \ |
| 1829 | .put = alc_mux_enum_put, \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | #define DEFINE_CAPMIX(num) \ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1833 | static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1834 | _DEFINE_CAPMIX(num), \ |
| 1835 | _DEFINE_CAPSRC(num), \ |
| 1836 | { } /* end */ \ |
| 1837 | } |
| 1838 | |
| 1839 | #define DEFINE_CAPMIX_NOSRC(num) \ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1840 | static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \ |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1841 | _DEFINE_CAPMIX(num), \ |
| 1842 | { } /* end */ \ |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | /* up to three ADCs */ |
| 1846 | DEFINE_CAPMIX(1); |
| 1847 | DEFINE_CAPMIX(2); |
| 1848 | DEFINE_CAPMIX(3); |
Takashi Iwai | a23b688 | 2009-03-23 15:21:36 +0100 | [diff] [blame] | 1849 | DEFINE_CAPMIX_NOSRC(1); |
| 1850 | DEFINE_CAPMIX_NOSRC(2); |
| 1851 | DEFINE_CAPMIX_NOSRC(3); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1852 | |
| 1853 | /* |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1854 | * virtual master controls |
| 1855 | */ |
| 1856 | |
| 1857 | /* |
| 1858 | * slave controls for virtual master |
| 1859 | */ |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1860 | static const char * const alc_slave_vols[] = { |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1861 | "Front Playback Volume", |
| 1862 | "Surround Playback Volume", |
| 1863 | "Center Playback Volume", |
| 1864 | "LFE Playback Volume", |
| 1865 | "Side Playback Volume", |
| 1866 | "Headphone Playback Volume", |
| 1867 | "Speaker Playback Volume", |
| 1868 | "Mono Playback Volume", |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1869 | "Line-Out Playback Volume", |
Takashi Iwai | 3fe45ae | 2011-08-18 15:13:17 +0200 | [diff] [blame] | 1870 | "PCM Playback Volume", |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1871 | NULL, |
| 1872 | }; |
| 1873 | |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1874 | static const char * const alc_slave_sws[] = { |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1875 | "Front Playback Switch", |
| 1876 | "Surround Playback Switch", |
| 1877 | "Center Playback Switch", |
| 1878 | "LFE Playback Switch", |
| 1879 | "Side Playback Switch", |
| 1880 | "Headphone Playback Switch", |
| 1881 | "Speaker Playback Switch", |
| 1882 | "Mono Playback Switch", |
Takashi Iwai | edb54a5 | 2008-01-29 12:47:02 +0100 | [diff] [blame] | 1883 | "IEC958 Playback Switch", |
Takashi Iwai | 23033b2 | 2009-12-08 12:36:52 +0100 | [diff] [blame] | 1884 | "Line-Out Playback Switch", |
Takashi Iwai | 3fe45ae | 2011-08-18 15:13:17 +0200 | [diff] [blame] | 1885 | "PCM Playback Switch", |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1886 | NULL, |
| 1887 | }; |
| 1888 | |
| 1889 | /* |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 1890 | * build control elements |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | */ |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1892 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1893 | #define NID_MAPPING (-1) |
| 1894 | |
| 1895 | #define SUBDEV_SPEAKER_ (0 << 6) |
| 1896 | #define SUBDEV_HP_ (1 << 6) |
| 1897 | #define SUBDEV_LINE_ (2 << 6) |
| 1898 | #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f)) |
| 1899 | #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f)) |
| 1900 | #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f)) |
| 1901 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1902 | static void alc_free_kctls(struct hda_codec *codec); |
| 1903 | |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1904 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1905 | /* additional beep mixers; the actual parameters are overwritten at build */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1906 | static const struct snd_kcontrol_new alc_beep_mixer[] = { |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1907 | HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT), |
Jaroslav Kysela | 123c07a | 2009-10-21 14:48:23 +0200 | [diff] [blame] | 1908 | HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT), |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1909 | { } /* end */ |
| 1910 | }; |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1911 | #endif |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | static int alc_build_controls(struct hda_codec *codec) |
| 1914 | { |
| 1915 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2f44f84 | 2010-06-22 11:12:32 +0200 | [diff] [blame] | 1916 | struct snd_kcontrol *kctl = NULL; |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1917 | const struct snd_kcontrol_new *knew; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1918 | int i, j, err; |
| 1919 | unsigned int u; |
| 1920 | hda_nid_t nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | |
| 1922 | for (i = 0; i < spec->num_mixers; i++) { |
| 1923 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 1924 | if (err < 0) |
| 1925 | return err; |
| 1926 | } |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 1927 | if (spec->cap_mixer) { |
| 1928 | err = snd_hda_add_new_ctls(codec, spec->cap_mixer); |
| 1929 | if (err < 0) |
| 1930 | return err; |
| 1931 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | if (spec->multiout.dig_out_nid) { |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 1933 | err = snd_hda_create_spdif_out_ctls(codec, |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 1934 | spec->multiout.dig_out_nid, |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 1935 | spec->multiout.dig_out_nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | if (err < 0) |
| 1937 | return err; |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1938 | if (!spec->no_analog) { |
| 1939 | err = snd_hda_create_spdif_share_sw(codec, |
| 1940 | &spec->multiout); |
| 1941 | if (err < 0) |
| 1942 | return err; |
| 1943 | spec->multiout.share_spdif = 1; |
| 1944 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | } |
| 1946 | if (spec->dig_in_nid) { |
| 1947 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); |
| 1948 | if (err < 0) |
| 1949 | return err; |
| 1950 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1951 | |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1952 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1953 | /* create beep controls if needed */ |
| 1954 | if (spec->beep_amp) { |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1955 | const struct snd_kcontrol_new *knew; |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1956 | for (knew = alc_beep_mixer; knew->name; knew++) { |
| 1957 | struct snd_kcontrol *kctl; |
| 1958 | kctl = snd_ctl_new1(knew, codec); |
| 1959 | if (!kctl) |
| 1960 | return -ENOMEM; |
| 1961 | kctl->private_value = spec->beep_amp; |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 1962 | err = snd_hda_ctl_add(codec, 0, kctl); |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1963 | if (err < 0) |
| 1964 | return err; |
| 1965 | } |
| 1966 | } |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 1967 | #endif |
Takashi Iwai | 45bdd1c | 2009-02-06 16:11:25 +0100 | [diff] [blame] | 1968 | |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1969 | /* if we have no master control, let's create it */ |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1970 | if (!spec->no_analog && |
| 1971 | !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1972 | unsigned int vmaster_tlv[4]; |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1973 | snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1974 | HDA_OUTPUT, vmaster_tlv); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1975 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", |
Takashi Iwai | 1c82ed1 | 2008-02-18 13:05:50 +0100 | [diff] [blame] | 1976 | vmaster_tlv, alc_slave_vols); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1977 | if (err < 0) |
| 1978 | return err; |
| 1979 | } |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 1980 | if (!spec->no_analog && |
| 1981 | !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1982 | err = snd_hda_add_vmaster(codec, "Master Playback Switch", |
| 1983 | NULL, alc_slave_sws); |
| 1984 | if (err < 0) |
| 1985 | return err; |
| 1986 | } |
| 1987 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1988 | /* assign Capture Source enums to NID */ |
Takashi Iwai | fbe618f | 2010-06-11 11:24:58 +0200 | [diff] [blame] | 1989 | if (spec->capsrc_nids || spec->adc_nids) { |
| 1990 | kctl = snd_hda_find_mixer_ctl(codec, "Capture Source"); |
| 1991 | if (!kctl) |
| 1992 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); |
| 1993 | for (i = 0; kctl && i < kctl->count; i++) { |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 1994 | const hda_nid_t *nids = spec->capsrc_nids; |
Takashi Iwai | fbe618f | 2010-06-11 11:24:58 +0200 | [diff] [blame] | 1995 | if (!nids) |
| 1996 | nids = spec->adc_nids; |
| 1997 | err = snd_hda_add_nid(codec, kctl, i, nids[i]); |
| 1998 | if (err < 0) |
| 1999 | return err; |
| 2000 | } |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2001 | } |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 2002 | if (spec->cap_mixer && spec->adc_nids) { |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2003 | const char *kname = kctl ? kctl->id.name : NULL; |
| 2004 | for (knew = spec->cap_mixer; knew->name; knew++) { |
| 2005 | if (kname && strcmp(knew->name, kname) == 0) |
| 2006 | continue; |
| 2007 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 2008 | for (i = 0; kctl && i < kctl->count; i++) { |
| 2009 | err = snd_hda_add_nid(codec, kctl, i, |
| 2010 | spec->adc_nids[i]); |
| 2011 | if (err < 0) |
| 2012 | return err; |
| 2013 | } |
| 2014 | } |
| 2015 | } |
| 2016 | |
| 2017 | /* other nid->control mapping */ |
| 2018 | for (i = 0; i < spec->num_mixers; i++) { |
| 2019 | for (knew = spec->mixers[i]; knew->name; knew++) { |
| 2020 | if (knew->iface != NID_MAPPING) |
| 2021 | continue; |
| 2022 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 2023 | if (kctl == NULL) |
| 2024 | continue; |
| 2025 | u = knew->subdevice; |
| 2026 | for (j = 0; j < 4; j++, u >>= 8) { |
| 2027 | nid = u & 0x3f; |
| 2028 | if (nid == 0) |
| 2029 | continue; |
| 2030 | switch (u & 0xc0) { |
| 2031 | case SUBDEV_SPEAKER_: |
| 2032 | nid = spec->autocfg.speaker_pins[nid]; |
| 2033 | break; |
| 2034 | case SUBDEV_LINE_: |
| 2035 | nid = spec->autocfg.line_out_pins[nid]; |
| 2036 | break; |
| 2037 | case SUBDEV_HP_: |
| 2038 | nid = spec->autocfg.hp_pins[nid]; |
| 2039 | break; |
| 2040 | default: |
| 2041 | continue; |
| 2042 | } |
| 2043 | err = snd_hda_add_nid(codec, kctl, 0, nid); |
| 2044 | if (err < 0) |
| 2045 | return err; |
| 2046 | } |
| 2047 | u = knew->private_value; |
| 2048 | for (j = 0; j < 4; j++, u >>= 8) { |
| 2049 | nid = u & 0xff; |
| 2050 | if (nid == 0) |
| 2051 | continue; |
| 2052 | err = snd_hda_add_nid(codec, kctl, 0, nid); |
| 2053 | if (err < 0) |
| 2054 | return err; |
| 2055 | } |
| 2056 | } |
| 2057 | } |
Takashi Iwai | bae84e7 | 2010-03-22 08:30:20 +0100 | [diff] [blame] | 2058 | |
| 2059 | alc_free_kctls(codec); /* no longer needed */ |
| 2060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | return 0; |
| 2062 | } |
| 2063 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | /* |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2066 | * Common callbacks |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2067 | */ |
Takashi Iwai | 16ded52 | 2005-06-10 19:58:24 +0200 | [diff] [blame] | 2068 | |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 2069 | static void alc_init_special_input_src(struct hda_codec *codec); |
| 2070 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | static int alc_init(struct hda_codec *codec) |
| 2072 | { |
| 2073 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2074 | unsigned int i; |
| 2075 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 2076 | alc_fix_pll(codec); |
Takashi Iwai | 4a79ba3 | 2009-04-22 16:31:35 +0200 | [diff] [blame] | 2077 | alc_auto_init_amp(codec, spec->init_amp); |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 2078 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2079 | for (i = 0; i < spec->num_init_verbs; i++) |
| 2080 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
Takashi Iwai | 584c0c4 | 2011-03-10 12:51:11 +0100 | [diff] [blame] | 2081 | alc_init_special_input_src(codec); |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2082 | |
| 2083 | if (spec->init_hook) |
| 2084 | spec->init_hook(codec); |
| 2085 | |
Takashi Iwai | 5870112 | 2011-01-13 15:41:45 +0100 | [diff] [blame] | 2086 | alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT); |
| 2087 | |
Takashi Iwai | 9e5341b | 2010-09-21 09:57:06 +0200 | [diff] [blame] | 2088 | hda_call_check_power_status(codec, 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | return 0; |
| 2090 | } |
| 2091 | |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2092 | static void alc_unsol_event(struct hda_codec *codec, unsigned int res) |
| 2093 | { |
| 2094 | struct alc_spec *spec = codec->spec; |
| 2095 | |
| 2096 | if (spec->unsol_event) |
| 2097 | spec->unsol_event(codec, res); |
| 2098 | } |
| 2099 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2100 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2101 | static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 2102 | { |
| 2103 | struct alc_spec *spec = codec->spec; |
| 2104 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); |
| 2105 | } |
| 2106 | #endif |
| 2107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | /* |
| 2109 | * Analog playback callbacks |
| 2110 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2111 | static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9b | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2113 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | { |
| 2115 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 2116 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 2117 | hinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | } |
| 2119 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2120 | static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | struct hda_codec *codec, |
| 2122 | unsigned int stream_tag, |
| 2123 | unsigned int format, |
Takashi Iwai | c8b6bf9b | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2124 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | { |
| 2126 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 2127 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, |
| 2128 | stream_tag, format, substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2131 | static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9b | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2133 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | { |
| 2135 | struct alc_spec *spec = codec->spec; |
| 2136 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
| 2137 | } |
| 2138 | |
| 2139 | /* |
| 2140 | * Digital out |
| 2141 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2142 | static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9b | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2144 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | { |
| 2146 | struct alc_spec *spec = codec->spec; |
| 2147 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 2148 | } |
| 2149 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2150 | static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 2151 | struct hda_codec *codec, |
| 2152 | unsigned int stream_tag, |
| 2153 | unsigned int format, |
| 2154 | struct snd_pcm_substream *substream) |
| 2155 | { |
| 2156 | struct alc_spec *spec = codec->spec; |
| 2157 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 2158 | stream_tag, format, substream); |
| 2159 | } |
| 2160 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2161 | static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 9b5f12e | 2009-02-13 11:47:37 +0100 | [diff] [blame] | 2162 | struct hda_codec *codec, |
| 2163 | struct snd_pcm_substream *substream) |
| 2164 | { |
| 2165 | struct alc_spec *spec = codec->spec; |
| 2166 | return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
| 2167 | } |
| 2168 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2169 | static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9b | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2171 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | { |
| 2173 | struct alc_spec *spec = codec->spec; |
| 2174 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 2175 | } |
| 2176 | |
| 2177 | /* |
| 2178 | * Analog capture |
| 2179 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2180 | static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | struct hda_codec *codec, |
| 2182 | unsigned int stream_tag, |
| 2183 | unsigned int format, |
Takashi Iwai | c8b6bf9b | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2184 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | { |
| 2186 | struct alc_spec *spec = codec->spec; |
| 2187 | |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2188 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | stream_tag, 0, format); |
| 2190 | return 0; |
| 2191 | } |
| 2192 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2193 | static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9b | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2195 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | { |
| 2197 | struct alc_spec *spec = codec->spec; |
| 2198 | |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 2199 | snd_hda_codec_cleanup_stream(codec, |
| 2200 | spec->adc_nids[substream->number + 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | return 0; |
| 2202 | } |
| 2203 | |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2204 | /* analog capture with dynamic dual-adc changes */ |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2205 | static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2206 | struct hda_codec *codec, |
| 2207 | unsigned int stream_tag, |
| 2208 | unsigned int format, |
| 2209 | struct snd_pcm_substream *substream) |
| 2210 | { |
| 2211 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2212 | 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] | 2213 | spec->cur_adc_stream_tag = stream_tag; |
| 2214 | spec->cur_adc_format = format; |
| 2215 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); |
| 2216 | return 0; |
| 2217 | } |
| 2218 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2219 | static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2220 | struct hda_codec *codec, |
| 2221 | struct snd_pcm_substream *substream) |
| 2222 | { |
| 2223 | struct alc_spec *spec = codec->spec; |
| 2224 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
| 2225 | spec->cur_adc = 0; |
| 2226 | return 0; |
| 2227 | } |
| 2228 | |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2229 | static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = { |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2230 | .substreams = 1, |
| 2231 | .channels_min = 2, |
| 2232 | .channels_max = 2, |
| 2233 | .nid = 0, /* fill later */ |
| 2234 | .ops = { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2235 | .prepare = dyn_adc_capture_pcm_prepare, |
| 2236 | .cleanup = dyn_adc_capture_pcm_cleanup |
Takashi Iwai | 840b64c | 2010-07-13 22:49:01 +0200 | [diff] [blame] | 2237 | }, |
| 2238 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | |
| 2240 | /* |
| 2241 | */ |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2242 | static const struct hda_pcm_stream alc_pcm_analog_playback = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | .substreams = 1, |
| 2244 | .channels_min = 2, |
| 2245 | .channels_max = 8, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2246 | /* NID is set in alc_build_pcms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2248 | .open = alc_playback_pcm_open, |
| 2249 | .prepare = alc_playback_pcm_prepare, |
| 2250 | .cleanup = alc_playback_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | }, |
| 2252 | }; |
| 2253 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2254 | static const struct hda_pcm_stream alc_pcm_analog_capture = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2255 | .substreams = 1, |
| 2256 | .channels_min = 2, |
| 2257 | .channels_max = 2, |
| 2258 | /* NID is set in alc_build_pcms */ |
| 2259 | }; |
| 2260 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2261 | static const struct hda_pcm_stream alc_pcm_analog_alt_playback = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2262 | .substreams = 1, |
| 2263 | .channels_min = 2, |
| 2264 | .channels_max = 2, |
| 2265 | /* NID is set in alc_build_pcms */ |
| 2266 | }; |
| 2267 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2268 | static const struct hda_pcm_stream alc_pcm_analog_alt_capture = { |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2269 | .substreams = 2, /* can be overridden */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | .channels_min = 2, |
| 2271 | .channels_max = 2, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2272 | /* NID is set in alc_build_pcms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2274 | .prepare = alc_alt_capture_pcm_prepare, |
| 2275 | .cleanup = alc_alt_capture_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | }, |
| 2277 | }; |
| 2278 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2279 | static const struct hda_pcm_stream alc_pcm_digital_playback = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | .substreams = 1, |
| 2281 | .channels_min = 2, |
| 2282 | .channels_max = 2, |
| 2283 | /* NID is set in alc_build_pcms */ |
| 2284 | .ops = { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2285 | .open = alc_dig_playback_pcm_open, |
| 2286 | .close = alc_dig_playback_pcm_close, |
| 2287 | .prepare = alc_dig_playback_pcm_prepare, |
| 2288 | .cleanup = alc_dig_playback_pcm_cleanup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | }, |
| 2290 | }; |
| 2291 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2292 | static const struct hda_pcm_stream alc_pcm_digital_capture = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | .substreams = 1, |
| 2294 | .channels_min = 2, |
| 2295 | .channels_max = 2, |
| 2296 | /* NID is set in alc_build_pcms */ |
| 2297 | }; |
| 2298 | |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 2299 | /* 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] | 2300 | static const struct hda_pcm_stream alc_pcm_null_stream = { |
Jonathan Woithe | 4c5186e | 2006-02-09 11:53:48 +0100 | [diff] [blame] | 2301 | .substreams = 0, |
| 2302 | .channels_min = 0, |
| 2303 | .channels_max = 0, |
| 2304 | }; |
| 2305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | static int alc_build_pcms(struct hda_codec *codec) |
| 2307 | { |
| 2308 | struct alc_spec *spec = codec->spec; |
| 2309 | struct hda_pcm *info = spec->pcm_rec; |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2310 | const struct hda_pcm_stream *p; |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2311 | bool have_multi_adcs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | int i; |
| 2313 | |
| 2314 | codec->num_pcms = 1; |
| 2315 | codec->pcm_info = info; |
| 2316 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2317 | if (spec->no_analog) |
| 2318 | goto skip_analog; |
| 2319 | |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 2320 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), |
| 2321 | "%s Analog", codec->chip_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | info->name = spec->stream_name_analog; |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 2323 | |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2324 | if (spec->multiout.dac_nids > 0) { |
| 2325 | p = spec->stream_analog_playback; |
| 2326 | if (!p) |
| 2327 | p = &alc_pcm_analog_playback; |
| 2328 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2329 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; |
| 2330 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2331 | if (spec->adc_nids) { |
| 2332 | p = spec->stream_analog_capture; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2333 | if (!p) { |
| 2334 | if (spec->dyn_adc_switch) |
| 2335 | p = &dyn_adc_pcm_analog_capture; |
| 2336 | else |
| 2337 | p = &alc_pcm_analog_capture; |
| 2338 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2339 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2340 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 2341 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 2343 | if (spec->channel_mode) { |
| 2344 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0; |
| 2345 | for (i = 0; i < spec->num_channel_mode; i++) { |
| 2346 | if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) { |
| 2347 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels; |
| 2348 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | } |
| 2350 | } |
| 2351 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2352 | skip_analog: |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2353 | /* SPDIF for stream index #1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 2355 | snprintf(spec->stream_name_digital, |
| 2356 | sizeof(spec->stream_name_digital), |
| 2357 | "%s Digital", codec->chip_name); |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2358 | codec->num_pcms = 2; |
Wu Fengguang | b25c9da | 2009-02-06 15:02:27 +0800 | [diff] [blame] | 2359 | codec->slave_dig_outs = spec->multiout.slave_dig_outs; |
Takashi Iwai | c06134d | 2006-10-11 18:49:13 +0200 | [diff] [blame] | 2360 | info = spec->pcm_rec + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | info->name = spec->stream_name_digital; |
Takashi Iwai | 8c44198 | 2009-01-20 18:30:20 +0100 | [diff] [blame] | 2362 | if (spec->dig_out_type) |
| 2363 | info->pcm_type = spec->dig_out_type; |
| 2364 | else |
| 2365 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2366 | if (spec->multiout.dig_out_nid) { |
| 2367 | p = spec->stream_digital_playback; |
| 2368 | if (!p) |
| 2369 | p = &alc_pcm_digital_playback; |
| 2370 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; |
| 2372 | } |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2373 | if (spec->dig_in_nid) { |
| 2374 | p = spec->stream_digital_capture; |
| 2375 | if (!p) |
| 2376 | p = &alc_pcm_digital_capture; |
| 2377 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; |
| 2379 | } |
Takashi Iwai | 963f803 | 2008-08-11 10:04:40 +0200 | [diff] [blame] | 2380 | /* FIXME: do we need this for all Realtek codec models? */ |
| 2381 | codec->spdif_status_reset = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | } |
| 2383 | |
Takashi Iwai | e64f14f | 2009-01-20 18:32:55 +0100 | [diff] [blame] | 2384 | if (spec->no_analog) |
| 2385 | return 0; |
| 2386 | |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2387 | /* If the use of more than one ADC is requested for the current |
| 2388 | * model, configure a second analog capture-only PCM. |
| 2389 | */ |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2390 | have_multi_adcs = (spec->num_adc_nids > 1) && |
| 2391 | !spec->dyn_adc_switch && !spec->auto_mic && |
| 2392 | (!spec->input_mux || spec->input_mux->num_items > 1); |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2393 | /* Additional Analaog capture for index #2 */ |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2394 | if (spec->alt_dac_nid || have_multi_adcs) { |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2395 | codec->num_pcms = 3; |
Takashi Iwai | c06134d | 2006-10-11 18:49:13 +0200 | [diff] [blame] | 2396 | info = spec->pcm_rec + 2; |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2397 | info->name = spec->stream_name_analog; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2398 | if (spec->alt_dac_nid) { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2399 | p = spec->stream_analog_alt_playback; |
| 2400 | if (!p) |
| 2401 | p = &alc_pcm_analog_alt_playback; |
| 2402 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2403 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 2404 | spec->alt_dac_nid; |
| 2405 | } else { |
| 2406 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 2407 | alc_pcm_null_stream; |
| 2408 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0; |
| 2409 | } |
Takashi Iwai | 1fa1757 | 2011-11-02 21:30:51 +0100 | [diff] [blame] | 2410 | if (have_multi_adcs) { |
Takashi Iwai | c2d986b | 2011-07-06 18:30:08 +0200 | [diff] [blame] | 2411 | p = spec->stream_analog_alt_capture; |
| 2412 | if (!p) |
| 2413 | p = &alc_pcm_analog_alt_capture; |
| 2414 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
Takashi Iwai | 6330079 | 2008-01-24 15:31:36 +0100 | [diff] [blame] | 2415 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 2416 | spec->adc_nids[1]; |
| 2417 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = |
| 2418 | spec->num_adc_nids - 1; |
| 2419 | } else { |
| 2420 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 2421 | alc_pcm_null_stream; |
| 2422 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0; |
Takashi Iwai | e08a007 | 2006-09-07 17:52:14 +0200 | [diff] [blame] | 2423 | } |
| 2424 | } |
| 2425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | return 0; |
| 2427 | } |
| 2428 | |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2429 | static inline void alc_shutup(struct hda_codec *codec) |
| 2430 | { |
Takashi Iwai | 1c71615 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 2431 | struct alc_spec *spec = codec->spec; |
| 2432 | |
| 2433 | if (spec && spec->shutup) |
| 2434 | spec->shutup(codec); |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2435 | snd_hda_shutup_pins(codec); |
| 2436 | } |
| 2437 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2438 | static void alc_free_kctls(struct hda_codec *codec) |
| 2439 | { |
| 2440 | struct alc_spec *spec = codec->spec; |
| 2441 | |
| 2442 | if (spec->kctls.list) { |
| 2443 | struct snd_kcontrol_new *kctl = spec->kctls.list; |
| 2444 | int i; |
| 2445 | for (i = 0; i < spec->kctls.used; i++) |
| 2446 | kfree(kctl[i].name); |
| 2447 | } |
| 2448 | snd_array_free(&spec->kctls); |
| 2449 | } |
| 2450 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2451 | static void alc_free_bind_ctls(struct hda_codec *codec) |
| 2452 | { |
| 2453 | struct alc_spec *spec = codec->spec; |
| 2454 | if (spec->bind_ctls.list) { |
| 2455 | struct hda_bind_ctls **ctl = spec->bind_ctls.list; |
| 2456 | int i; |
| 2457 | for (i = 0; i < spec->bind_ctls.used; i++) |
| 2458 | kfree(ctl[i]); |
| 2459 | } |
| 2460 | snd_array_free(&spec->bind_ctls); |
| 2461 | } |
| 2462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | static void alc_free(struct hda_codec *codec) |
| 2464 | { |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2465 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2466 | |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2467 | if (!spec) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2468 | return; |
| 2469 | |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2470 | alc_shutup(codec); |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 2471 | snd_hda_input_jack_free(codec); |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2472 | alc_free_kctls(codec); |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2473 | alc_free_bind_ctls(codec); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2474 | kfree(spec); |
Kusanagi Kouichi | 680cd53 | 2009-02-05 00:00:58 +0900 | [diff] [blame] | 2475 | snd_hda_detach_beep_device(codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2478 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2479 | static void alc_power_eapd(struct hda_codec *codec) |
| 2480 | { |
Takashi Iwai | 691f1fc | 2011-04-07 10:31:43 +0200 | [diff] [blame] | 2481 | alc_auto_setup_eapd(codec, false); |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2482 | } |
| 2483 | |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2484 | static int alc_suspend(struct hda_codec *codec, pm_message_t state) |
| 2485 | { |
| 2486 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | a4e09aa | 2009-12-27 11:22:24 +0100 | [diff] [blame] | 2487 | alc_shutup(codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2488 | if (spec && spec->power_hook) |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2489 | spec->power_hook(codec); |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2490 | return 0; |
| 2491 | } |
| 2492 | #endif |
| 2493 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 2494 | #ifdef CONFIG_PM |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2495 | static int alc_resume(struct hda_codec *codec) |
| 2496 | { |
Takashi Iwai | 1c71615 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 2497 | msleep(150); /* to avoid pop noise */ |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2498 | codec->patch_ops.init(codec); |
| 2499 | snd_hda_codec_resume_amp(codec); |
| 2500 | snd_hda_codec_resume_cache(codec); |
Takashi Iwai | 9e5341b | 2010-09-21 09:57:06 +0200 | [diff] [blame] | 2501 | hda_call_check_power_status(codec, 0x01); |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2502 | return 0; |
| 2503 | } |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2504 | #endif |
| 2505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | /* |
| 2507 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 2508 | static const struct hda_codec_ops alc_patch_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | .build_controls = alc_build_controls, |
| 2510 | .build_pcms = alc_build_pcms, |
| 2511 | .init = alc_init, |
| 2512 | .free = alc_free, |
Takashi Iwai | ae6b813 | 2006-03-03 16:47:17 +0100 | [diff] [blame] | 2513 | .unsol_event = alc_unsol_event, |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 2514 | #ifdef CONFIG_PM |
Takashi Iwai | e044c39 | 2008-10-27 16:56:24 +0100 | [diff] [blame] | 2515 | .resume = alc_resume, |
| 2516 | #endif |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2517 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Hector Martin | f5de24b | 2009-12-20 22:51:31 +0100 | [diff] [blame] | 2518 | .suspend = alc_suspend, |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2519 | .check_power_status = alc_check_power_status, |
| 2520 | #endif |
Daniel T Chen | c97259d | 2009-12-27 18:52:08 -0500 | [diff] [blame] | 2521 | .reboot_notify = alc_shutup, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | }; |
| 2523 | |
Kailang Yang | c027ddc | 2010-03-19 11:33:06 +0100 | [diff] [blame] | 2524 | /* replace the codec chip_name with the given string */ |
| 2525 | static int alc_codec_rename(struct hda_codec *codec, const char *name) |
| 2526 | { |
| 2527 | kfree(codec->chip_name); |
| 2528 | codec->chip_name = kstrdup(name, GFP_KERNEL); |
| 2529 | if (!codec->chip_name) { |
| 2530 | alc_free(codec); |
| 2531 | return -ENOMEM; |
| 2532 | } |
| 2533 | return 0; |
| 2534 | } |
| 2535 | |
Takashi Iwai | 2fa522b | 2005-05-12 14:51:12 +0200 | [diff] [blame] | 2536 | /* |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2537 | * Rename codecs appropriately from COEF value |
| 2538 | */ |
| 2539 | struct alc_codec_rename_table { |
| 2540 | unsigned int vendor_id; |
| 2541 | unsigned short coef_mask; |
| 2542 | unsigned short coef_bits; |
| 2543 | const char *name; |
| 2544 | }; |
| 2545 | |
| 2546 | static struct alc_codec_rename_table rename_tbl[] = { |
| 2547 | { 0x10ec0269, 0xfff0, 0x3010, "ALC277" }, |
| 2548 | { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" }, |
| 2549 | { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" }, |
| 2550 | { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" }, |
| 2551 | { 0x10ec0269, 0xffff, 0xa023, "ALC259" }, |
| 2552 | { 0x10ec0269, 0xffff, 0x6023, "ALC281X" }, |
| 2553 | { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" }, |
| 2554 | { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" }, |
| 2555 | { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" }, |
| 2556 | { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" }, |
| 2557 | { 0x10ec0899, 0x2000, 0x2000, "ALC899" }, |
| 2558 | { 0x10ec0892, 0xffff, 0x8020, "ALC661" }, |
| 2559 | { 0x10ec0892, 0xffff, 0x8011, "ALC661" }, |
| 2560 | { 0x10ec0892, 0xffff, 0x4011, "ALC656" }, |
| 2561 | { } /* terminator */ |
| 2562 | }; |
| 2563 | |
| 2564 | static int alc_codec_rename_from_preset(struct hda_codec *codec) |
| 2565 | { |
| 2566 | const struct alc_codec_rename_table *p; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2567 | |
| 2568 | for (p = rename_tbl; p->vendor_id; p++) { |
| 2569 | if (p->vendor_id != codec->vendor_id) |
| 2570 | continue; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 2571 | if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits) |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 2572 | return alc_codec_rename(codec, p->name); |
| 2573 | } |
| 2574 | return 0; |
| 2575 | } |
| 2576 | |
| 2577 | /* |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2578 | * Automatic parse of I/O pins from the BIOS configuration |
| 2579 | */ |
| 2580 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2581 | enum { |
| 2582 | ALC_CTL_WIDGET_VOL, |
| 2583 | ALC_CTL_WIDGET_MUTE, |
| 2584 | ALC_CTL_BIND_MUTE, |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2585 | ALC_CTL_BIND_VOL, |
| 2586 | ALC_CTL_BIND_SW, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2587 | }; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2588 | static const struct snd_kcontrol_new alc_control_templates[] = { |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2589 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
| 2590 | HDA_CODEC_MUTE(NULL, 0, 0, 0), |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2591 | HDA_BIND_MUTE(NULL, 0, 0, 0), |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2592 | HDA_BIND_VOL(NULL, 0), |
| 2593 | HDA_BIND_SW(NULL, 0), |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2594 | }; |
| 2595 | |
| 2596 | /* add dynamic controls */ |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2597 | 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] | 2598 | int cidx, unsigned long val) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2599 | { |
Takashi Iwai | c8b6bf9b | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2600 | struct snd_kcontrol_new *knew; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2601 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2602 | knew = alc_kcontrol_new(spec); |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2603 | if (!knew) |
| 2604 | return -ENOMEM; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2605 | *knew = alc_control_templates[type]; |
Paulo Marques | 543537b | 2005-06-23 00:09:02 -0700 | [diff] [blame] | 2606 | knew->name = kstrdup(name, GFP_KERNEL); |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2607 | if (!knew->name) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2608 | return -ENOMEM; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2609 | knew->index = cidx; |
Jaroslav Kysela | 4d02d1b | 2009-11-12 10:15:48 +0100 | [diff] [blame] | 2610 | if (get_amp_nid_(val)) |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 2611 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2612 | knew->private_value = val; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2613 | return 0; |
| 2614 | } |
| 2615 | |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2616 | static int add_control_with_pfx(struct alc_spec *spec, int type, |
| 2617 | const char *pfx, const char *dir, |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2618 | const char *sfx, int cidx, unsigned long val) |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2619 | { |
| 2620 | char name[32]; |
| 2621 | snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx); |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2622 | return add_control(spec, type, name, cidx, val); |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2623 | } |
| 2624 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2625 | #define add_pb_vol_ctrl(spec, type, pfx, val) \ |
| 2626 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val) |
| 2627 | #define add_pb_sw_ctrl(spec, type, pfx, val) \ |
| 2628 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val) |
| 2629 | #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \ |
| 2630 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val) |
| 2631 | #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \ |
| 2632 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val) |
Takashi Iwai | 0afe5f8 | 2009-10-02 09:20:00 +0200 | [diff] [blame] | 2633 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2634 | static const char * const channel_name[4] = { |
| 2635 | "Front", "Surround", "CLFE", "Side" |
| 2636 | }; |
| 2637 | |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2638 | static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch, |
| 2639 | bool can_be_master, int *index) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2640 | { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2641 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2642 | |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2643 | *index = 0; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2644 | if (cfg->line_outs == 1 && !spec->multi_ios && |
| 2645 | !cfg->hp_outs && !cfg->speaker_outs && can_be_master) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2646 | return "Master"; |
| 2647 | |
| 2648 | switch (cfg->line_out_type) { |
| 2649 | case AUTO_PIN_SPEAKER_OUT: |
David Henningsson | ebbeb3d | 2011-03-04 14:08:30 +0100 | [diff] [blame] | 2650 | if (cfg->line_outs == 1) |
| 2651 | return "Speaker"; |
| 2652 | break; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2653 | case AUTO_PIN_HP_OUT: |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 2654 | /* for multi-io case, only the primary out */ |
| 2655 | if (ch && spec->multi_ios) |
| 2656 | break; |
| 2657 | *index = ch; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2658 | return "Headphone"; |
| 2659 | default: |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2660 | if (cfg->line_outs == 1 && !spec->multi_ios) |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2661 | return "PCM"; |
| 2662 | break; |
| 2663 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 2664 | if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name))) |
| 2665 | return "PCM"; |
| 2666 | |
| 2667 | return channel_name[ch]; |
Takashi Iwai | bcb2f0f | 2011-01-10 15:45:23 +0100 | [diff] [blame] | 2668 | } |
| 2669 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2670 | /* create input playback/capture controls for the given pin */ |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2671 | 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] | 2672 | const char *ctlname, int ctlidx, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 2673 | int idx, hda_nid_t mix_nid) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2674 | { |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 2675 | int err; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2676 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2677 | err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2678 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 2679 | if (err < 0) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2680 | return err; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2681 | err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2682 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 2683 | if (err < 0) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2684 | return err; |
| 2685 | return 0; |
| 2686 | } |
| 2687 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2688 | 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] | 2689 | { |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2690 | unsigned int pincap = snd_hda_query_pin_caps(codec, nid); |
| 2691 | return (pincap & AC_PINCAP_IN) != 0; |
| 2692 | } |
| 2693 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 2694 | /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */ |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2695 | static int alc_auto_fill_adc_caps(struct hda_codec *codec) |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2696 | { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2697 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2698 | hda_nid_t nid; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2699 | hda_nid_t *adc_nids = spec->private_adc_nids; |
| 2700 | hda_nid_t *cap_nids = spec->private_capsrc_nids; |
| 2701 | int max_nums = ARRAY_SIZE(spec->private_adc_nids); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2702 | int i, nums = 0; |
| 2703 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 2704 | if (spec->shared_mic_hp) |
| 2705 | max_nums = 1; /* no multi streams with the shared HP/mic */ |
| 2706 | |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2707 | nid = codec->start_nid; |
| 2708 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 2709 | hda_nid_t src; |
| 2710 | const hda_nid_t *list; |
| 2711 | unsigned int caps = get_wcaps(codec, nid); |
| 2712 | int type = get_wcaps_type(caps); |
| 2713 | |
| 2714 | if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL)) |
| 2715 | continue; |
| 2716 | adc_nids[nums] = nid; |
| 2717 | cap_nids[nums] = nid; |
| 2718 | src = nid; |
| 2719 | for (;;) { |
| 2720 | int n; |
| 2721 | type = get_wcaps_type(get_wcaps(codec, src)); |
| 2722 | if (type == AC_WID_PIN) |
| 2723 | break; |
| 2724 | if (type == AC_WID_AUD_SEL) { |
| 2725 | cap_nids[nums] = src; |
| 2726 | break; |
| 2727 | } |
| 2728 | n = snd_hda_get_conn_list(codec, src, &list); |
| 2729 | if (n > 1) { |
| 2730 | cap_nids[nums] = src; |
| 2731 | break; |
| 2732 | } else if (n != 1) |
| 2733 | break; |
| 2734 | src = *list; |
| 2735 | } |
| 2736 | if (++nums >= max_nums) |
| 2737 | break; |
| 2738 | } |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2739 | spec->adc_nids = spec->private_adc_nids; |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2740 | spec->capsrc_nids = spec->private_capsrc_nids; |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2741 | spec->num_adc_nids = nums; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2742 | return nums; |
| 2743 | } |
| 2744 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2745 | /* create playback/capture controls for input pins */ |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2746 | static int alc_auto_create_input_ctls(struct hda_codec *codec) |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2747 | { |
| 2748 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2749 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2750 | hda_nid_t mixer = spec->mixer_nid; |
Herton Ronaldo Krzesinski | 61b9b9b | 2009-01-28 09:16:33 -0200 | [diff] [blame] | 2751 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2752 | int num_adcs; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2753 | int i, c, err, idx, type_idx = 0; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2754 | const char *prev_label = NULL; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2755 | |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2756 | num_adcs = alc_auto_fill_adc_caps(codec); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2757 | if (num_adcs < 0) |
| 2758 | return 0; |
| 2759 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2760 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2761 | hda_nid_t pin; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2762 | const char *label; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2763 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2764 | pin = cfg->inputs[i].pin; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2765 | if (!alc_is_input_pin(codec, pin)) |
| 2766 | continue; |
| 2767 | |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2768 | label = hda_get_autocfg_input_label(codec, cfg, i); |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 2769 | if (spec->shared_mic_hp && !strcmp(label, "Misc")) |
| 2770 | label = "Headphone Mic"; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2771 | if (prev_label && !strcmp(label, prev_label)) |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2772 | type_idx++; |
| 2773 | else |
| 2774 | type_idx = 0; |
David Henningsson | 5322bf2 | 2011-01-05 11:03:56 +0100 | [diff] [blame] | 2775 | prev_label = label; |
| 2776 | |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2777 | if (mixer) { |
| 2778 | idx = get_connection_index(codec, mixer, pin); |
| 2779 | if (idx >= 0) { |
| 2780 | err = new_analog_input(spec, pin, |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2781 | label, type_idx, |
| 2782 | idx, mixer); |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2783 | if (err < 0) |
| 2784 | return err; |
| 2785 | } |
| 2786 | } |
| 2787 | |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2788 | for (c = 0; c < num_adcs; c++) { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 2789 | hda_nid_t cap = spec->capsrc_nids ? |
| 2790 | spec->capsrc_nids[c] : spec->adc_nids[c]; |
| 2791 | idx = get_connection_index(codec, cap, pin); |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2792 | if (idx >= 0) { |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2793 | spec->imux_pins[imux->num_items] = pin; |
Takashi Iwai | b782170 | 2011-07-06 15:12:46 +0200 | [diff] [blame] | 2794 | snd_hda_add_imux_item(imux, label, idx, NULL); |
| 2795 | break; |
| 2796 | } |
| 2797 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2798 | } |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 2799 | |
| 2800 | spec->num_mux_defs = 1; |
| 2801 | spec->input_mux = imux; |
| 2802 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2803 | return 0; |
| 2804 | } |
| 2805 | |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 2806 | /* create a shared input with the headphone out */ |
| 2807 | static int alc_auto_create_shared_input(struct hda_codec *codec) |
| 2808 | { |
| 2809 | struct alc_spec *spec = codec->spec; |
| 2810 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2811 | unsigned int defcfg; |
| 2812 | hda_nid_t nid; |
| 2813 | |
| 2814 | /* only one internal input pin? */ |
| 2815 | if (cfg->num_inputs != 1) |
| 2816 | return 0; |
| 2817 | defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin); |
| 2818 | if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT) |
| 2819 | return 0; |
| 2820 | |
| 2821 | if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) |
| 2822 | nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */ |
| 2823 | else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT) |
| 2824 | nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */ |
| 2825 | else |
| 2826 | return 0; /* both not available */ |
| 2827 | |
| 2828 | if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN)) |
| 2829 | return 0; /* no input */ |
| 2830 | |
| 2831 | cfg->inputs[1].pin = nid; |
| 2832 | cfg->inputs[1].type = AUTO_PIN_MIC; |
| 2833 | cfg->num_inputs = 2; |
| 2834 | spec->shared_mic_hp = 1; |
| 2835 | snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid); |
| 2836 | return 0; |
| 2837 | } |
| 2838 | |
Takashi Iwai | f6c7e54 | 2008-02-12 18:32:23 +0100 | [diff] [blame] | 2839 | static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid, |
| 2840 | unsigned int pin_type) |
| 2841 | { |
| 2842 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 2843 | pin_type); |
| 2844 | /* unmute pin */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 2845 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
| 2846 | 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] | 2847 | AMP_OUT_UNMUTE); |
Takashi Iwai | f6c7e54 | 2008-02-12 18:32:23 +0100 | [diff] [blame] | 2848 | } |
| 2849 | |
Takashi Iwai | baba8ee | 2007-04-23 17:17:48 +0200 | [diff] [blame] | 2850 | static int get_pin_type(int line_out_type) |
| 2851 | { |
| 2852 | if (line_out_type == AUTO_PIN_HP_OUT) |
| 2853 | return PIN_HP; |
| 2854 | else |
| 2855 | return PIN_OUT; |
| 2856 | } |
| 2857 | |
Takashi Iwai | 0a7f532 | 2011-07-06 15:15:12 +0200 | [diff] [blame] | 2858 | static void alc_auto_init_analog_input(struct hda_codec *codec) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2859 | { |
| 2860 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2861 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2862 | int i; |
| 2863 | |
Takashi Iwai | 66ceeb6 | 2010-08-30 13:05:52 +0200 | [diff] [blame] | 2864 | for (i = 0; i < cfg->num_inputs; i++) { |
| 2865 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | 05f5f47 | 2009-08-25 13:10:18 +0200 | [diff] [blame] | 2866 | if (alc_is_input_pin(codec, nid)) { |
Takashi Iwai | 30ea098 | 2010-09-16 18:47:56 +0200 | [diff] [blame] | 2867 | alc_set_input_pin(codec, nid, cfg->inputs[i].type); |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 2868 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
Takashi Iwai | f12ab1e | 2007-04-12 15:51:47 +0200 | [diff] [blame] | 2869 | snd_hda_codec_write(codec, nid, 0, |
| 2870 | AC_VERB_SET_AMP_GAIN_MUTE, |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2871 | AMP_OUT_MUTE); |
| 2872 | } |
| 2873 | } |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 2874 | |
| 2875 | /* mute all loopback inputs */ |
| 2876 | if (spec->mixer_nid) { |
| 2877 | int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL); |
| 2878 | for (i = 0; i < nums; i++) |
| 2879 | snd_hda_codec_write(codec, spec->mixer_nid, 0, |
| 2880 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 2881 | AMP_IN_MUTE(i)); |
| 2882 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 2883 | } |
| 2884 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2885 | /* convert from MIX nid to DAC */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2886 | 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] | 2887 | { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2888 | hda_nid_t list[5]; |
Takashi Iwai | 1304ac8 | 2011-04-06 15:16:21 +0200 | [diff] [blame] | 2889 | int i, num; |
| 2890 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 2891 | if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT) |
| 2892 | return nid; |
Takashi Iwai | 1304ac8 | 2011-04-06 15:16:21 +0200 | [diff] [blame] | 2893 | num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list)); |
| 2894 | for (i = 0; i < num; i++) { |
| 2895 | if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT) |
| 2896 | return list[i]; |
| 2897 | } |
| 2898 | return 0; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2899 | } |
| 2900 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2901 | /* go down to the selector widget before the mixer */ |
| 2902 | static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin) |
| 2903 | { |
| 2904 | hda_nid_t srcs[5]; |
| 2905 | int num = snd_hda_get_connections(codec, pin, srcs, |
| 2906 | ARRAY_SIZE(srcs)); |
| 2907 | if (num != 1 || |
| 2908 | get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL) |
| 2909 | return pin; |
| 2910 | return srcs[0]; |
| 2911 | } |
| 2912 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2913 | /* get MIX nid connected to the given pin targeted to DAC */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2914 | 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] | 2915 | hda_nid_t dac) |
| 2916 | { |
David Henningsson | cc1c452 | 2010-11-24 14:17:47 +0100 | [diff] [blame] | 2917 | hda_nid_t mix[5]; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2918 | int i, num; |
| 2919 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2920 | pin = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2921 | num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); |
| 2922 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2923 | if (alc_auto_mix_to_dac(codec, mix[i]) == dac) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2924 | return mix[i]; |
| 2925 | } |
| 2926 | return 0; |
| 2927 | } |
| 2928 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 2929 | /* select the connection from pin to DAC if needed */ |
| 2930 | static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin, |
| 2931 | hda_nid_t dac) |
| 2932 | { |
| 2933 | hda_nid_t mix[5]; |
| 2934 | int i, num; |
| 2935 | |
| 2936 | pin = alc_go_down_to_selector(codec, pin); |
| 2937 | num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); |
| 2938 | if (num < 2) |
| 2939 | return 0; |
| 2940 | for (i = 0; i < num; i++) { |
| 2941 | if (alc_auto_mix_to_dac(codec, mix[i]) == dac) { |
| 2942 | snd_hda_codec_update_cache(codec, pin, 0, |
| 2943 | AC_VERB_SET_CONNECT_SEL, i); |
| 2944 | return 0; |
| 2945 | } |
| 2946 | } |
| 2947 | return 0; |
| 2948 | } |
| 2949 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2950 | /* look for an empty DAC slot */ |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2951 | 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] | 2952 | { |
| 2953 | struct alc_spec *spec = codec->spec; |
| 2954 | hda_nid_t srcs[5]; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2955 | int i, num; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2956 | |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2957 | pin = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2958 | num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs)); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2959 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 2960 | hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2961 | if (!nid) |
| 2962 | continue; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2963 | if (found_in_nid_list(nid, spec->multiout.dac_nids, |
| 2964 | spec->multiout.num_dacs)) |
| 2965 | continue; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 2966 | if (found_in_nid_list(nid, spec->multiout.hp_out_nid, |
| 2967 | ARRAY_SIZE(spec->multiout.hp_out_nid))) |
| 2968 | continue; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2969 | if (found_in_nid_list(nid, spec->multiout.extra_out_nid, |
| 2970 | ARRAY_SIZE(spec->multiout.extra_out_nid))) |
| 2971 | continue; |
| 2972 | return nid; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 2973 | } |
| 2974 | return 0; |
| 2975 | } |
| 2976 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 2977 | static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin) |
| 2978 | { |
| 2979 | hda_nid_t sel = alc_go_down_to_selector(codec, pin); |
| 2980 | if (snd_hda_get_conn_list(codec, sel, NULL) == 1) |
| 2981 | return alc_auto_look_for_dac(codec, pin); |
| 2982 | return 0; |
| 2983 | } |
| 2984 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 2985 | static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs, |
| 2986 | const hda_nid_t *pins, hda_nid_t *dacs) |
| 2987 | { |
| 2988 | int i; |
| 2989 | |
| 2990 | if (num_outs && !dacs[0]) { |
| 2991 | dacs[0] = alc_auto_look_for_dac(codec, pins[0]); |
| 2992 | if (!dacs[0]) |
| 2993 | return 0; |
| 2994 | } |
| 2995 | |
| 2996 | for (i = 1; i < num_outs; i++) |
| 2997 | dacs[i] = get_dac_if_single(codec, pins[i]); |
| 2998 | for (i = 1; i < num_outs; i++) { |
| 2999 | if (!dacs[i]) |
| 3000 | dacs[i] = alc_auto_look_for_dac(codec, pins[i]); |
| 3001 | } |
| 3002 | return 0; |
| 3003 | } |
| 3004 | |
| 3005 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, |
| 3006 | unsigned int location); |
| 3007 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3008 | /* fill in the dac_nids table from the parsed pin configuration */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3009 | static int alc_auto_fill_dac_nids(struct hda_codec *codec) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3010 | { |
| 3011 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | cb053a8 | 2011-06-27 11:32:07 +0200 | [diff] [blame] | 3012 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 350434e | 2011-06-30 21:29:12 +0200 | [diff] [blame] | 3013 | bool redone = false; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3014 | int i; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3015 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3016 | again: |
Takashi Iwai | 8f398ae | 2011-07-23 18:57:11 +0200 | [diff] [blame] | 3017 | /* set num_dacs once to full for alc_auto_look_for_dac() */ |
| 3018 | spec->multiout.num_dacs = cfg->line_outs; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3019 | spec->multiout.hp_out_nid[0] = 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3020 | spec->multiout.extra_out_nid[0] = 0; |
| 3021 | memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids)); |
| 3022 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 3023 | |
| 3024 | /* fill hard-wired DACs first */ |
| 3025 | if (!redone) { |
| 3026 | for (i = 0; i < cfg->line_outs; i++) |
| 3027 | spec->private_dac_nids[i] = |
| 3028 | get_dac_if_single(codec, cfg->line_out_pins[i]); |
| 3029 | if (cfg->hp_outs) |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3030 | spec->multiout.hp_out_nid[0] = |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3031 | get_dac_if_single(codec, cfg->hp_pins[0]); |
| 3032 | if (cfg->speaker_outs) |
| 3033 | spec->multiout.extra_out_nid[0] = |
| 3034 | get_dac_if_single(codec, cfg->speaker_pins[0]); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3035 | } |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3036 | |
| 3037 | for (i = 0; i < cfg->line_outs; i++) { |
| 3038 | hda_nid_t pin = cfg->line_out_pins[i]; |
| 3039 | if (spec->private_dac_nids[i]) |
| 3040 | continue; |
| 3041 | spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin); |
| 3042 | if (!spec->private_dac_nids[i] && !redone) { |
| 3043 | /* if we can't find primary DACs, re-probe without |
| 3044 | * checking the hard-wired DACs |
| 3045 | */ |
| 3046 | redone = true; |
| 3047 | goto again; |
| 3048 | } |
| 3049 | } |
| 3050 | |
Takashi Iwai | 8f398ae | 2011-07-23 18:57:11 +0200 | [diff] [blame] | 3051 | /* re-count num_dacs and squash invalid entries */ |
| 3052 | spec->multiout.num_dacs = 0; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3053 | for (i = 0; i < cfg->line_outs; i++) { |
| 3054 | if (spec->private_dac_nids[i]) |
| 3055 | spec->multiout.num_dacs++; |
| 3056 | else |
| 3057 | memmove(spec->private_dac_nids + i, |
| 3058 | spec->private_dac_nids + i + 1, |
| 3059 | sizeof(hda_nid_t) * (cfg->line_outs - i - 1)); |
| 3060 | } |
| 3061 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3062 | if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
| 3063 | /* try to fill multi-io first */ |
| 3064 | unsigned int location, defcfg; |
| 3065 | int num_pins; |
Takashi Iwai | bb8bf4d | 2011-07-06 13:07:54 +0200 | [diff] [blame] | 3066 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3067 | defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]); |
| 3068 | location = get_defcfg_location(defcfg); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3069 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3070 | num_pins = alc_auto_fill_multi_ios(codec, location); |
| 3071 | if (num_pins > 0) { |
| 3072 | spec->multi_ios = num_pins; |
| 3073 | spec->ext_channel_count = 2; |
| 3074 | spec->multiout.num_dacs = num_pins + 1; |
| 3075 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3076 | } |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3077 | |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3078 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) |
| 3079 | alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins, |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3080 | spec->multiout.hp_out_nid); |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3081 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) |
| 3082 | alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins, |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3083 | spec->multiout.extra_out_nid); |
| 3084 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3085 | return 0; |
| 3086 | } |
| 3087 | |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3088 | static inline unsigned int get_ctl_pos(unsigned int data) |
| 3089 | { |
| 3090 | hda_nid_t nid = get_amp_nid_(data); |
| 3091 | unsigned int dir = get_amp_direction_(data); |
| 3092 | return (nid << 1) | dir; |
| 3093 | } |
| 3094 | |
| 3095 | #define is_ctl_used(bits, data) \ |
| 3096 | test_bit(get_ctl_pos(data), bits) |
| 3097 | #define mark_ctl_usage(bits, data) \ |
| 3098 | set_bit(get_ctl_pos(data), bits) |
| 3099 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3100 | static int alc_auto_add_vol_ctl(struct hda_codec *codec, |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3101 | const char *pfx, int cidx, |
| 3102 | hda_nid_t nid, unsigned int chs) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3103 | { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3104 | struct alc_spec *spec = codec->spec; |
| 3105 | unsigned int val; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3106 | if (!nid) |
| 3107 | return 0; |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3108 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); |
| 3109 | if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */ |
| 3110 | return 0; |
| 3111 | mark_ctl_usage(spec->vol_ctls, val); |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3112 | 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] | 3113 | val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3114 | } |
| 3115 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3116 | #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \ |
| 3117 | alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3) |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3118 | |
| 3119 | /* create a mute-switch for the given mixer widget; |
| 3120 | * if it has multiple sources (e.g. DAC and loopback), create a bind-mute |
| 3121 | */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3122 | static int alc_auto_add_sw_ctl(struct hda_codec *codec, |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3123 | const char *pfx, int cidx, |
| 3124 | hda_nid_t nid, unsigned int chs) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3125 | { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3126 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3127 | int wid_type; |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3128 | int type; |
| 3129 | unsigned long val; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3130 | if (!nid) |
| 3131 | return 0; |
| 3132 | wid_type = get_wcaps_type(get_wcaps(codec, nid)); |
| 3133 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) { |
| 3134 | type = ALC_CTL_WIDGET_MUTE; |
| 3135 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); |
| 3136 | } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) { |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3137 | type = ALC_CTL_WIDGET_MUTE; |
| 3138 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT); |
| 3139 | } else { |
| 3140 | type = ALC_CTL_BIND_MUTE; |
| 3141 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT); |
| 3142 | } |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3143 | if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */ |
| 3144 | return 0; |
| 3145 | mark_ctl_usage(spec->sw_ctls, val); |
Takashi Iwai | 97aaab7 | 2011-07-06 14:02:55 +0200 | [diff] [blame] | 3146 | return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3147 | } |
| 3148 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3149 | #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \ |
| 3150 | alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3151 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3152 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, |
| 3153 | hda_nid_t pin, hda_nid_t dac) |
| 3154 | { |
| 3155 | hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac); |
| 3156 | if (nid_has_mute(codec, pin, HDA_OUTPUT)) |
| 3157 | return pin; |
| 3158 | else if (mix && nid_has_mute(codec, mix, HDA_INPUT)) |
| 3159 | return mix; |
| 3160 | else if (nid_has_mute(codec, dac, HDA_OUTPUT)) |
| 3161 | return dac; |
| 3162 | return 0; |
| 3163 | } |
| 3164 | |
| 3165 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, |
| 3166 | hda_nid_t pin, hda_nid_t dac) |
| 3167 | { |
| 3168 | hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac); |
| 3169 | if (nid_has_volume(codec, dac, HDA_OUTPUT)) |
| 3170 | return dac; |
| 3171 | else if (nid_has_volume(codec, mix, HDA_OUTPUT)) |
| 3172 | return mix; |
| 3173 | else if (nid_has_volume(codec, pin, HDA_OUTPUT)) |
| 3174 | return pin; |
| 3175 | return 0; |
| 3176 | } |
| 3177 | |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3178 | /* add playback controls from the parsed DAC table */ |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3179 | static int alc_auto_create_multi_out_ctls(struct hda_codec *codec, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3180 | const struct auto_pin_cfg *cfg) |
| 3181 | { |
| 3182 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3183 | int i, err, noutputs; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3184 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3185 | noutputs = cfg->line_outs; |
| 3186 | if (spec->multi_ios > 0) |
| 3187 | noutputs += spec->multi_ios; |
| 3188 | |
| 3189 | for (i = 0; i < noutputs; i++) { |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 3190 | const char *name; |
| 3191 | int index; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3192 | hda_nid_t dac, pin; |
| 3193 | hda_nid_t sw, vol; |
| 3194 | |
| 3195 | dac = spec->multiout.dac_nids[i]; |
| 3196 | if (!dac) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3197 | continue; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3198 | if (i >= cfg->line_outs) |
| 3199 | pin = spec->multi_io[i - 1].pin; |
| 3200 | else |
| 3201 | pin = cfg->line_out_pins[i]; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3202 | |
| 3203 | sw = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3204 | vol = alc_look_for_out_vol_nid(codec, pin, dac); |
Takashi Iwai | 6843ca1 | 2011-06-24 11:03:58 +0200 | [diff] [blame] | 3205 | name = alc_get_line_out_pfx(spec, i, true, &index); |
Takashi Iwai | 9c4e84d | 2011-08-24 17:27:52 +0200 | [diff] [blame] | 3206 | if (!name || !strcmp(name, "CLFE")) { |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3207 | /* Center/LFE */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3208 | err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3209 | if (err < 0) |
| 3210 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3211 | err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3212 | if (err < 0) |
| 3213 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3214 | err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3215 | if (err < 0) |
| 3216 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3217 | err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3218 | if (err < 0) |
| 3219 | return err; |
| 3220 | } else { |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3221 | err = alc_auto_add_stereo_vol(codec, name, index, vol); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3222 | if (err < 0) |
| 3223 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3224 | err = alc_auto_add_stereo_sw(codec, name, index, sw); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3225 | if (err < 0) |
| 3226 | return err; |
| 3227 | } |
| 3228 | } |
| 3229 | return 0; |
| 3230 | } |
| 3231 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3232 | static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin, |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3233 | hda_nid_t dac, const char *pfx) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3234 | { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3235 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3236 | hda_nid_t sw, vol; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3237 | int err; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3238 | |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3239 | if (!dac) { |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3240 | unsigned int val; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3241 | /* the corresponding DAC is already occupied */ |
| 3242 | if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)) |
| 3243 | return 0; /* no way */ |
| 3244 | /* create a switch only */ |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3245 | val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT); |
| 3246 | if (is_ctl_used(spec->sw_ctls, val)) |
| 3247 | return 0; /* already created */ |
| 3248 | mark_ctl_usage(spec->sw_ctls, val); |
| 3249 | return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3250 | } |
| 3251 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3252 | sw = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3253 | vol = alc_look_for_out_vol_nid(codec, pin, dac); |
| 3254 | err = alc_auto_add_stereo_vol(codec, pfx, 0, vol); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3255 | if (err < 0) |
Takashi Iwai | 24fb917 | 2008-09-02 14:48:20 +0200 | [diff] [blame] | 3256 | return err; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3257 | err = alc_auto_add_stereo_sw(codec, pfx, 0, sw); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3258 | if (err < 0) |
| 3259 | return err; |
Takashi Iwai | 3af9ee6 | 2011-06-27 12:34:01 +0200 | [diff] [blame] | 3260 | return 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3261 | } |
| 3262 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3263 | static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec, |
| 3264 | unsigned int nums, |
| 3265 | struct hda_ctl_ops *ops) |
| 3266 | { |
| 3267 | struct alc_spec *spec = codec->spec; |
| 3268 | struct hda_bind_ctls **ctlp, *ctl; |
| 3269 | snd_array_init(&spec->bind_ctls, sizeof(ctl), 8); |
| 3270 | ctlp = snd_array_new(&spec->bind_ctls); |
| 3271 | if (!ctlp) |
| 3272 | return NULL; |
| 3273 | ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL); |
| 3274 | *ctlp = ctl; |
| 3275 | if (ctl) |
| 3276 | ctl->ops = ops; |
| 3277 | return ctl; |
| 3278 | } |
| 3279 | |
| 3280 | /* add playback controls for speaker and HP outputs */ |
| 3281 | static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins, |
| 3282 | const hda_nid_t *pins, |
| 3283 | const hda_nid_t *dacs, |
| 3284 | const char *pfx) |
| 3285 | { |
| 3286 | struct alc_spec *spec = codec->spec; |
| 3287 | struct hda_bind_ctls *ctl; |
| 3288 | char name[32]; |
| 3289 | int i, n, err; |
| 3290 | |
| 3291 | if (!num_pins || !pins[0]) |
| 3292 | return 0; |
| 3293 | |
Takashi Iwai | 527e4d7 | 2011-10-27 16:33:27 +0200 | [diff] [blame] | 3294 | if (num_pins == 1) { |
| 3295 | hda_nid_t dac = *dacs; |
| 3296 | if (!dac) |
| 3297 | dac = spec->multiout.dac_nids[0]; |
| 3298 | return alc_auto_create_extra_out(codec, *pins, dac, pfx); |
| 3299 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3300 | |
| 3301 | if (dacs[num_pins - 1]) { |
| 3302 | /* OK, we have a multi-output system with individual volumes */ |
| 3303 | for (i = 0; i < num_pins; i++) { |
| 3304 | snprintf(name, sizeof(name), "%s %s", |
| 3305 | pfx, channel_name[i]); |
| 3306 | err = alc_auto_create_extra_out(codec, pins[i], dacs[i], |
| 3307 | name); |
| 3308 | if (err < 0) |
| 3309 | return err; |
| 3310 | } |
| 3311 | return 0; |
| 3312 | } |
| 3313 | |
| 3314 | /* Let's create a bind-controls */ |
| 3315 | ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw); |
| 3316 | if (!ctl) |
| 3317 | return -ENOMEM; |
| 3318 | n = 0; |
| 3319 | for (i = 0; i < num_pins; i++) { |
| 3320 | if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP) |
| 3321 | ctl->values[n++] = |
| 3322 | HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT); |
| 3323 | } |
| 3324 | if (n) { |
| 3325 | snprintf(name, sizeof(name), "%s Playback Switch", pfx); |
| 3326 | err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl); |
| 3327 | if (err < 0) |
| 3328 | return err; |
| 3329 | } |
| 3330 | |
| 3331 | ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol); |
| 3332 | if (!ctl) |
| 3333 | return -ENOMEM; |
| 3334 | n = 0; |
| 3335 | for (i = 0; i < num_pins; i++) { |
| 3336 | hda_nid_t vol; |
| 3337 | if (!pins[i] || !dacs[i]) |
| 3338 | continue; |
| 3339 | vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]); |
| 3340 | if (vol) |
| 3341 | ctl->values[n++] = |
| 3342 | HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT); |
| 3343 | } |
| 3344 | if (n) { |
| 3345 | snprintf(name, sizeof(name), "%s Playback Volume", pfx); |
| 3346 | err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl); |
| 3347 | if (err < 0) |
| 3348 | return err; |
| 3349 | } |
| 3350 | return 0; |
| 3351 | } |
| 3352 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3353 | static int alc_auto_create_hp_out(struct hda_codec *codec) |
| 3354 | { |
| 3355 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3356 | return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs, |
| 3357 | spec->autocfg.hp_pins, |
| 3358 | spec->multiout.hp_out_nid, |
| 3359 | "Headphone"); |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | static int alc_auto_create_speaker_out(struct hda_codec *codec) |
| 3363 | { |
| 3364 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3365 | return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs, |
| 3366 | spec->autocfg.speaker_pins, |
| 3367 | spec->multiout.extra_out_nid, |
| 3368 | "Speaker"); |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3369 | } |
| 3370 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3371 | static void alc_auto_set_output_and_unmute(struct hda_codec *codec, |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3372 | hda_nid_t pin, int pin_type, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3373 | hda_nid_t dac) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3374 | { |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3375 | int i, num; |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3376 | hda_nid_t nid, mix = 0; |
Takashi Iwai | ce503f3 | 2010-07-30 10:37:29 +0200 | [diff] [blame] | 3377 | hda_nid_t srcs[HDA_MAX_CONNECTIONS]; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3378 | |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3379 | alc_set_pin_output(codec, pin, pin_type); |
| 3380 | nid = alc_go_down_to_selector(codec, pin); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3381 | num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs)); |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3382 | for (i = 0; i < num; i++) { |
Takashi Iwai | 604401a | 2011-04-27 15:14:23 +0200 | [diff] [blame] | 3383 | if (alc_auto_mix_to_dac(codec, srcs[i]) != dac) |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3384 | continue; |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3385 | mix = srcs[i]; |
| 3386 | break; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3387 | } |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3388 | if (!mix) |
| 3389 | return; |
| 3390 | |
| 3391 | /* need the manual connection? */ |
| 3392 | if (num > 1) |
| 3393 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i); |
| 3394 | /* unmute mixer widget inputs */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3395 | if (nid_has_mute(codec, mix, HDA_INPUT)) { |
| 3396 | 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] | 3397 | AMP_IN_UNMUTE(0)); |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3398 | 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] | 3399 | AMP_IN_UNMUTE(1)); |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3400 | } |
Takashi Iwai | cd51155 | 2011-07-06 13:10:42 +0200 | [diff] [blame] | 3401 | /* initialize volume */ |
Takashi Iwai | afcd551 | 2011-07-08 11:07:59 +0200 | [diff] [blame] | 3402 | nid = alc_look_for_out_vol_nid(codec, pin, dac); |
| 3403 | if (nid) |
| 3404 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 3405 | AMP_OUT_ZERO); |
Takashi Iwai | 43dea22 | 2011-11-06 11:25:34 +0100 | [diff] [blame] | 3406 | |
| 3407 | /* unmute DAC if it's not assigned to a mixer */ |
| 3408 | nid = alc_look_for_out_mute_nid(codec, pin, dac); |
| 3409 | if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT)) |
| 3410 | snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 3411 | AMP_OUT_ZERO); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3412 | } |
| 3413 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3414 | static void alc_auto_init_multi_out(struct hda_codec *codec) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3415 | { |
| 3416 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3417 | int pin_type = get_pin_type(spec->autocfg.line_out_type); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3418 | int i; |
| 3419 | |
| 3420 | for (i = 0; i <= HDA_SIDE; i++) { |
| 3421 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; |
| 3422 | if (nid) |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3423 | alc_auto_set_output_and_unmute(codec, nid, pin_type, |
Takashi Iwai | 7085ec1 | 2009-10-02 09:03:58 +0200 | [diff] [blame] | 3424 | spec->multiout.dac_nids[i]); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3425 | } |
| 3426 | } |
| 3427 | |
Takashi Iwai | 343a04b | 2011-07-06 14:28:39 +0200 | [diff] [blame] | 3428 | static void alc_auto_init_extra_out(struct hda_codec *codec) |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3429 | { |
| 3430 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3431 | int i; |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3432 | hda_nid_t pin, dac; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3433 | |
David Henningsson | 636030e | 2011-10-12 19:26:03 +0200 | [diff] [blame] | 3434 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3435 | if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT) |
| 3436 | break; |
Takashi Iwai | e23832a | 2011-08-23 18:16:56 +0200 | [diff] [blame] | 3437 | pin = spec->autocfg.hp_pins[i]; |
| 3438 | if (!pin) |
| 3439 | break; |
| 3440 | dac = spec->multiout.hp_out_nid[i]; |
| 3441 | if (!dac) { |
| 3442 | if (i > 0 && spec->multiout.hp_out_nid[0]) |
| 3443 | dac = spec->multiout.hp_out_nid[0]; |
| 3444 | else |
| 3445 | dac = spec->multiout.dac_nids[0]; |
| 3446 | } |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3447 | alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac); |
| 3448 | } |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3449 | for (i = 0; i < spec->autocfg.speaker_outs; i++) { |
Takashi Iwai | 716eef0 | 2011-10-21 15:07:42 +0200 | [diff] [blame] | 3450 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) |
| 3451 | break; |
Takashi Iwai | 8cd0775 | 2011-08-23 15:16:22 +0200 | [diff] [blame] | 3452 | pin = spec->autocfg.speaker_pins[i]; |
| 3453 | if (!pin) |
| 3454 | break; |
| 3455 | dac = spec->multiout.extra_out_nid[i]; |
| 3456 | if (!dac) { |
| 3457 | if (i > 0 && spec->multiout.extra_out_nid[0]) |
| 3458 | dac = spec->multiout.extra_out_nid[0]; |
| 3459 | else |
| 3460 | dac = spec->multiout.dac_nids[0]; |
| 3461 | } |
Takashi Iwai | 675c1aa | 2011-08-23 12:36:28 +0200 | [diff] [blame] | 3462 | alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac); |
| 3463 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 3464 | } |
| 3465 | |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3466 | /* |
| 3467 | * multi-io helper |
| 3468 | */ |
| 3469 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, |
| 3470 | unsigned int location) |
| 3471 | { |
| 3472 | struct alc_spec *spec = codec->spec; |
| 3473 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3474 | hda_nid_t prime_dac = spec->private_dac_nids[0]; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3475 | int type, i, num_pins = 0; |
| 3476 | |
| 3477 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { |
| 3478 | for (i = 0; i < cfg->num_inputs; i++) { |
| 3479 | hda_nid_t nid = cfg->inputs[i].pin; |
| 3480 | hda_nid_t dac; |
| 3481 | unsigned int defcfg, caps; |
| 3482 | if (cfg->inputs[i].type != type) |
| 3483 | continue; |
| 3484 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
| 3485 | if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX) |
| 3486 | continue; |
| 3487 | if (location && get_defcfg_location(defcfg) != location) |
| 3488 | continue; |
| 3489 | caps = snd_hda_query_pin_caps(codec, nid); |
| 3490 | if (!(caps & AC_PINCAP_OUT)) |
| 3491 | continue; |
| 3492 | dac = alc_auto_look_for_dac(codec, nid); |
| 3493 | if (!dac) |
| 3494 | continue; |
| 3495 | spec->multi_io[num_pins].pin = nid; |
| 3496 | spec->multi_io[num_pins].dac = dac; |
| 3497 | num_pins++; |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3498 | spec->private_dac_nids[spec->multiout.num_dacs++] = dac; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3499 | } |
| 3500 | } |
| 3501 | spec->multiout.num_dacs = 1; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3502 | if (num_pins < 2) { |
| 3503 | /* clear up again */ |
| 3504 | memset(spec->private_dac_nids, 0, |
| 3505 | sizeof(spec->private_dac_nids)); |
| 3506 | spec->private_dac_nids[0] = prime_dac; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3507 | return 0; |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3508 | } |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3509 | return num_pins; |
| 3510 | } |
| 3511 | |
| 3512 | static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol, |
| 3513 | struct snd_ctl_elem_info *uinfo) |
| 3514 | { |
| 3515 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3516 | struct alc_spec *spec = codec->spec; |
| 3517 | |
| 3518 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 3519 | uinfo->count = 1; |
| 3520 | uinfo->value.enumerated.items = spec->multi_ios + 1; |
| 3521 | if (uinfo->value.enumerated.item > spec->multi_ios) |
| 3522 | uinfo->value.enumerated.item = spec->multi_ios; |
| 3523 | sprintf(uinfo->value.enumerated.name, "%dch", |
| 3524 | (uinfo->value.enumerated.item + 1) * 2); |
| 3525 | return 0; |
| 3526 | } |
| 3527 | |
| 3528 | static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol, |
| 3529 | struct snd_ctl_elem_value *ucontrol) |
| 3530 | { |
| 3531 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3532 | struct alc_spec *spec = codec->spec; |
| 3533 | ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2; |
| 3534 | return 0; |
| 3535 | } |
| 3536 | |
| 3537 | static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output) |
| 3538 | { |
| 3539 | struct alc_spec *spec = codec->spec; |
| 3540 | hda_nid_t nid = spec->multi_io[idx].pin; |
| 3541 | |
| 3542 | if (!spec->multi_io[idx].ctl_in) |
| 3543 | spec->multi_io[idx].ctl_in = |
| 3544 | snd_hda_codec_read(codec, nid, 0, |
| 3545 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 3546 | if (output) { |
| 3547 | snd_hda_codec_update_cache(codec, nid, 0, |
| 3548 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 3549 | PIN_OUT); |
| 3550 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
| 3551 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
| 3552 | HDA_AMP_MUTE, 0); |
| 3553 | alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac); |
| 3554 | } else { |
| 3555 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
| 3556 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
| 3557 | HDA_AMP_MUTE, HDA_AMP_MUTE); |
| 3558 | snd_hda_codec_update_cache(codec, nid, 0, |
| 3559 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 3560 | spec->multi_io[idx].ctl_in); |
| 3561 | } |
| 3562 | return 0; |
| 3563 | } |
| 3564 | |
| 3565 | static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol, |
| 3566 | struct snd_ctl_elem_value *ucontrol) |
| 3567 | { |
| 3568 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3569 | struct alc_spec *spec = codec->spec; |
| 3570 | int i, ch; |
| 3571 | |
| 3572 | ch = ucontrol->value.enumerated.item[0]; |
| 3573 | if (ch < 0 || ch > spec->multi_ios) |
| 3574 | return -EINVAL; |
| 3575 | if (ch == (spec->ext_channel_count - 1) / 2) |
| 3576 | return 0; |
| 3577 | spec->ext_channel_count = (ch + 1) * 2; |
| 3578 | for (i = 0; i < spec->multi_ios; i++) |
| 3579 | alc_set_multi_io(codec, i, i < ch); |
| 3580 | spec->multiout.max_channels = spec->ext_channel_count; |
Takashi Iwai | 7b1655f | 2011-07-14 15:31:21 +0200 | [diff] [blame] | 3581 | if (spec->need_dac_fix && !spec->const_channel_count) |
| 3582 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3583 | return 1; |
| 3584 | } |
| 3585 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 3586 | static const struct snd_kcontrol_new alc_auto_channel_mode_enum = { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3587 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3588 | .name = "Channel Mode", |
| 3589 | .info = alc_auto_ch_mode_info, |
| 3590 | .get = alc_auto_ch_mode_get, |
| 3591 | .put = alc_auto_ch_mode_put, |
| 3592 | }; |
| 3593 | |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3594 | static int alc_auto_add_multi_channel_mode(struct hda_codec *codec) |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3595 | { |
| 3596 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3597 | |
Takashi Iwai | c267468 | 2011-08-24 17:57:44 +0200 | [diff] [blame] | 3598 | if (spec->multi_ios > 0) { |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3599 | struct snd_kcontrol_new *knew; |
| 3600 | |
| 3601 | knew = alc_kcontrol_new(spec); |
| 3602 | if (!knew) |
| 3603 | return -ENOMEM; |
| 3604 | *knew = alc_auto_channel_mode_enum; |
| 3605 | knew->name = kstrdup("Channel Mode", GFP_KERNEL); |
| 3606 | if (!knew->name) |
| 3607 | return -ENOMEM; |
Takashi Iwai | ce764ab | 2011-04-27 16:35:23 +0200 | [diff] [blame] | 3608 | } |
| 3609 | return 0; |
| 3610 | } |
| 3611 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3612 | /* filter out invalid adc_nids (and capsrc_nids) that don't give all |
| 3613 | * active input pins |
| 3614 | */ |
| 3615 | static void alc_remove_invalid_adc_nids(struct hda_codec *codec) |
| 3616 | { |
| 3617 | struct alc_spec *spec = codec->spec; |
| 3618 | const struct hda_input_mux *imux; |
| 3619 | hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)]; |
| 3620 | hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)]; |
| 3621 | int i, n, nums; |
| 3622 | |
| 3623 | imux = spec->input_mux; |
| 3624 | if (!imux) |
| 3625 | return; |
| 3626 | if (spec->dyn_adc_switch) |
| 3627 | return; |
| 3628 | |
| 3629 | nums = 0; |
| 3630 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 3631 | hda_nid_t cap = spec->private_capsrc_nids[n]; |
| 3632 | int num_conns = snd_hda_get_conn_list(codec, cap, NULL); |
| 3633 | for (i = 0; i < imux->num_items; i++) { |
| 3634 | hda_nid_t pin = spec->imux_pins[i]; |
| 3635 | if (pin) { |
| 3636 | if (get_connection_index(codec, cap, pin) < 0) |
| 3637 | break; |
| 3638 | } else if (num_conns <= imux->items[i].index) |
| 3639 | break; |
| 3640 | } |
| 3641 | if (i >= imux->num_items) { |
| 3642 | adc_nids[nums] = spec->private_adc_nids[n]; |
| 3643 | capsrc_nids[nums++] = cap; |
| 3644 | } |
| 3645 | } |
| 3646 | if (!nums) { |
| 3647 | /* check whether ADC-switch is possible */ |
| 3648 | if (!alc_check_dyn_adc_switch(codec)) { |
| 3649 | printk(KERN_WARNING "hda_codec: %s: no valid ADC found;" |
| 3650 | " using fallback 0x%x\n", |
| 3651 | codec->chip_name, spec->private_adc_nids[0]); |
| 3652 | spec->num_adc_nids = 1; |
| 3653 | spec->auto_mic = 0; |
| 3654 | return; |
| 3655 | } |
| 3656 | } else if (nums != spec->num_adc_nids) { |
| 3657 | memcpy(spec->private_adc_nids, adc_nids, |
| 3658 | nums * sizeof(hda_nid_t)); |
| 3659 | memcpy(spec->private_capsrc_nids, capsrc_nids, |
| 3660 | nums * sizeof(hda_nid_t)); |
| 3661 | spec->num_adc_nids = nums; |
| 3662 | } |
| 3663 | |
| 3664 | if (spec->auto_mic) |
| 3665 | alc_auto_mic_check_imux(codec); /* check auto-mic setups */ |
| 3666 | else if (spec->input_mux->num_items == 1) |
| 3667 | spec->num_adc_nids = 1; /* reduce to a single ADC */ |
| 3668 | } |
| 3669 | |
| 3670 | /* |
| 3671 | * initialize ADC paths |
| 3672 | */ |
| 3673 | static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx) |
| 3674 | { |
| 3675 | struct alc_spec *spec = codec->spec; |
| 3676 | hda_nid_t nid; |
| 3677 | |
| 3678 | nid = spec->adc_nids[adc_idx]; |
| 3679 | /* mute ADC */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3680 | if (nid_has_mute(codec, nid, HDA_INPUT)) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3681 | snd_hda_codec_write(codec, nid, 0, |
| 3682 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 3683 | AMP_IN_MUTE(0)); |
| 3684 | return; |
| 3685 | } |
| 3686 | if (!spec->capsrc_nids) |
| 3687 | return; |
| 3688 | nid = spec->capsrc_nids[adc_idx]; |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3689 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3690 | snd_hda_codec_write(codec, nid, 0, |
| 3691 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 3692 | AMP_OUT_MUTE); |
| 3693 | } |
| 3694 | |
| 3695 | static void alc_auto_init_input_src(struct hda_codec *codec) |
| 3696 | { |
| 3697 | struct alc_spec *spec = codec->spec; |
| 3698 | int c, nums; |
| 3699 | |
| 3700 | for (c = 0; c < spec->num_adc_nids; c++) |
| 3701 | alc_auto_init_adc(codec, c); |
| 3702 | if (spec->dyn_adc_switch) |
| 3703 | nums = 1; |
| 3704 | else |
| 3705 | nums = spec->num_adc_nids; |
| 3706 | for (c = 0; c < nums; c++) |
| 3707 | alc_mux_select(codec, 0, spec->cur_mux[c], true); |
| 3708 | } |
| 3709 | |
| 3710 | /* add mic boosts if needed */ |
| 3711 | static int alc_auto_add_mic_boost(struct hda_codec *codec) |
| 3712 | { |
| 3713 | struct alc_spec *spec = codec->spec; |
| 3714 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3715 | int i, err; |
| 3716 | int type_idx = 0; |
| 3717 | hda_nid_t nid; |
| 3718 | const char *prev_label = NULL; |
| 3719 | |
| 3720 | for (i = 0; i < cfg->num_inputs; i++) { |
| 3721 | if (cfg->inputs[i].type > AUTO_PIN_MIC) |
| 3722 | break; |
| 3723 | nid = cfg->inputs[i].pin; |
| 3724 | if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { |
| 3725 | const char *label; |
| 3726 | char boost_label[32]; |
| 3727 | |
| 3728 | label = hda_get_autocfg_input_label(codec, cfg, i); |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 3729 | if (spec->shared_mic_hp && !strcmp(label, "Misc")) |
| 3730 | label = "Headphone Mic"; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3731 | if (prev_label && !strcmp(label, prev_label)) |
| 3732 | type_idx++; |
| 3733 | else |
| 3734 | type_idx = 0; |
| 3735 | prev_label = label; |
| 3736 | |
| 3737 | snprintf(boost_label, sizeof(boost_label), |
| 3738 | "%s Boost Volume", label); |
| 3739 | err = add_control(spec, ALC_CTL_WIDGET_VOL, |
| 3740 | boost_label, type_idx, |
| 3741 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT)); |
| 3742 | if (err < 0) |
| 3743 | return err; |
| 3744 | } |
| 3745 | } |
| 3746 | return 0; |
| 3747 | } |
| 3748 | |
| 3749 | /* select or unmute the given capsrc route */ |
| 3750 | static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap, |
| 3751 | int idx) |
| 3752 | { |
| 3753 | if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) { |
| 3754 | snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx, |
| 3755 | HDA_AMP_MUTE, 0); |
| 3756 | } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) { |
| 3757 | snd_hda_codec_write_cache(codec, cap, 0, |
| 3758 | AC_VERB_SET_CONNECT_SEL, idx); |
| 3759 | } |
| 3760 | } |
| 3761 | |
| 3762 | /* set the default connection to that pin */ |
| 3763 | static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin) |
| 3764 | { |
| 3765 | struct alc_spec *spec = codec->spec; |
| 3766 | int i; |
| 3767 | |
| 3768 | if (!pin) |
| 3769 | return 0; |
| 3770 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 3771 | hda_nid_t cap = spec->capsrc_nids ? |
| 3772 | spec->capsrc_nids[i] : spec->adc_nids[i]; |
| 3773 | int idx; |
| 3774 | |
| 3775 | idx = get_connection_index(codec, cap, pin); |
| 3776 | if (idx < 0) |
| 3777 | continue; |
| 3778 | select_or_unmute_capsrc(codec, cap, idx); |
| 3779 | return i; /* return the found index */ |
| 3780 | } |
| 3781 | return -1; /* not found */ |
| 3782 | } |
| 3783 | |
| 3784 | /* initialize some special cases for input sources */ |
| 3785 | static void alc_init_special_input_src(struct hda_codec *codec) |
| 3786 | { |
| 3787 | struct alc_spec *spec = codec->spec; |
| 3788 | int i; |
| 3789 | |
| 3790 | for (i = 0; i < spec->autocfg.num_inputs; i++) |
| 3791 | init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin); |
| 3792 | } |
| 3793 | |
| 3794 | /* assign appropriate capture mixers */ |
| 3795 | static void set_capture_mixer(struct hda_codec *codec) |
| 3796 | { |
| 3797 | struct alc_spec *spec = codec->spec; |
| 3798 | static const struct snd_kcontrol_new *caps[2][3] = { |
| 3799 | { alc_capture_mixer_nosrc1, |
| 3800 | alc_capture_mixer_nosrc2, |
| 3801 | alc_capture_mixer_nosrc3 }, |
| 3802 | { alc_capture_mixer1, |
| 3803 | alc_capture_mixer2, |
| 3804 | alc_capture_mixer3 }, |
| 3805 | }; |
| 3806 | |
| 3807 | /* check whether either of ADC or MUX has a volume control */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3808 | if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3809 | if (!spec->capsrc_nids) |
| 3810 | return; /* no volume */ |
Takashi Iwai | 44c0240 | 2011-07-08 15:14:19 +0200 | [diff] [blame] | 3811 | if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT)) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3812 | return; /* no volume in capsrc, too */ |
| 3813 | spec->vol_in_capsrc = 1; |
| 3814 | } |
| 3815 | |
| 3816 | if (spec->num_adc_nids > 0) { |
| 3817 | int mux = 0; |
| 3818 | int num_adcs = 0; |
| 3819 | |
| 3820 | if (spec->input_mux && spec->input_mux->num_items > 1) |
| 3821 | mux = 1; |
| 3822 | if (spec->auto_mic) { |
| 3823 | num_adcs = 1; |
| 3824 | mux = 0; |
| 3825 | } else if (spec->dyn_adc_switch) |
| 3826 | num_adcs = 1; |
| 3827 | if (!num_adcs) { |
| 3828 | if (spec->num_adc_nids > 3) |
| 3829 | spec->num_adc_nids = 3; |
| 3830 | else if (!spec->num_adc_nids) |
| 3831 | return; |
| 3832 | num_adcs = spec->num_adc_nids; |
| 3833 | } |
| 3834 | spec->cap_mixer = caps[mux][num_adcs - 1]; |
| 3835 | } |
| 3836 | } |
| 3837 | |
| 3838 | /* |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 3839 | * standard auto-parser initializations |
| 3840 | */ |
| 3841 | static void alc_auto_init_std(struct hda_codec *codec) |
| 3842 | { |
| 3843 | struct alc_spec *spec = codec->spec; |
| 3844 | alc_auto_init_multi_out(codec); |
| 3845 | alc_auto_init_extra_out(codec); |
| 3846 | alc_auto_init_analog_input(codec); |
| 3847 | alc_auto_init_input_src(codec); |
| 3848 | alc_auto_init_digital(codec); |
| 3849 | if (spec->unsol_event) |
| 3850 | alc_inithook(codec); |
| 3851 | } |
| 3852 | |
| 3853 | /* |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3854 | * Digital-beep handlers |
| 3855 | */ |
| 3856 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
| 3857 | #define set_beep_amp(spec, nid, idx, dir) \ |
| 3858 | ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir)) |
| 3859 | |
| 3860 | static const struct snd_pci_quirk beep_white_list[] = { |
| 3861 | SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1), |
| 3862 | SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1), |
| 3863 | SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1), |
| 3864 | SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1), |
| 3865 | SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1), |
| 3866 | {} |
| 3867 | }; |
| 3868 | |
| 3869 | static inline int has_cdefine_beep(struct hda_codec *codec) |
| 3870 | { |
| 3871 | struct alc_spec *spec = codec->spec; |
| 3872 | const struct snd_pci_quirk *q; |
| 3873 | q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list); |
| 3874 | if (q) |
| 3875 | return q->value; |
| 3876 | return spec->cdefine.enable_pcbeep; |
| 3877 | } |
| 3878 | #else |
| 3879 | #define set_beep_amp(spec, nid, idx, dir) /* NOP */ |
| 3880 | #define has_cdefine_beep(codec) 0 |
| 3881 | #endif |
| 3882 | |
| 3883 | /* parse the BIOS configuration and set up the alc_spec */ |
| 3884 | /* return 1 if successful, 0 if the proper config is not found, |
| 3885 | * or a negative error code |
| 3886 | */ |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3887 | static int alc_parse_auto_config(struct hda_codec *codec, |
| 3888 | const hda_nid_t *ignore_nids, |
| 3889 | const hda_nid_t *ssid_nids) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3890 | { |
| 3891 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3892 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3893 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3894 | |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 3895 | err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids, |
| 3896 | spec->parse_flags); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3897 | if (err < 0) |
| 3898 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3899 | if (!cfg->line_outs) { |
| 3900 | if (cfg->dig_outs || cfg->dig_in_pin) { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3901 | spec->multiout.max_channels = 2; |
| 3902 | spec->no_analog = 1; |
| 3903 | goto dig_only; |
| 3904 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3905 | return 0; /* can't find valid BIOS pin config */ |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3906 | } |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3907 | |
Takashi Iwai | 0650367 | 2011-10-06 08:27:19 +0200 | [diff] [blame] | 3908 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && |
| 3909 | cfg->line_outs <= cfg->hp_outs) { |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3910 | /* use HP as primary out */ |
| 3911 | cfg->speaker_outs = cfg->line_outs; |
| 3912 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 3913 | sizeof(cfg->speaker_pins)); |
| 3914 | cfg->line_outs = cfg->hp_outs; |
| 3915 | memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins)); |
| 3916 | cfg->hp_outs = 0; |
| 3917 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); |
| 3918 | cfg->line_out_type = AUTO_PIN_HP_OUT; |
| 3919 | } |
| 3920 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3921 | err = alc_auto_fill_dac_nids(codec); |
| 3922 | if (err < 0) |
| 3923 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3924 | err = alc_auto_add_multi_channel_mode(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3925 | if (err < 0) |
| 3926 | return err; |
Takashi Iwai | 23c09b0 | 2011-08-19 09:05:35 +0200 | [diff] [blame] | 3927 | err = alc_auto_create_multi_out_ctls(codec, cfg); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3928 | if (err < 0) |
| 3929 | return err; |
| 3930 | err = alc_auto_create_hp_out(codec); |
| 3931 | if (err < 0) |
| 3932 | return err; |
| 3933 | err = alc_auto_create_speaker_out(codec); |
| 3934 | if (err < 0) |
| 3935 | return err; |
Takashi Iwai | 24de183 | 2011-11-07 17:13:39 +0100 | [diff] [blame] | 3936 | err = alc_auto_create_shared_input(codec); |
| 3937 | if (err < 0) |
| 3938 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3939 | err = alc_auto_create_input_ctls(codec); |
| 3940 | if (err < 0) |
| 3941 | return err; |
| 3942 | |
| 3943 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3944 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3945 | dig_only: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3946 | alc_auto_parse_digital(codec); |
| 3947 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3948 | if (!spec->no_analog) |
| 3949 | alc_remove_invalid_adc_nids(codec); |
| 3950 | |
| 3951 | if (ssid_nids) |
| 3952 | alc_ssid_check(codec, ssid_nids); |
| 3953 | |
| 3954 | if (!spec->no_analog) { |
| 3955 | alc_auto_check_switches(codec); |
| 3956 | err = alc_auto_add_mic_boost(codec); |
| 3957 | if (err < 0) |
| 3958 | return err; |
| 3959 | } |
| 3960 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3961 | if (spec->kctls.list) |
| 3962 | add_mixer(spec, spec->kctls.list); |
| 3963 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3964 | return 1; |
| 3965 | } |
| 3966 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 3967 | static int alc880_parse_auto_config(struct hda_codec *codec) |
| 3968 | { |
| 3969 | static const hda_nid_t alc880_ignore[] = { 0x1d, 0 }; |
| 3970 | static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 3971 | return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids); |
| 3972 | } |
| 3973 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 3974 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3975 | static const struct hda_amp_list alc880_loopbacks[] = { |
| 3976 | { 0x0b, HDA_INPUT, 0 }, |
| 3977 | { 0x0b, HDA_INPUT, 1 }, |
| 3978 | { 0x0b, HDA_INPUT, 2 }, |
| 3979 | { 0x0b, HDA_INPUT, 3 }, |
| 3980 | { 0x0b, HDA_INPUT, 4 }, |
| 3981 | { } /* end */ |
| 3982 | }; |
| 3983 | #endif |
| 3984 | |
| 3985 | /* |
| 3986 | * board setups |
| 3987 | */ |
| 3988 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 3989 | #define alc_board_config \ |
| 3990 | snd_hda_check_board_config |
| 3991 | #define alc_board_codec_sid_config \ |
| 3992 | snd_hda_check_board_codec_sid_config |
| 3993 | #include "alc_quirks.c" |
| 3994 | #else |
| 3995 | #define alc_board_config(codec, nums, models, tbl) -1 |
| 3996 | #define alc_board_codec_sid_config(codec, nums, models, tbl) -1 |
| 3997 | #define setup_preset(codec, x) /* NOP */ |
| 3998 | #endif |
| 3999 | |
| 4000 | /* |
| 4001 | * OK, here we have finally the patch for ALC880 |
| 4002 | */ |
| 4003 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4004 | #include "alc880_quirks.c" |
| 4005 | #endif |
| 4006 | |
| 4007 | static int patch_alc880(struct hda_codec *codec) |
| 4008 | { |
| 4009 | struct alc_spec *spec; |
| 4010 | int board_config; |
| 4011 | int err; |
| 4012 | |
| 4013 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4014 | if (spec == NULL) |
| 4015 | return -ENOMEM; |
| 4016 | |
| 4017 | codec->spec = spec; |
| 4018 | |
| 4019 | spec->mixer_nid = 0x0b; |
Takashi Iwai | 7b1655f | 2011-07-14 15:31:21 +0200 | [diff] [blame] | 4020 | spec->need_dac_fix = 1; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4021 | |
| 4022 | board_config = alc_board_config(codec, ALC880_MODEL_LAST, |
| 4023 | alc880_models, alc880_cfg_tbl); |
| 4024 | if (board_config < 0) { |
| 4025 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 4026 | codec->chip_name); |
| 4027 | board_config = ALC_MODEL_AUTO; |
| 4028 | } |
| 4029 | |
| 4030 | if (board_config == ALC_MODEL_AUTO) { |
| 4031 | /* automatic parse from the BIOS config */ |
| 4032 | err = alc880_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4033 | if (err < 0) |
| 4034 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4035 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4036 | else if (!err) { |
| 4037 | printk(KERN_INFO |
| 4038 | "hda_codec: Cannot set up configuration " |
| 4039 | "from BIOS. Using 3-stack mode...\n"); |
| 4040 | board_config = ALC880_3ST; |
| 4041 | } |
| 4042 | #endif |
| 4043 | } |
| 4044 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4045 | if (board_config != ALC_MODEL_AUTO) |
| 4046 | setup_preset(codec, &alc880_presets[board_config]); |
| 4047 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4048 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4049 | alc_auto_fill_adc_caps(codec); |
| 4050 | alc_rebuild_imux_for_auto_mic(codec); |
| 4051 | alc_remove_invalid_adc_nids(codec); |
| 4052 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4053 | |
| 4054 | if (!spec->no_analog && !spec->cap_mixer) |
| 4055 | set_capture_mixer(codec); |
| 4056 | |
| 4057 | if (!spec->no_analog) { |
| 4058 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4059 | if (err < 0) |
| 4060 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4061 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 4062 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4063 | |
| 4064 | spec->vmaster_nid = 0x0c; |
| 4065 | |
| 4066 | codec->patch_ops = alc_patch_ops; |
| 4067 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 4068 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4069 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4070 | if (!spec->loopback.amplist) |
| 4071 | spec->loopback.amplist = alc880_loopbacks; |
| 4072 | #endif |
| 4073 | |
| 4074 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4075 | |
| 4076 | error: |
| 4077 | alc_free(codec); |
| 4078 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | |
| 4082 | /* |
| 4083 | * ALC260 support |
| 4084 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4085 | static int alc260_parse_auto_config(struct hda_codec *codec) |
| 4086 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4087 | static const hda_nid_t alc260_ignore[] = { 0x17, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4088 | static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 }; |
| 4089 | return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4090 | } |
| 4091 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4092 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4093 | static const struct hda_amp_list alc260_loopbacks[] = { |
| 4094 | { 0x07, HDA_INPUT, 0 }, |
| 4095 | { 0x07, HDA_INPUT, 1 }, |
| 4096 | { 0x07, HDA_INPUT, 2 }, |
| 4097 | { 0x07, HDA_INPUT, 3 }, |
| 4098 | { 0x07, HDA_INPUT, 4 }, |
| 4099 | { } /* end */ |
| 4100 | }; |
| 4101 | #endif |
| 4102 | |
| 4103 | /* |
| 4104 | * Pin config fixes |
| 4105 | */ |
| 4106 | enum { |
| 4107 | PINFIX_HP_DC5750, |
| 4108 | }; |
| 4109 | |
| 4110 | static const struct alc_fixup alc260_fixups[] = { |
| 4111 | [PINFIX_HP_DC5750] = { |
| 4112 | .type = ALC_FIXUP_PINS, |
| 4113 | .v.pins = (const struct alc_pincfg[]) { |
| 4114 | { 0x11, 0x90130110 }, /* speaker */ |
| 4115 | { } |
| 4116 | } |
| 4117 | }, |
| 4118 | }; |
| 4119 | |
| 4120 | static const struct snd_pci_quirk alc260_fixup_tbl[] = { |
| 4121 | SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750), |
| 4122 | {} |
| 4123 | }; |
| 4124 | |
| 4125 | /* |
| 4126 | */ |
| 4127 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4128 | #include "alc260_quirks.c" |
| 4129 | #endif |
| 4130 | |
| 4131 | static int patch_alc260(struct hda_codec *codec) |
| 4132 | { |
| 4133 | struct alc_spec *spec; |
| 4134 | int err, board_config; |
| 4135 | |
| 4136 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4137 | if (spec == NULL) |
| 4138 | return -ENOMEM; |
| 4139 | |
| 4140 | codec->spec = spec; |
| 4141 | |
| 4142 | spec->mixer_nid = 0x07; |
| 4143 | |
| 4144 | board_config = alc_board_config(codec, ALC260_MODEL_LAST, |
| 4145 | alc260_models, alc260_cfg_tbl); |
| 4146 | if (board_config < 0) { |
| 4147 | snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 4148 | codec->chip_name); |
| 4149 | board_config = ALC_MODEL_AUTO; |
| 4150 | } |
| 4151 | |
| 4152 | if (board_config == ALC_MODEL_AUTO) { |
| 4153 | alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); |
| 4154 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 4155 | } |
| 4156 | |
| 4157 | if (board_config == ALC_MODEL_AUTO) { |
| 4158 | /* automatic parse from the BIOS config */ |
| 4159 | err = alc260_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4160 | if (err < 0) |
| 4161 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4162 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4163 | else if (!err) { |
| 4164 | printk(KERN_INFO |
| 4165 | "hda_codec: Cannot set up configuration " |
| 4166 | "from BIOS. Using base mode...\n"); |
| 4167 | board_config = ALC260_BASIC; |
| 4168 | } |
| 4169 | #endif |
| 4170 | } |
| 4171 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4172 | if (board_config != ALC_MODEL_AUTO) |
| 4173 | setup_preset(codec, &alc260_presets[board_config]); |
| 4174 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4175 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4176 | alc_auto_fill_adc_caps(codec); |
| 4177 | alc_rebuild_imux_for_auto_mic(codec); |
| 4178 | alc_remove_invalid_adc_nids(codec); |
| 4179 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4180 | |
| 4181 | if (!spec->no_analog && !spec->cap_mixer) |
| 4182 | set_capture_mixer(codec); |
| 4183 | |
| 4184 | if (!spec->no_analog) { |
| 4185 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4186 | if (err < 0) |
| 4187 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4188 | set_beep_amp(spec, 0x07, 0x05, HDA_INPUT); |
| 4189 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4190 | |
| 4191 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4192 | |
| 4193 | spec->vmaster_nid = 0x08; |
| 4194 | |
| 4195 | codec->patch_ops = alc_patch_ops; |
| 4196 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | 8452a98 | 2011-07-08 16:19:48 +0200 | [diff] [blame] | 4197 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4198 | spec->shutup = alc_eapd_shutup; |
| 4199 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4200 | if (!spec->loopback.amplist) |
| 4201 | spec->loopback.amplist = alc260_loopbacks; |
| 4202 | #endif |
| 4203 | |
| 4204 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4205 | |
| 4206 | error: |
| 4207 | alc_free(codec); |
| 4208 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4209 | } |
| 4210 | |
| 4211 | |
| 4212 | /* |
| 4213 | * ALC882/883/885/888/889 support |
| 4214 | * |
| 4215 | * ALC882 is almost identical with ALC880 but has cleaner and more flexible |
| 4216 | * configuration. Each pin widget can choose any input DACs and a mixer. |
| 4217 | * Each ADC is connected from a mixer of all inputs. This makes possible |
| 4218 | * 6-channel independent captures. |
| 4219 | * |
| 4220 | * In addition, an independent DAC for the multi-playback (not used in this |
| 4221 | * driver yet). |
| 4222 | */ |
| 4223 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4224 | #define alc882_loopbacks alc880_loopbacks |
| 4225 | #endif |
| 4226 | |
| 4227 | /* |
| 4228 | * Pin config fixes |
| 4229 | */ |
| 4230 | enum { |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4231 | ALC882_FIXUP_ABIT_AW9D_MAX, |
| 4232 | ALC882_FIXUP_LENOVO_Y530, |
| 4233 | ALC882_FIXUP_PB_M5210, |
| 4234 | ALC882_FIXUP_ACER_ASPIRE_7736, |
| 4235 | ALC882_FIXUP_ASUS_W90V, |
| 4236 | ALC889_FIXUP_VAIO_TT, |
Takashi Iwai | 0e7cc2e | 2011-11-09 12:42:48 +0100 | [diff] [blame] | 4237 | ALC888_FIXUP_EEE1601, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4238 | }; |
| 4239 | |
| 4240 | static const struct alc_fixup alc882_fixups[] = { |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4241 | [ALC882_FIXUP_ABIT_AW9D_MAX] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4242 | .type = ALC_FIXUP_PINS, |
| 4243 | .v.pins = (const struct alc_pincfg[]) { |
| 4244 | { 0x15, 0x01080104 }, /* side */ |
| 4245 | { 0x16, 0x01011012 }, /* rear */ |
| 4246 | { 0x17, 0x01016011 }, /* clfe */ |
| 4247 | { } |
| 4248 | } |
| 4249 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4250 | [ALC882_FIXUP_LENOVO_Y530] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4251 | .type = ALC_FIXUP_PINS, |
| 4252 | .v.pins = (const struct alc_pincfg[]) { |
| 4253 | { 0x15, 0x99130112 }, /* rear int speakers */ |
| 4254 | { 0x16, 0x99130111 }, /* subwoofer */ |
| 4255 | { } |
| 4256 | } |
| 4257 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4258 | [ALC882_FIXUP_PB_M5210] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4259 | .type = ALC_FIXUP_VERBS, |
| 4260 | .v.verbs = (const struct hda_verb[]) { |
| 4261 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, |
| 4262 | {} |
| 4263 | } |
| 4264 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4265 | [ALC882_FIXUP_ACER_ASPIRE_7736] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4266 | .type = ALC_FIXUP_SKU, |
| 4267 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
| 4268 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4269 | [ALC882_FIXUP_ASUS_W90V] = { |
Takashi Iwai | 5cdf745 | 2011-10-26 23:04:08 +0200 | [diff] [blame] | 4270 | .type = ALC_FIXUP_PINS, |
| 4271 | .v.pins = (const struct alc_pincfg[]) { |
| 4272 | { 0x16, 0x99130110 }, /* fix sequence for CLFE */ |
| 4273 | { } |
| 4274 | } |
| 4275 | }, |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4276 | [ALC889_FIXUP_VAIO_TT] = { |
| 4277 | .type = ALC_FIXUP_PINS, |
| 4278 | .v.pins = (const struct alc_pincfg[]) { |
| 4279 | { 0x17, 0x90170111 }, /* hidden surround speaker */ |
| 4280 | { } |
| 4281 | } |
| 4282 | }, |
Takashi Iwai | 0e7cc2e | 2011-11-09 12:42:48 +0100 | [diff] [blame] | 4283 | [ALC888_FIXUP_EEE1601] = { |
| 4284 | .type = ALC_FIXUP_VERBS, |
| 4285 | .v.verbs = (const struct hda_verb[]) { |
| 4286 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b }, |
| 4287 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 }, |
| 4288 | { } |
| 4289 | } |
| 4290 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4291 | }; |
| 4292 | |
| 4293 | static const struct snd_pci_quirk alc882_fixup_tbl[] = { |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4294 | SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210), |
| 4295 | SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V), |
Takashi Iwai | 0e7cc2e | 2011-11-09 12:42:48 +0100 | [diff] [blame] | 4296 | SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601), |
Takashi Iwai | 5c0ebfb | 2011-11-07 17:59:13 +0100 | [diff] [blame] | 4297 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530), |
| 4298 | SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX), |
| 4299 | SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736), |
| 4300 | SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4301 | {} |
| 4302 | }; |
| 4303 | |
| 4304 | /* |
| 4305 | * BIOS auto configuration |
| 4306 | */ |
| 4307 | /* almost identical with ALC880 parser... */ |
| 4308 | static int alc882_parse_auto_config(struct hda_codec *codec) |
| 4309 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4310 | static const hda_nid_t alc882_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4311 | static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 4312 | return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4313 | } |
| 4314 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4315 | /* |
| 4316 | */ |
| 4317 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4318 | #include "alc882_quirks.c" |
| 4319 | #endif |
| 4320 | |
| 4321 | static int patch_alc882(struct hda_codec *codec) |
| 4322 | { |
| 4323 | struct alc_spec *spec; |
| 4324 | int err, board_config; |
| 4325 | |
| 4326 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4327 | if (spec == NULL) |
| 4328 | return -ENOMEM; |
| 4329 | |
| 4330 | codec->spec = spec; |
| 4331 | |
| 4332 | spec->mixer_nid = 0x0b; |
| 4333 | |
| 4334 | switch (codec->vendor_id) { |
| 4335 | case 0x10ec0882: |
| 4336 | case 0x10ec0885: |
| 4337 | break; |
| 4338 | default: |
| 4339 | /* ALC883 and variants */ |
| 4340 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); |
| 4341 | break; |
| 4342 | } |
| 4343 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4344 | err = alc_codec_rename_from_preset(codec); |
| 4345 | if (err < 0) |
| 4346 | goto error; |
| 4347 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4348 | board_config = alc_board_config(codec, ALC882_MODEL_LAST, |
| 4349 | alc882_models, alc882_cfg_tbl); |
| 4350 | |
| 4351 | if (board_config < 0) |
| 4352 | board_config = alc_board_codec_sid_config(codec, |
| 4353 | ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl); |
| 4354 | |
| 4355 | if (board_config < 0) { |
| 4356 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 4357 | codec->chip_name); |
| 4358 | board_config = ALC_MODEL_AUTO; |
| 4359 | } |
| 4360 | |
| 4361 | if (board_config == ALC_MODEL_AUTO) { |
| 4362 | alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups); |
| 4363 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 4364 | } |
| 4365 | |
| 4366 | alc_auto_parse_customize_define(codec); |
| 4367 | |
| 4368 | if (board_config == ALC_MODEL_AUTO) { |
| 4369 | /* automatic parse from the BIOS config */ |
| 4370 | err = alc882_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4371 | if (err < 0) |
| 4372 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4373 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
| 4374 | else if (!err) { |
| 4375 | printk(KERN_INFO |
| 4376 | "hda_codec: Cannot set up configuration " |
| 4377 | "from BIOS. Using base mode...\n"); |
| 4378 | board_config = ALC882_3ST_DIG; |
| 4379 | } |
| 4380 | #endif |
| 4381 | } |
| 4382 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4383 | if (board_config != ALC_MODEL_AUTO) |
| 4384 | setup_preset(codec, &alc882_presets[board_config]); |
| 4385 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4386 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4387 | alc_auto_fill_adc_caps(codec); |
| 4388 | alc_rebuild_imux_for_auto_mic(codec); |
| 4389 | alc_remove_invalid_adc_nids(codec); |
| 4390 | } |
| 4391 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4392 | if (!spec->no_analog && !spec->cap_mixer) |
| 4393 | set_capture_mixer(codec); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4394 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4395 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 4396 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4397 | if (err < 0) |
| 4398 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4399 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4400 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4401 | |
| 4402 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4403 | |
| 4404 | spec->vmaster_nid = 0x0c; |
| 4405 | |
| 4406 | codec->patch_ops = alc_patch_ops; |
| 4407 | if (board_config == ALC_MODEL_AUTO) |
Takashi Iwai | e477062 | 2011-07-08 11:11:35 +0200 | [diff] [blame] | 4408 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4409 | |
| 4410 | alc_init_jacks(codec); |
| 4411 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4412 | if (!spec->loopback.amplist) |
| 4413 | spec->loopback.amplist = alc882_loopbacks; |
| 4414 | #endif |
| 4415 | |
| 4416 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4417 | |
| 4418 | error: |
| 4419 | alc_free(codec); |
| 4420 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | |
| 4424 | /* |
| 4425 | * ALC262 support |
| 4426 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4427 | static int alc262_parse_auto_config(struct hda_codec *codec) |
| 4428 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4429 | static const hda_nid_t alc262_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4430 | static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 4431 | return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4432 | } |
| 4433 | |
| 4434 | /* |
| 4435 | * Pin config fixes |
| 4436 | */ |
| 4437 | enum { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4438 | ALC262_FIXUP_FSC_H270, |
| 4439 | ALC262_FIXUP_HP_Z200, |
| 4440 | ALC262_FIXUP_TYAN, |
Takashi Iwai | 12837c9 | 2011-11-07 12:45:24 +0100 | [diff] [blame] | 4441 | ALC262_FIXUP_TOSHIBA_RX1, |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 4442 | ALC262_FIXUP_LENOVO_3000, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 4443 | ALC262_FIXUP_BENQ, |
| 4444 | ALC262_FIXUP_BENQ_T31, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4445 | }; |
| 4446 | |
| 4447 | static const struct alc_fixup alc262_fixups[] = { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4448 | [ALC262_FIXUP_FSC_H270] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4449 | .type = ALC_FIXUP_PINS, |
| 4450 | .v.pins = (const struct alc_pincfg[]) { |
| 4451 | { 0x14, 0x99130110 }, /* speaker */ |
| 4452 | { 0x15, 0x0221142f }, /* front HP */ |
| 4453 | { 0x1b, 0x0121141f }, /* rear HP */ |
| 4454 | { } |
| 4455 | } |
| 4456 | }, |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4457 | [ALC262_FIXUP_HP_Z200] = { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4458 | .type = ALC_FIXUP_PINS, |
| 4459 | .v.pins = (const struct alc_pincfg[]) { |
| 4460 | { 0x16, 0x99130120 }, /* internal speaker */ |
| 4461 | { } |
| 4462 | } |
| 4463 | }, |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4464 | [ALC262_FIXUP_TYAN] = { |
| 4465 | .type = ALC_FIXUP_PINS, |
| 4466 | .v.pins = (const struct alc_pincfg[]) { |
| 4467 | { 0x14, 0x1993e1f0 }, /* int AUX */ |
| 4468 | { } |
| 4469 | } |
| 4470 | }, |
Takashi Iwai | 12837c9 | 2011-11-07 12:45:24 +0100 | [diff] [blame] | 4471 | [ALC262_FIXUP_TOSHIBA_RX1] = { |
| 4472 | .type = ALC_FIXUP_PINS, |
| 4473 | .v.pins = (const struct alc_pincfg[]) { |
| 4474 | { 0x14, 0x90170110 }, /* speaker */ |
| 4475 | { 0x15, 0x0421101f }, /* HP */ |
| 4476 | { 0x1a, 0x40f000f0 }, /* N/A */ |
| 4477 | { 0x1b, 0x40f000f0 }, /* N/A */ |
| 4478 | { 0x1e, 0x40f000f0 }, /* N/A */ |
| 4479 | } |
| 4480 | }, |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 4481 | [ALC262_FIXUP_LENOVO_3000] = { |
| 4482 | .type = ALC_FIXUP_VERBS, |
| 4483 | .v.verbs = (const struct hda_verb[]) { |
| 4484 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 4485 | {} |
| 4486 | }, |
| 4487 | .chained = true, |
| 4488 | .chain_id = ALC262_FIXUP_BENQ, |
| 4489 | }, |
| 4490 | [ALC262_FIXUP_BENQ] = { |
| 4491 | .type = ALC_FIXUP_VERBS, |
| 4492 | .v.verbs = (const struct hda_verb[]) { |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 4493 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4494 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, |
| 4495 | {} |
| 4496 | } |
| 4497 | }, |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 4498 | [ALC262_FIXUP_BENQ_T31] = { |
| 4499 | .type = ALC_FIXUP_VERBS, |
| 4500 | .v.verbs = (const struct hda_verb[]) { |
| 4501 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
| 4502 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, |
| 4503 | {} |
| 4504 | } |
| 4505 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4506 | }; |
| 4507 | |
| 4508 | static const struct snd_pci_quirk alc262_fixup_tbl[] = { |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4509 | SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200), |
Takashi Iwai | 3dcd3be | 2011-11-07 14:59:40 +0100 | [diff] [blame] | 4510 | SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ), |
| 4511 | SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ), |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4512 | SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN), |
Takashi Iwai | 12837c9 | 2011-11-07 12:45:24 +0100 | [diff] [blame] | 4513 | SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1", |
| 4514 | ALC262_FIXUP_TOSHIBA_RX1), |
Takashi Iwai | ea4e7af | 2011-11-07 12:23:55 +0100 | [diff] [blame] | 4515 | SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270), |
Takashi Iwai | c470150 | 2011-11-07 14:20:07 +0100 | [diff] [blame] | 4516 | SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000), |
Takashi Iwai | b42590b | 2011-11-07 14:41:01 +0100 | [diff] [blame] | 4517 | SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ), |
| 4518 | SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4519 | {} |
| 4520 | }; |
| 4521 | |
| 4522 | |
| 4523 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4524 | #define alc262_loopbacks alc880_loopbacks |
| 4525 | #endif |
| 4526 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4527 | /* |
| 4528 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4529 | static int patch_alc262(struct hda_codec *codec) |
| 4530 | { |
| 4531 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4532 | int err; |
| 4533 | |
| 4534 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4535 | if (spec == NULL) |
| 4536 | return -ENOMEM; |
| 4537 | |
| 4538 | codec->spec = spec; |
| 4539 | |
| 4540 | spec->mixer_nid = 0x0b; |
| 4541 | |
| 4542 | #if 0 |
| 4543 | /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is |
| 4544 | * under-run |
| 4545 | */ |
| 4546 | { |
| 4547 | int tmp; |
| 4548 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 4549 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); |
| 4550 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); |
| 4551 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80); |
| 4552 | } |
| 4553 | #endif |
| 4554 | alc_auto_parse_customize_define(codec); |
| 4555 | |
| 4556 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); |
| 4557 | |
Takashi Iwai | 42399f7 | 2011-11-07 17:18:44 +0100 | [diff] [blame] | 4558 | alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups); |
| 4559 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4560 | |
Takashi Iwai | 42399f7 | 2011-11-07 17:18:44 +0100 | [diff] [blame] | 4561 | /* automatic parse from the BIOS config */ |
| 4562 | err = alc262_parse_auto_config(codec); |
| 4563 | if (err < 0) |
| 4564 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4565 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4566 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4567 | alc_auto_fill_adc_caps(codec); |
| 4568 | alc_rebuild_imux_for_auto_mic(codec); |
| 4569 | alc_remove_invalid_adc_nids(codec); |
| 4570 | } |
| 4571 | |
| 4572 | if (!spec->no_analog && !spec->cap_mixer) |
| 4573 | set_capture_mixer(codec); |
| 4574 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4575 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 4576 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4577 | if (err < 0) |
| 4578 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4579 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4580 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4581 | |
| 4582 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 4583 | |
| 4584 | spec->vmaster_nid = 0x0c; |
| 4585 | |
| 4586 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 42399f7 | 2011-11-07 17:18:44 +0100 | [diff] [blame] | 4587 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4588 | spec->shutup = alc_eapd_shutup; |
| 4589 | |
| 4590 | alc_init_jacks(codec); |
| 4591 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4592 | if (!spec->loopback.amplist) |
| 4593 | spec->loopback.amplist = alc262_loopbacks; |
| 4594 | #endif |
| 4595 | |
| 4596 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4597 | |
| 4598 | error: |
| 4599 | alc_free(codec); |
| 4600 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | /* |
| 4604 | * ALC268 |
| 4605 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4606 | /* bind Beep switches of both NID 0x0f and 0x10 */ |
| 4607 | static const struct hda_bind_ctls alc268_bind_beep_sw = { |
| 4608 | .ops = &snd_hda_bind_sw, |
| 4609 | .values = { |
| 4610 | HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT), |
| 4611 | HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT), |
| 4612 | 0 |
| 4613 | }, |
| 4614 | }; |
| 4615 | |
| 4616 | static const struct snd_kcontrol_new alc268_beep_mixer[] = { |
| 4617 | HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT), |
| 4618 | HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw), |
| 4619 | { } |
| 4620 | }; |
| 4621 | |
| 4622 | /* set PCBEEP vol = 0, mute connections */ |
| 4623 | static const struct hda_verb alc268_beep_init_verbs[] = { |
| 4624 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4625 | {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4626 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4627 | { } |
| 4628 | }; |
| 4629 | |
| 4630 | /* |
| 4631 | * BIOS auto configuration |
| 4632 | */ |
| 4633 | static int alc268_parse_auto_config(struct hda_codec *codec) |
| 4634 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4635 | static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4636 | struct alc_spec *spec = codec->spec; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4637 | int err = alc_parse_auto_config(codec, NULL, alc268_ssids); |
| 4638 | if (err > 0) { |
| 4639 | if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { |
| 4640 | add_mixer(spec, alc268_beep_mixer); |
| 4641 | add_verb(spec, alc268_beep_init_verbs); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4642 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4643 | } |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4644 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4645 | } |
| 4646 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4647 | /* |
| 4648 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4649 | static int patch_alc268(struct hda_codec *codec) |
| 4650 | { |
| 4651 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4652 | int i, has_beep, err; |
| 4653 | |
| 4654 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4655 | if (spec == NULL) |
| 4656 | return -ENOMEM; |
| 4657 | |
| 4658 | codec->spec = spec; |
| 4659 | |
| 4660 | /* ALC268 has no aa-loopback mixer */ |
| 4661 | |
Takashi Iwai | 6ebb805 | 2011-08-16 15:15:40 +0200 | [diff] [blame] | 4662 | /* automatic parse from the BIOS config */ |
| 4663 | err = alc268_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4664 | if (err < 0) |
| 4665 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4666 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4667 | has_beep = 0; |
| 4668 | for (i = 0; i < spec->num_mixers; i++) { |
| 4669 | if (spec->mixers[i] == alc268_beep_mixer) { |
| 4670 | has_beep = 1; |
| 4671 | break; |
| 4672 | } |
| 4673 | } |
| 4674 | |
| 4675 | if (has_beep) { |
| 4676 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4677 | if (err < 0) |
| 4678 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4679 | if (!query_amp_caps(codec, 0x1d, HDA_INPUT)) |
| 4680 | /* override the amp caps for beep generator */ |
| 4681 | snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT, |
| 4682 | (0x0c << AC_AMPCAP_OFFSET_SHIFT) | |
| 4683 | (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 4684 | (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 4685 | (0 << AC_AMPCAP_MUTE_SHIFT)); |
| 4686 | } |
| 4687 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 4688 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4689 | alc_auto_fill_adc_caps(codec); |
| 4690 | alc_rebuild_imux_for_auto_mic(codec); |
| 4691 | alc_remove_invalid_adc_nids(codec); |
| 4692 | } |
| 4693 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4694 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4695 | set_capture_mixer(codec); |
| 4696 | |
| 4697 | spec->vmaster_nid = 0x02; |
| 4698 | |
| 4699 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 6ebb805 | 2011-08-16 15:15:40 +0200 | [diff] [blame] | 4700 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4701 | spec->shutup = alc_eapd_shutup; |
| 4702 | |
| 4703 | alc_init_jacks(codec); |
| 4704 | |
| 4705 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 4706 | |
| 4707 | error: |
| 4708 | alc_free(codec); |
| 4709 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4710 | } |
| 4711 | |
| 4712 | /* |
| 4713 | * ALC269 |
| 4714 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4715 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4716 | #define alc269_loopbacks alc880_loopbacks |
| 4717 | #endif |
| 4718 | |
| 4719 | static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { |
| 4720 | .substreams = 1, |
| 4721 | .channels_min = 2, |
| 4722 | .channels_max = 8, |
| 4723 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
| 4724 | /* NID is set in alc_build_pcms */ |
| 4725 | .ops = { |
| 4726 | .open = alc_playback_pcm_open, |
| 4727 | .prepare = alc_playback_pcm_prepare, |
| 4728 | .cleanup = alc_playback_pcm_cleanup |
| 4729 | }, |
| 4730 | }; |
| 4731 | |
| 4732 | static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { |
| 4733 | .substreams = 1, |
| 4734 | .channels_min = 2, |
| 4735 | .channels_max = 2, |
| 4736 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
| 4737 | /* NID is set in alc_build_pcms */ |
| 4738 | }; |
| 4739 | |
| 4740 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4741 | static int alc269_mic2_for_mute_led(struct hda_codec *codec) |
| 4742 | { |
| 4743 | switch (codec->subsystem_id) { |
| 4744 | case 0x103c1586: |
| 4745 | return 1; |
| 4746 | } |
| 4747 | return 0; |
| 4748 | } |
| 4749 | |
| 4750 | static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid) |
| 4751 | { |
| 4752 | /* update mute-LED according to the speaker mute state */ |
| 4753 | if (nid == 0x01 || nid == 0x14) { |
| 4754 | int pinval; |
| 4755 | if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) & |
| 4756 | HDA_AMP_MUTE) |
| 4757 | pinval = 0x24; |
| 4758 | else |
| 4759 | pinval = 0x20; |
| 4760 | /* mic2 vref pin is used for mute LED control */ |
| 4761 | snd_hda_codec_update_cache(codec, 0x19, 0, |
| 4762 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 4763 | pinval); |
| 4764 | } |
| 4765 | return alc_check_power_status(codec, nid); |
| 4766 | } |
| 4767 | #endif /* CONFIG_SND_HDA_POWER_SAVE */ |
| 4768 | |
| 4769 | /* different alc269-variants */ |
| 4770 | enum { |
| 4771 | ALC269_TYPE_ALC269VA, |
| 4772 | ALC269_TYPE_ALC269VB, |
| 4773 | ALC269_TYPE_ALC269VC, |
| 4774 | }; |
| 4775 | |
| 4776 | /* |
| 4777 | * BIOS auto configuration |
| 4778 | */ |
| 4779 | static int alc269_parse_auto_config(struct hda_codec *codec) |
| 4780 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4781 | static const hda_nid_t alc269_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4782 | static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 }; |
| 4783 | static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 4784 | struct alc_spec *spec = codec->spec; |
| 4785 | const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ? |
| 4786 | alc269va_ssids : alc269_ssids; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4787 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 4788 | return alc_parse_auto_config(codec, alc269_ignore, ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4789 | } |
| 4790 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4791 | static void alc269_toggle_power_output(struct hda_codec *codec, int power_up) |
| 4792 | { |
| 4793 | int val = alc_read_coef_idx(codec, 0x04); |
| 4794 | if (power_up) |
| 4795 | val |= 1 << 11; |
| 4796 | else |
| 4797 | val &= ~(1 << 11); |
| 4798 | alc_write_coef_idx(codec, 0x04, val); |
| 4799 | } |
| 4800 | |
| 4801 | static void alc269_shutup(struct hda_codec *codec) |
| 4802 | { |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 4803 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4804 | alc269_toggle_power_output(codec, 0); |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 4805 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4806 | alc269_toggle_power_output(codec, 0); |
| 4807 | msleep(150); |
| 4808 | } |
| 4809 | } |
| 4810 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 4811 | #ifdef CONFIG_PM |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4812 | static int alc269_resume(struct hda_codec *codec) |
| 4813 | { |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 4814 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4815 | alc269_toggle_power_output(codec, 0); |
| 4816 | msleep(150); |
| 4817 | } |
| 4818 | |
| 4819 | codec->patch_ops.init(codec); |
| 4820 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 4821 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4822 | alc269_toggle_power_output(codec, 1); |
| 4823 | msleep(200); |
| 4824 | } |
| 4825 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 4826 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4827 | alc269_toggle_power_output(codec, 1); |
| 4828 | |
| 4829 | snd_hda_codec_resume_amp(codec); |
| 4830 | snd_hda_codec_resume_cache(codec); |
| 4831 | hda_call_check_power_status(codec, 0x01); |
| 4832 | return 0; |
| 4833 | } |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 4834 | #endif /* CONFIG_PM */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4835 | |
| 4836 | static void alc269_fixup_hweq(struct hda_codec *codec, |
| 4837 | const struct alc_fixup *fix, int action) |
| 4838 | { |
| 4839 | int coef; |
| 4840 | |
| 4841 | if (action != ALC_FIXUP_ACT_INIT) |
| 4842 | return; |
| 4843 | coef = alc_read_coef_idx(codec, 0x1e); |
| 4844 | alc_write_coef_idx(codec, 0x1e, coef | 0x80); |
| 4845 | } |
| 4846 | |
| 4847 | static void alc271_fixup_dmic(struct hda_codec *codec, |
| 4848 | const struct alc_fixup *fix, int action) |
| 4849 | { |
| 4850 | static const struct hda_verb verbs[] = { |
| 4851 | {0x20, AC_VERB_SET_COEF_INDEX, 0x0d}, |
| 4852 | {0x20, AC_VERB_SET_PROC_COEF, 0x4000}, |
| 4853 | {} |
| 4854 | }; |
| 4855 | unsigned int cfg; |
| 4856 | |
| 4857 | if (strcmp(codec->chip_name, "ALC271X")) |
| 4858 | return; |
| 4859 | cfg = snd_hda_codec_get_pincfg(codec, 0x12); |
| 4860 | if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED) |
| 4861 | snd_hda_sequence_write(codec, verbs); |
| 4862 | } |
| 4863 | |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 4864 | static void alc269_fixup_pcm_44k(struct hda_codec *codec, |
| 4865 | const struct alc_fixup *fix, int action) |
| 4866 | { |
| 4867 | struct alc_spec *spec = codec->spec; |
| 4868 | |
| 4869 | if (action != ALC_FIXUP_ACT_PROBE) |
| 4870 | return; |
| 4871 | |
| 4872 | /* Due to a hardware problem on Lenovo Ideadpad, we need to |
| 4873 | * fix the sample rate of analog I/O to 44.1kHz |
| 4874 | */ |
| 4875 | spec->stream_analog_playback = &alc269_44k_pcm_analog_playback; |
| 4876 | spec->stream_analog_capture = &alc269_44k_pcm_analog_capture; |
| 4877 | } |
| 4878 | |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 4879 | static void alc269_fixup_stereo_dmic(struct hda_codec *codec, |
| 4880 | const struct alc_fixup *fix, int action) |
| 4881 | { |
| 4882 | int coef; |
| 4883 | |
| 4884 | if (action != ALC_FIXUP_ACT_INIT) |
| 4885 | return; |
| 4886 | /* The digital-mic unit sends PDM (differential signal) instead of |
| 4887 | * the standard PCM, thus you can't record a valid mono stream as is. |
| 4888 | * Below is a workaround specific to ALC269 to control the dmic |
| 4889 | * signal source as mono. |
| 4890 | */ |
| 4891 | coef = alc_read_coef_idx(codec, 0x07); |
| 4892 | alc_write_coef_idx(codec, 0x07, coef | 0x80); |
| 4893 | } |
| 4894 | |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 4895 | static void alc269_quanta_automute(struct hda_codec *codec) |
| 4896 | { |
David Henningsson | 42cf0d0 | 2011-09-20 12:04:56 +0200 | [diff] [blame] | 4897 | update_outputs(codec); |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 4898 | |
| 4899 | snd_hda_codec_write(codec, 0x20, 0, |
| 4900 | AC_VERB_SET_COEF_INDEX, 0x0c); |
| 4901 | snd_hda_codec_write(codec, 0x20, 0, |
| 4902 | AC_VERB_SET_PROC_COEF, 0x680); |
| 4903 | |
| 4904 | snd_hda_codec_write(codec, 0x20, 0, |
| 4905 | AC_VERB_SET_COEF_INDEX, 0x0c); |
| 4906 | snd_hda_codec_write(codec, 0x20, 0, |
| 4907 | AC_VERB_SET_PROC_COEF, 0x480); |
| 4908 | } |
| 4909 | |
| 4910 | static void alc269_fixup_quanta_mute(struct hda_codec *codec, |
| 4911 | const struct alc_fixup *fix, int action) |
| 4912 | { |
| 4913 | struct alc_spec *spec = codec->spec; |
| 4914 | if (action != ALC_FIXUP_ACT_PROBE) |
| 4915 | return; |
| 4916 | spec->automute_hook = alc269_quanta_automute; |
| 4917 | } |
| 4918 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4919 | enum { |
| 4920 | ALC269_FIXUP_SONY_VAIO, |
| 4921 | ALC275_FIXUP_SONY_VAIO_GPIO2, |
| 4922 | ALC269_FIXUP_DELL_M101Z, |
| 4923 | ALC269_FIXUP_SKU_IGNORE, |
| 4924 | ALC269_FIXUP_ASUS_G73JW, |
| 4925 | ALC269_FIXUP_LENOVO_EAPD, |
| 4926 | ALC275_FIXUP_SONY_HWEQ, |
| 4927 | ALC271_FIXUP_DMIC, |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 4928 | ALC269_FIXUP_PCM_44K, |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 4929 | ALC269_FIXUP_STEREO_DMIC, |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 4930 | ALC269_FIXUP_QUANTA_MUTE, |
| 4931 | ALC269_FIXUP_LIFEBOOK, |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 4932 | ALC269_FIXUP_AMIC, |
| 4933 | ALC269_FIXUP_DMIC, |
| 4934 | ALC269VB_FIXUP_AMIC, |
| 4935 | ALC269VB_FIXUP_DMIC, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 4936 | }; |
| 4937 | |
| 4938 | static const struct alc_fixup alc269_fixups[] = { |
| 4939 | [ALC269_FIXUP_SONY_VAIO] = { |
| 4940 | .type = ALC_FIXUP_VERBS, |
| 4941 | .v.verbs = (const struct hda_verb[]) { |
| 4942 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD}, |
| 4943 | {} |
| 4944 | } |
| 4945 | }, |
| 4946 | [ALC275_FIXUP_SONY_VAIO_GPIO2] = { |
| 4947 | .type = ALC_FIXUP_VERBS, |
| 4948 | .v.verbs = (const struct hda_verb[]) { |
| 4949 | {0x01, AC_VERB_SET_GPIO_MASK, 0x04}, |
| 4950 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04}, |
| 4951 | {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, |
| 4952 | { } |
| 4953 | }, |
| 4954 | .chained = true, |
| 4955 | .chain_id = ALC269_FIXUP_SONY_VAIO |
| 4956 | }, |
| 4957 | [ALC269_FIXUP_DELL_M101Z] = { |
| 4958 | .type = ALC_FIXUP_VERBS, |
| 4959 | .v.verbs = (const struct hda_verb[]) { |
| 4960 | /* Enables internal speaker */ |
| 4961 | {0x20, AC_VERB_SET_COEF_INDEX, 13}, |
| 4962 | {0x20, AC_VERB_SET_PROC_COEF, 0x4040}, |
| 4963 | {} |
| 4964 | } |
| 4965 | }, |
| 4966 | [ALC269_FIXUP_SKU_IGNORE] = { |
| 4967 | .type = ALC_FIXUP_SKU, |
| 4968 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
| 4969 | }, |
| 4970 | [ALC269_FIXUP_ASUS_G73JW] = { |
| 4971 | .type = ALC_FIXUP_PINS, |
| 4972 | .v.pins = (const struct alc_pincfg[]) { |
| 4973 | { 0x17, 0x99130111 }, /* subwoofer */ |
| 4974 | { } |
| 4975 | } |
| 4976 | }, |
| 4977 | [ALC269_FIXUP_LENOVO_EAPD] = { |
| 4978 | .type = ALC_FIXUP_VERBS, |
| 4979 | .v.verbs = (const struct hda_verb[]) { |
| 4980 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, |
| 4981 | {} |
| 4982 | } |
| 4983 | }, |
| 4984 | [ALC275_FIXUP_SONY_HWEQ] = { |
| 4985 | .type = ALC_FIXUP_FUNC, |
| 4986 | .v.func = alc269_fixup_hweq, |
| 4987 | .chained = true, |
| 4988 | .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2 |
| 4989 | }, |
| 4990 | [ALC271_FIXUP_DMIC] = { |
| 4991 | .type = ALC_FIXUP_FUNC, |
| 4992 | .v.func = alc271_fixup_dmic, |
| 4993 | }, |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 4994 | [ALC269_FIXUP_PCM_44K] = { |
| 4995 | .type = ALC_FIXUP_FUNC, |
| 4996 | .v.func = alc269_fixup_pcm_44k, |
| 4997 | }, |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 4998 | [ALC269_FIXUP_STEREO_DMIC] = { |
| 4999 | .type = ALC_FIXUP_FUNC, |
| 5000 | .v.func = alc269_fixup_stereo_dmic, |
| 5001 | }, |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5002 | [ALC269_FIXUP_QUANTA_MUTE] = { |
| 5003 | .type = ALC_FIXUP_FUNC, |
| 5004 | .v.func = alc269_fixup_quanta_mute, |
| 5005 | }, |
| 5006 | [ALC269_FIXUP_LIFEBOOK] = { |
| 5007 | .type = ALC_FIXUP_PINS, |
| 5008 | .v.pins = (const struct alc_pincfg[]) { |
| 5009 | { 0x1a, 0x2101103f }, /* dock line-out */ |
| 5010 | { 0x1b, 0x23a11040 }, /* dock mic-in */ |
| 5011 | { } |
| 5012 | }, |
| 5013 | .chained = true, |
| 5014 | .chain_id = ALC269_FIXUP_QUANTA_MUTE |
| 5015 | }, |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5016 | [ALC269_FIXUP_AMIC] = { |
| 5017 | .type = ALC_FIXUP_PINS, |
| 5018 | .v.pins = (const struct alc_pincfg[]) { |
| 5019 | { 0x14, 0x99130110 }, /* speaker */ |
| 5020 | { 0x15, 0x0121401f }, /* HP out */ |
| 5021 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5022 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 5023 | { } |
| 5024 | }, |
| 5025 | }, |
| 5026 | [ALC269_FIXUP_DMIC] = { |
| 5027 | .type = ALC_FIXUP_PINS, |
| 5028 | .v.pins = (const struct alc_pincfg[]) { |
| 5029 | { 0x12, 0x99a3092f }, /* int-mic */ |
| 5030 | { 0x14, 0x99130110 }, /* speaker */ |
| 5031 | { 0x15, 0x0121401f }, /* HP out */ |
| 5032 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5033 | { } |
| 5034 | }, |
| 5035 | }, |
| 5036 | [ALC269VB_FIXUP_AMIC] = { |
| 5037 | .type = ALC_FIXUP_PINS, |
| 5038 | .v.pins = (const struct alc_pincfg[]) { |
| 5039 | { 0x14, 0x99130110 }, /* speaker */ |
| 5040 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5041 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 5042 | { 0x21, 0x0121401f }, /* HP out */ |
| 5043 | { } |
| 5044 | }, |
| 5045 | }, |
| 5046 | [ALC269_FIXUP_DMIC] = { |
| 5047 | .type = ALC_FIXUP_PINS, |
| 5048 | .v.pins = (const struct alc_pincfg[]) { |
| 5049 | { 0x12, 0x99a3092f }, /* int-mic */ |
| 5050 | { 0x14, 0x99130110 }, /* speaker */ |
| 5051 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5052 | { 0x21, 0x0121401f }, /* HP out */ |
| 5053 | { } |
| 5054 | }, |
| 5055 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5056 | }; |
| 5057 | |
| 5058 | static const struct snd_pci_quirk alc269_fixup_tbl[] = { |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 5059 | SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW), |
Takashi Iwai | adabb3e | 2011-08-03 07:48:37 +0200 | [diff] [blame] | 5060 | SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC), |
| 5061 | SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC), |
| 5062 | SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC), |
| 5063 | SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), |
| 5064 | SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5065 | SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2), |
| 5066 | SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), |
| 5067 | SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), |
| 5068 | SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO), |
| 5069 | SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z), |
| 5070 | SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC), |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5071 | SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5072 | SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE), |
| 5073 | SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE), |
| 5074 | SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE), |
| 5075 | SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE), |
| 5076 | SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE), |
Takashi Iwai | 2451991 | 2011-08-16 15:08:49 +0200 | [diff] [blame] | 5077 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE), |
Takashi Iwai | 017f2a1 | 2011-07-09 14:42:25 +0200 | [diff] [blame] | 5078 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5079 | SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD), |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5080 | |
| 5081 | #if 1 |
| 5082 | /* Below is a quirk table taken from the old code. |
| 5083 | * Basically the device should work as is without the fixup table. |
| 5084 | * If BIOS doesn't give a proper info, enable the corresponding |
| 5085 | * fixup entry. |
| 5086 | */ |
| 5087 | SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A", |
| 5088 | ALC269_FIXUP_AMIC), |
| 5089 | SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC), |
| 5090 | SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC), |
| 5091 | SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC), |
| 5092 | SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC), |
| 5093 | SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC), |
| 5094 | SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC), |
| 5095 | SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC), |
| 5096 | SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC), |
| 5097 | SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC), |
| 5098 | SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC), |
| 5099 | SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC), |
| 5100 | SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC), |
| 5101 | SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC), |
| 5102 | SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC), |
| 5103 | SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC), |
| 5104 | SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC), |
| 5105 | SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC), |
| 5106 | SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC), |
| 5107 | SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC), |
| 5108 | SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC), |
| 5109 | SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC), |
| 5110 | SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC), |
| 5111 | SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC), |
| 5112 | SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC), |
| 5113 | SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC), |
| 5114 | SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC), |
| 5115 | SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC), |
| 5116 | SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC), |
| 5117 | SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC), |
| 5118 | SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC), |
| 5119 | SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC), |
| 5120 | SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC), |
| 5121 | SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC), |
| 5122 | SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC), |
| 5123 | SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC), |
| 5124 | SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC), |
| 5125 | SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC), |
| 5126 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC), |
| 5127 | SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC), |
| 5128 | SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC), |
| 5129 | #endif |
| 5130 | {} |
| 5131 | }; |
| 5132 | |
| 5133 | static const struct alc_model_fixup alc269_fixup_models[] = { |
| 5134 | {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"}, |
| 5135 | {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"}, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5136 | {} |
| 5137 | }; |
| 5138 | |
| 5139 | |
| 5140 | static int alc269_fill_coef(struct hda_codec *codec) |
| 5141 | { |
| 5142 | int val; |
| 5143 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5144 | if ((alc_get_coef0(codec) & 0x00ff) < 0x015) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5145 | alc_write_coef_idx(codec, 0xf, 0x960b); |
| 5146 | alc_write_coef_idx(codec, 0xe, 0x8817); |
| 5147 | } |
| 5148 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5149 | if ((alc_get_coef0(codec) & 0x00ff) == 0x016) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5150 | alc_write_coef_idx(codec, 0xf, 0x960b); |
| 5151 | alc_write_coef_idx(codec, 0xe, 0x8814); |
| 5152 | } |
| 5153 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5154 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5155 | val = alc_read_coef_idx(codec, 0x04); |
| 5156 | /* Power up output pin */ |
| 5157 | alc_write_coef_idx(codec, 0x04, val | (1<<11)); |
| 5158 | } |
| 5159 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5160 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5161 | val = alc_read_coef_idx(codec, 0xd); |
| 5162 | if ((val & 0x0c00) >> 10 != 0x1) { |
| 5163 | /* Capless ramp up clock control */ |
| 5164 | alc_write_coef_idx(codec, 0xd, val | (1<<10)); |
| 5165 | } |
| 5166 | val = alc_read_coef_idx(codec, 0x17); |
| 5167 | if ((val & 0x01c0) >> 6 != 0x4) { |
| 5168 | /* Class D power on reset */ |
| 5169 | alc_write_coef_idx(codec, 0x17, val | (1<<7)); |
| 5170 | } |
| 5171 | } |
| 5172 | |
| 5173 | val = alc_read_coef_idx(codec, 0xd); /* Class D */ |
| 5174 | alc_write_coef_idx(codec, 0xd, val | (1<<14)); |
| 5175 | |
| 5176 | val = alc_read_coef_idx(codec, 0x4); /* HP */ |
| 5177 | alc_write_coef_idx(codec, 0x4, val | (1<<11)); |
| 5178 | |
| 5179 | return 0; |
| 5180 | } |
| 5181 | |
| 5182 | /* |
| 5183 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5184 | static int patch_alc269(struct hda_codec *codec) |
| 5185 | { |
| 5186 | struct alc_spec *spec; |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5187 | int err = 0; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5188 | |
| 5189 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5190 | if (spec == NULL) |
| 5191 | return -ENOMEM; |
| 5192 | |
| 5193 | codec->spec = spec; |
| 5194 | |
| 5195 | spec->mixer_nid = 0x0b; |
| 5196 | |
| 5197 | alc_auto_parse_customize_define(codec); |
| 5198 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5199 | err = alc_codec_rename_from_preset(codec); |
| 5200 | if (err < 0) |
| 5201 | goto error; |
| 5202 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5203 | if (codec->vendor_id == 0x10ec0269) { |
| 5204 | spec->codec_variant = ALC269_TYPE_ALC269VA; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5205 | switch (alc_get_coef0(codec) & 0x00f0) { |
| 5206 | case 0x0010: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5207 | if (codec->bus->pci->subsystem_vendor == 0x1025 && |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5208 | spec->cdefine.platform_type == 1) |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5209 | err = alc_codec_rename(codec, "ALC271X"); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5210 | spec->codec_variant = ALC269_TYPE_ALC269VB; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5211 | break; |
| 5212 | case 0x0020: |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5213 | if (codec->bus->pci->subsystem_vendor == 0x17aa && |
| 5214 | codec->bus->pci->subsystem_device == 0x21f3) |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5215 | err = alc_codec_rename(codec, "ALC3202"); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5216 | spec->codec_variant = ALC269_TYPE_ALC269VC; |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5217 | break; |
| 5218 | default: |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5219 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5220 | } |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5221 | if (err < 0) |
| 5222 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5223 | alc269_fill_coef(codec); |
| 5224 | } |
| 5225 | |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5226 | alc_pick_fixup(codec, alc269_fixup_models, |
| 5227 | alc269_fixup_tbl, alc269_fixups); |
| 5228 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5229 | |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5230 | /* automatic parse from the BIOS config */ |
| 5231 | err = alc269_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5232 | if (err < 0) |
| 5233 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5234 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5235 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5236 | alc_auto_fill_adc_caps(codec); |
| 5237 | alc_rebuild_imux_for_auto_mic(codec); |
| 5238 | alc_remove_invalid_adc_nids(codec); |
| 5239 | } |
| 5240 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5241 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5242 | set_capture_mixer(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5243 | |
| 5244 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 5245 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5246 | if (err < 0) |
| 5247 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5248 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5249 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5250 | |
| 5251 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5252 | |
| 5253 | spec->vmaster_nid = 0x02; |
| 5254 | |
| 5255 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 5256 | #ifdef CONFIG_PM |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5257 | codec->patch_ops.resume = alc269_resume; |
| 5258 | #endif |
Takashi Iwai | a4297b5 | 2011-08-23 18:40:12 +0200 | [diff] [blame] | 5259 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5260 | spec->shutup = alc269_shutup; |
| 5261 | |
| 5262 | alc_init_jacks(codec); |
| 5263 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5264 | if (!spec->loopback.amplist) |
| 5265 | spec->loopback.amplist = alc269_loopbacks; |
| 5266 | if (alc269_mic2_for_mute_led(codec)) |
| 5267 | codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps; |
| 5268 | #endif |
| 5269 | |
| 5270 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5271 | |
| 5272 | error: |
| 5273 | alc_free(codec); |
| 5274 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5275 | } |
| 5276 | |
| 5277 | /* |
| 5278 | * ALC861 |
| 5279 | */ |
| 5280 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5281 | static int alc861_parse_auto_config(struct hda_codec *codec) |
| 5282 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5283 | static const hda_nid_t alc861_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5284 | static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 }; |
| 5285 | return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5286 | } |
| 5287 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5288 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5289 | static const struct hda_amp_list alc861_loopbacks[] = { |
| 5290 | { 0x15, HDA_INPUT, 0 }, |
| 5291 | { 0x15, HDA_INPUT, 1 }, |
| 5292 | { 0x15, HDA_INPUT, 2 }, |
| 5293 | { 0x15, HDA_INPUT, 3 }, |
| 5294 | { } /* end */ |
| 5295 | }; |
| 5296 | #endif |
| 5297 | |
| 5298 | |
| 5299 | /* Pin config fixes */ |
| 5300 | enum { |
| 5301 | PINFIX_FSC_AMILO_PI1505, |
| 5302 | }; |
| 5303 | |
| 5304 | static const struct alc_fixup alc861_fixups[] = { |
| 5305 | [PINFIX_FSC_AMILO_PI1505] = { |
| 5306 | .type = ALC_FIXUP_PINS, |
| 5307 | .v.pins = (const struct alc_pincfg[]) { |
| 5308 | { 0x0b, 0x0221101f }, /* HP */ |
| 5309 | { 0x0f, 0x90170310 }, /* speaker */ |
| 5310 | { } |
| 5311 | } |
| 5312 | }, |
| 5313 | }; |
| 5314 | |
| 5315 | static const struct snd_pci_quirk alc861_fixup_tbl[] = { |
| 5316 | SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505), |
| 5317 | {} |
| 5318 | }; |
| 5319 | |
| 5320 | /* |
| 5321 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5322 | static int patch_alc861(struct hda_codec *codec) |
| 5323 | { |
| 5324 | struct alc_spec *spec; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5325 | int err; |
| 5326 | |
| 5327 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5328 | if (spec == NULL) |
| 5329 | return -ENOMEM; |
| 5330 | |
| 5331 | codec->spec = spec; |
| 5332 | |
| 5333 | spec->mixer_nid = 0x15; |
| 5334 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5335 | alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); |
| 5336 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5337 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5338 | /* automatic parse from the BIOS config */ |
| 5339 | err = alc861_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5340 | if (err < 0) |
| 5341 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5342 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5343 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5344 | alc_auto_fill_adc_caps(codec); |
| 5345 | alc_rebuild_imux_for_auto_mic(codec); |
| 5346 | alc_remove_invalid_adc_nids(codec); |
| 5347 | } |
| 5348 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5349 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5350 | set_capture_mixer(codec); |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5351 | |
| 5352 | if (!spec->no_analog) { |
| 5353 | err = snd_hda_attach_beep_device(codec, 0x23); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5354 | if (err < 0) |
| 5355 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5356 | set_beep_amp(spec, 0x23, 0, HDA_OUTPUT); |
| 5357 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5358 | |
| 5359 | spec->vmaster_nid = 0x03; |
| 5360 | |
| 5361 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5362 | |
| 5363 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5364 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5365 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5366 | spec->power_hook = alc_power_eapd; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5367 | if (!spec->loopback.amplist) |
| 5368 | spec->loopback.amplist = alc861_loopbacks; |
| 5369 | #endif |
| 5370 | |
| 5371 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5372 | |
| 5373 | error: |
| 5374 | alc_free(codec); |
| 5375 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5376 | } |
| 5377 | |
| 5378 | /* |
| 5379 | * ALC861-VD support |
| 5380 | * |
| 5381 | * Based on ALC882 |
| 5382 | * |
| 5383 | * In addition, an independent DAC |
| 5384 | */ |
| 5385 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5386 | #define alc861vd_loopbacks alc880_loopbacks |
| 5387 | #endif |
| 5388 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5389 | static int alc861vd_parse_auto_config(struct hda_codec *codec) |
| 5390 | { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5391 | static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5392 | static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5393 | return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5394 | } |
| 5395 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5396 | enum { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5397 | ALC660VD_FIX_ASUS_GPIO1, |
| 5398 | ALC861VD_FIX_DALLAS, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5399 | }; |
| 5400 | |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5401 | /* exclude VREF80 */ |
| 5402 | static void alc861vd_fixup_dallas(struct hda_codec *codec, |
| 5403 | const struct alc_fixup *fix, int action) |
| 5404 | { |
| 5405 | if (action == ALC_FIXUP_ACT_PRE_PROBE) { |
| 5406 | snd_hda_override_pin_caps(codec, 0x18, 0x00001714); |
| 5407 | snd_hda_override_pin_caps(codec, 0x19, 0x0000171c); |
| 5408 | } |
| 5409 | } |
| 5410 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5411 | static const struct alc_fixup alc861vd_fixups[] = { |
| 5412 | [ALC660VD_FIX_ASUS_GPIO1] = { |
| 5413 | .type = ALC_FIXUP_VERBS, |
| 5414 | .v.verbs = (const struct hda_verb[]) { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5415 | /* reset GPIO1 */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5416 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, |
| 5417 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, |
| 5418 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, |
| 5419 | { } |
| 5420 | } |
| 5421 | }, |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5422 | [ALC861VD_FIX_DALLAS] = { |
| 5423 | .type = ALC_FIXUP_FUNC, |
| 5424 | .v.func = alc861vd_fixup_dallas, |
| 5425 | }, |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5426 | }; |
| 5427 | |
| 5428 | static const struct snd_pci_quirk alc861vd_fixup_tbl[] = { |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5429 | SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5430 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1), |
Takashi Iwai | 8fdcb6f | 2011-08-23 17:28:55 +0200 | [diff] [blame] | 5431 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS), |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5432 | {} |
| 5433 | }; |
| 5434 | |
| 5435 | static const struct hda_verb alc660vd_eapd_verbs[] = { |
| 5436 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2}, |
| 5437 | {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2}, |
| 5438 | { } |
| 5439 | }; |
| 5440 | |
| 5441 | /* |
| 5442 | */ |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5443 | static int patch_alc861vd(struct hda_codec *codec) |
| 5444 | { |
| 5445 | struct alc_spec *spec; |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5446 | int err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5447 | |
| 5448 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5449 | if (spec == NULL) |
| 5450 | return -ENOMEM; |
| 5451 | |
| 5452 | codec->spec = spec; |
| 5453 | |
| 5454 | spec->mixer_nid = 0x0b; |
| 5455 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5456 | alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); |
| 5457 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5458 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5459 | /* automatic parse from the BIOS config */ |
| 5460 | err = alc861vd_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5461 | if (err < 0) |
| 5462 | goto error; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5463 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5464 | if (codec->vendor_id == 0x10ec0660) { |
| 5465 | /* always turn on EAPD */ |
| 5466 | add_verb(spec, alc660vd_eapd_verbs); |
| 5467 | } |
| 5468 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5469 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5470 | alc_auto_fill_adc_caps(codec); |
| 5471 | alc_rebuild_imux_for_auto_mic(codec); |
| 5472 | alc_remove_invalid_adc_nids(codec); |
| 5473 | } |
| 5474 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5475 | if (!spec->no_analog && !spec->cap_mixer) |
| 5476 | set_capture_mixer(codec); |
| 5477 | |
| 5478 | if (!spec->no_analog) { |
| 5479 | err = snd_hda_attach_beep_device(codec, 0x23); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5480 | if (err < 0) |
| 5481 | goto error; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5482 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 5483 | } |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5484 | |
| 5485 | spec->vmaster_nid = 0x02; |
| 5486 | |
| 5487 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5488 | |
| 5489 | codec->patch_ops = alc_patch_ops; |
| 5490 | |
Takashi Iwai | cb4e482 | 2011-08-23 17:34:25 +0200 | [diff] [blame] | 5491 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5492 | spec->shutup = alc_eapd_shutup; |
| 5493 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5494 | if (!spec->loopback.amplist) |
| 5495 | spec->loopback.amplist = alc861vd_loopbacks; |
| 5496 | #endif |
| 5497 | |
| 5498 | return 0; |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5499 | |
| 5500 | error: |
| 5501 | alc_free(codec); |
| 5502 | return err; |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5503 | } |
| 5504 | |
| 5505 | /* |
| 5506 | * ALC662 support |
| 5507 | * |
| 5508 | * ALC662 is almost identical with ALC880 but has cleaner and more flexible |
| 5509 | * configuration. Each pin widget can choose any input DACs and a mixer. |
| 5510 | * Each ADC is connected from a mixer of all inputs. This makes possible |
| 5511 | * 6-channel independent captures. |
| 5512 | * |
| 5513 | * In addition, an independent DAC for the multi-playback (not used in this |
| 5514 | * driver yet). |
| 5515 | */ |
| 5516 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5517 | #define alc662_loopbacks alc880_loopbacks |
| 5518 | #endif |
| 5519 | |
| 5520 | /* |
| 5521 | * BIOS auto configuration |
| 5522 | */ |
| 5523 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5524 | static int alc662_parse_auto_config(struct hda_codec *codec) |
| 5525 | { |
Takashi Iwai | 4c6d72d | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 5526 | static const hda_nid_t alc662_ignore[] = { 0x1d, 0 }; |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5527 | static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 }; |
| 5528 | static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
| 5529 | const hda_nid_t *ssids; |
Takashi Iwai | ee979a14 | 2008-09-02 15:42:20 +0200 | [diff] [blame] | 5530 | |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 5531 | if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 || |
| 5532 | codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670) |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5533 | ssids = alc663_ssids; |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 5534 | else |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5535 | ssids = alc662_ssids; |
| 5536 | return alc_parse_auto_config(codec, alc662_ignore, ssids); |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5537 | } |
| 5538 | |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5539 | static void alc272_fixup_mario(struct hda_codec *codec, |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5540 | const struct alc_fixup *fix, int action) |
Takashi Iwai | 6fc398c | 2011-01-13 14:36:37 +0100 | [diff] [blame] | 5541 | { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5542 | if (action != ALC_FIXUP_ACT_PROBE) |
Takashi Iwai | 6fc398c | 2011-01-13 14:36:37 +0100 | [diff] [blame] | 5543 | return; |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5544 | if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT, |
| 5545 | (0x3b << AC_AMPCAP_OFFSET_SHIFT) | |
| 5546 | (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 5547 | (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 5548 | (0 << AC_AMPCAP_MUTE_SHIFT))) |
| 5549 | printk(KERN_WARNING |
| 5550 | "hda_codec: failed to override amp caps for NID 0x2\n"); |
| 5551 | } |
| 5552 | |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5553 | enum { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5554 | ALC662_FIXUP_ASPIRE, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5555 | ALC662_FIXUP_IDEAPAD, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5556 | ALC272_FIXUP_MARIO, |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 5557 | ALC662_FIXUP_CZC_P10T, |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 5558 | ALC662_FIXUP_SKU_IGNORE, |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 5559 | ALC662_FIXUP_HP_RP5800, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5560 | ALC662_FIXUP_ASUS_MODE1, |
| 5561 | ALC662_FIXUP_ASUS_MODE2, |
| 5562 | ALC662_FIXUP_ASUS_MODE3, |
| 5563 | ALC662_FIXUP_ASUS_MODE4, |
| 5564 | ALC662_FIXUP_ASUS_MODE5, |
| 5565 | ALC662_FIXUP_ASUS_MODE6, |
| 5566 | ALC662_FIXUP_ASUS_MODE7, |
| 5567 | ALC662_FIXUP_ASUS_MODE8, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5568 | }; |
| 5569 | |
| 5570 | static const struct alc_fixup alc662_fixups[] = { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5571 | [ALC662_FIXUP_ASPIRE] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5572 | .type = ALC_FIXUP_PINS, |
| 5573 | .v.pins = (const struct alc_pincfg[]) { |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5574 | { 0x15, 0x99130112 }, /* subwoofer */ |
| 5575 | { } |
| 5576 | } |
| 5577 | }, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5578 | [ALC662_FIXUP_IDEAPAD] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5579 | .type = ALC_FIXUP_PINS, |
| 5580 | .v.pins = (const struct alc_pincfg[]) { |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5581 | { 0x17, 0x99130112 }, /* subwoofer */ |
| 5582 | { } |
| 5583 | } |
| 5584 | }, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5585 | [ALC272_FIXUP_MARIO] = { |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5586 | .type = ALC_FIXUP_FUNC, |
| 5587 | .v.func = alc272_fixup_mario, |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 5588 | }, |
| 5589 | [ALC662_FIXUP_CZC_P10T] = { |
| 5590 | .type = ALC_FIXUP_VERBS, |
| 5591 | .v.verbs = (const struct hda_verb[]) { |
| 5592 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, |
| 5593 | {} |
| 5594 | } |
| 5595 | }, |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 5596 | [ALC662_FIXUP_SKU_IGNORE] = { |
| 5597 | .type = ALC_FIXUP_SKU, |
| 5598 | .v.sku = ALC_FIXUP_SKU_IGNORE, |
Takashi Iwai | c6b3587 | 2011-03-28 12:05:31 +0200 | [diff] [blame] | 5599 | }, |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 5600 | [ALC662_FIXUP_HP_RP5800] = { |
| 5601 | .type = ALC_FIXUP_PINS, |
| 5602 | .v.pins = (const struct alc_pincfg[]) { |
| 5603 | { 0x14, 0x0221201f }, /* HP out */ |
| 5604 | { } |
| 5605 | }, |
| 5606 | .chained = true, |
| 5607 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5608 | }, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5609 | [ALC662_FIXUP_ASUS_MODE1] = { |
| 5610 | .type = ALC_FIXUP_PINS, |
| 5611 | .v.pins = (const struct alc_pincfg[]) { |
| 5612 | { 0x14, 0x99130110 }, /* speaker */ |
| 5613 | { 0x18, 0x01a19c20 }, /* mic */ |
| 5614 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 5615 | { 0x21, 0x0121401f }, /* HP out */ |
| 5616 | { } |
| 5617 | }, |
| 5618 | .chained = true, |
| 5619 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5620 | }, |
| 5621 | [ALC662_FIXUP_ASUS_MODE2] = { |
Takashi Iwai | 2996bdb | 2011-08-18 16:02:24 +0200 | [diff] [blame] | 5622 | .type = ALC_FIXUP_PINS, |
| 5623 | .v.pins = (const struct alc_pincfg[]) { |
| 5624 | { 0x14, 0x99130110 }, /* speaker */ |
| 5625 | { 0x18, 0x01a19820 }, /* mic */ |
| 5626 | { 0x19, 0x99a3092f }, /* int-mic */ |
| 5627 | { 0x1b, 0x0121401f }, /* HP out */ |
| 5628 | { } |
| 5629 | }, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5630 | .chained = true, |
| 5631 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5632 | }, |
| 5633 | [ALC662_FIXUP_ASUS_MODE3] = { |
| 5634 | .type = ALC_FIXUP_PINS, |
| 5635 | .v.pins = (const struct alc_pincfg[]) { |
| 5636 | { 0x14, 0x99130110 }, /* speaker */ |
| 5637 | { 0x15, 0x0121441f }, /* HP */ |
| 5638 | { 0x18, 0x01a19840 }, /* mic */ |
| 5639 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5640 | { 0x21, 0x01211420 }, /* HP2 */ |
| 5641 | { } |
| 5642 | }, |
| 5643 | .chained = true, |
| 5644 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5645 | }, |
| 5646 | [ALC662_FIXUP_ASUS_MODE4] = { |
| 5647 | .type = ALC_FIXUP_PINS, |
| 5648 | .v.pins = (const struct alc_pincfg[]) { |
| 5649 | { 0x14, 0x99130110 }, /* speaker */ |
| 5650 | { 0x16, 0x99130111 }, /* speaker */ |
| 5651 | { 0x18, 0x01a19840 }, /* mic */ |
| 5652 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5653 | { 0x21, 0x0121441f }, /* HP */ |
| 5654 | { } |
| 5655 | }, |
| 5656 | .chained = true, |
| 5657 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5658 | }, |
| 5659 | [ALC662_FIXUP_ASUS_MODE5] = { |
| 5660 | .type = ALC_FIXUP_PINS, |
| 5661 | .v.pins = (const struct alc_pincfg[]) { |
| 5662 | { 0x14, 0x99130110 }, /* speaker */ |
| 5663 | { 0x15, 0x0121441f }, /* HP */ |
| 5664 | { 0x16, 0x99130111 }, /* speaker */ |
| 5665 | { 0x18, 0x01a19840 }, /* mic */ |
| 5666 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5667 | { } |
| 5668 | }, |
| 5669 | .chained = true, |
| 5670 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5671 | }, |
| 5672 | [ALC662_FIXUP_ASUS_MODE6] = { |
| 5673 | .type = ALC_FIXUP_PINS, |
| 5674 | .v.pins = (const struct alc_pincfg[]) { |
| 5675 | { 0x14, 0x99130110 }, /* speaker */ |
| 5676 | { 0x15, 0x01211420 }, /* HP2 */ |
| 5677 | { 0x18, 0x01a19840 }, /* mic */ |
| 5678 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5679 | { 0x1b, 0x0121441f }, /* HP */ |
| 5680 | { } |
| 5681 | }, |
| 5682 | .chained = true, |
| 5683 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5684 | }, |
| 5685 | [ALC662_FIXUP_ASUS_MODE7] = { |
| 5686 | .type = ALC_FIXUP_PINS, |
| 5687 | .v.pins = (const struct alc_pincfg[]) { |
| 5688 | { 0x14, 0x99130110 }, /* speaker */ |
| 5689 | { 0x17, 0x99130111 }, /* speaker */ |
| 5690 | { 0x18, 0x01a19840 }, /* mic */ |
| 5691 | { 0x19, 0x99a3094f }, /* int-mic */ |
| 5692 | { 0x1b, 0x01214020 }, /* HP */ |
| 5693 | { 0x21, 0x0121401f }, /* HP */ |
| 5694 | { } |
| 5695 | }, |
| 5696 | .chained = true, |
| 5697 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
| 5698 | }, |
| 5699 | [ALC662_FIXUP_ASUS_MODE8] = { |
| 5700 | .type = ALC_FIXUP_PINS, |
| 5701 | .v.pins = (const struct alc_pincfg[]) { |
| 5702 | { 0x14, 0x99130110 }, /* speaker */ |
| 5703 | { 0x12, 0x99a30970 }, /* int-mic */ |
| 5704 | { 0x15, 0x01214020 }, /* HP */ |
| 5705 | { 0x17, 0x99130111 }, /* speaker */ |
| 5706 | { 0x18, 0x01a19840 }, /* mic */ |
| 5707 | { 0x21, 0x0121401f }, /* HP */ |
| 5708 | { } |
| 5709 | }, |
| 5710 | .chained = true, |
| 5711 | .chain_id = ALC662_FIXUP_SKU_IGNORE |
Takashi Iwai | 2996bdb | 2011-08-18 16:02:24 +0200 | [diff] [blame] | 5712 | }, |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5713 | }; |
| 5714 | |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 5715 | static const struct snd_pci_quirk alc662_fixup_tbl[] = { |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5716 | SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2), |
David Henningsson | a6c47a8 | 2011-02-10 15:39:19 +0100 | [diff] [blame] | 5717 | SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE), |
David Henningsson | 94024cd | 2011-04-29 14:10:55 +0200 | [diff] [blame] | 5718 | SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE), |
Daniel T Chen | 2df0351 | 2010-10-10 22:39:28 -0400 | [diff] [blame] | 5719 | SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE), |
Takashi Iwai | e59ea3e | 2011-06-29 17:21:00 +0200 | [diff] [blame] | 5720 | SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5721 | SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2), |
Daniel T Chen | a0e90ac | 2010-11-20 10:20:35 -0500 | [diff] [blame] | 5722 | SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD), |
Valentine Sinitsyn | d411858 | 2010-10-01 22:24:08 +0600 | [diff] [blame] | 5723 | SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD), |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5724 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD), |
Anisse Astier | d2ebd47 | 2011-01-20 12:36:21 +0100 | [diff] [blame] | 5725 | SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T), |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5726 | |
| 5727 | #if 0 |
| 5728 | /* Below is a quirk table taken from the old code. |
| 5729 | * Basically the device should work as is without the fixup table. |
| 5730 | * If BIOS doesn't give a proper info, enable the corresponding |
| 5731 | * fixup entry. |
| 5732 | */ |
| 5733 | SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1), |
| 5734 | SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3), |
| 5735 | SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1), |
| 5736 | SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3), |
| 5737 | SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 5738 | SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5739 | SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 5740 | SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1), |
| 5741 | SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1), |
| 5742 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5743 | SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7), |
| 5744 | SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7), |
| 5745 | SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8), |
| 5746 | SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3), |
| 5747 | SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1), |
| 5748 | SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5749 | SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2), |
| 5750 | SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1), |
| 5751 | SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5752 | SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 5753 | SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 5754 | SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5755 | SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1), |
| 5756 | SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3), |
| 5757 | SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2), |
| 5758 | SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5759 | SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5), |
| 5760 | SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), |
| 5761 | SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5762 | SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1), |
| 5763 | SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5764 | SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5765 | SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3), |
| 5766 | SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3), |
| 5767 | SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1), |
| 5768 | SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1), |
| 5769 | SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1), |
| 5770 | SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1), |
| 5771 | SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1), |
| 5772 | SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), |
| 5773 | SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2), |
| 5774 | SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1), |
| 5775 | SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 5776 | SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3), |
| 5777 | SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1), |
| 5778 | SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1), |
| 5779 | SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1), |
| 5780 | SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2), |
| 5781 | SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), |
| 5782 | SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4), |
| 5783 | #endif |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5784 | {} |
| 5785 | }; |
| 5786 | |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5787 | static const struct alc_model_fixup alc662_fixup_models[] = { |
| 5788 | {.id = ALC272_FIXUP_MARIO, .name = "mario"}, |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5789 | {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"}, |
| 5790 | {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"}, |
| 5791 | {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"}, |
| 5792 | {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"}, |
| 5793 | {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"}, |
| 5794 | {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"}, |
| 5795 | {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"}, |
| 5796 | {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"}, |
Todd Broch | 6be7948 | 2010-12-07 16:51:05 -0800 | [diff] [blame] | 5797 | {} |
| 5798 | }; |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5799 | |
| 5800 | |
Takashi Iwai | 1d045db | 2011-07-07 18:23:21 +0200 | [diff] [blame] | 5801 | /* |
| 5802 | */ |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5803 | static int patch_alc662(struct hda_codec *codec) |
| 5804 | { |
| 5805 | struct alc_spec *spec; |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5806 | int err = 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5807 | |
| 5808 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5809 | if (!spec) |
| 5810 | return -ENOMEM; |
| 5811 | |
| 5812 | codec->spec = spec; |
| 5813 | |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 5814 | spec->mixer_nid = 0x0b; |
| 5815 | |
Takashi Iwai | 53c334a | 2011-08-23 18:27:14 +0200 | [diff] [blame] | 5816 | /* handle multiple HPs as is */ |
| 5817 | spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; |
| 5818 | |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 5819 | alc_auto_parse_customize_define(codec); |
| 5820 | |
Takashi Iwai | 2c3bf9a | 2008-06-04 12:39:38 +0200 | [diff] [blame] | 5821 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
| 5822 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5823 | err = alc_codec_rename_from_preset(codec); |
| 5824 | if (err < 0) |
| 5825 | goto error; |
| 5826 | |
Takashi Iwai | 1bb7e43 | 2011-10-17 16:50:59 +0200 | [diff] [blame] | 5827 | if ((alc_get_coef0(codec) & (1 << 14)) && |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5828 | codec->bus->pci->subsystem_vendor == 0x1025 && |
| 5829 | spec->cdefine.platform_type == 1) { |
| 5830 | if (alc_codec_rename(codec, "ALC272X") < 0) |
| 5831 | goto error; |
Takashi Iwai | 20ca0c3 | 2011-10-17 16:00:35 +0200 | [diff] [blame] | 5832 | } |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 5833 | |
Takashi Iwai | b9c5106 | 2011-08-24 18:08:07 +0200 | [diff] [blame] | 5834 | alc_pick_fixup(codec, alc662_fixup_models, |
| 5835 | alc662_fixup_tbl, alc662_fixups); |
| 5836 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
| 5837 | /* automatic parse from the BIOS config */ |
| 5838 | err = alc662_parse_auto_config(codec); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5839 | if (err < 0) |
| 5840 | goto error; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5841 | |
Takashi Iwai | 60a6a84 | 2011-07-27 14:01:24 +0200 | [diff] [blame] | 5842 | if (!spec->no_analog && !spec->adc_nids) { |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 5843 | alc_auto_fill_adc_caps(codec); |
Takashi Iwai | 2126896 | 2011-07-07 15:01:13 +0200 | [diff] [blame] | 5844 | alc_rebuild_imux_for_auto_mic(codec); |
Takashi Iwai | d6cc9fab | 2011-07-06 16:38:42 +0200 | [diff] [blame] | 5845 | alc_remove_invalid_adc_nids(codec); |
Takashi Iwai | dd70469 | 2009-08-11 08:45:11 +0200 | [diff] [blame] | 5846 | } |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5847 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5848 | if (!spec->no_analog && !spec->cap_mixer) |
Takashi Iwai | b59bdf3 | 2009-08-11 09:47:30 +0200 | [diff] [blame] | 5849 | set_capture_mixer(codec); |
Takashi Iwai | f9e336f | 2008-10-31 16:37:07 +0100 | [diff] [blame] | 5850 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5851 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
| 5852 | err = snd_hda_attach_beep_device(codec, 0x1); |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5853 | if (err < 0) |
| 5854 | goto error; |
Kailang Yang | da00c24 | 2010-03-19 11:23:45 +0100 | [diff] [blame] | 5855 | switch (codec->vendor_id) { |
| 5856 | case 0x10ec0662: |
| 5857 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
| 5858 | break; |
| 5859 | case 0x10ec0272: |
| 5860 | case 0x10ec0663: |
| 5861 | case 0x10ec0665: |
| 5862 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
| 5863 | break; |
| 5864 | case 0x10ec0273: |
| 5865 | set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT); |
| 5866 | break; |
| 5867 | } |
Kailang Yang | cec27c8 | 2010-02-04 14:18:18 +0100 | [diff] [blame] | 5868 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 5869 | spec->vmaster_nid = 0x02; |
| 5870 | |
Takashi Iwai | b5bfbc6 | 2011-01-13 14:22:32 +0100 | [diff] [blame] | 5871 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
| 5872 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5873 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | b9c5106 | 2011-08-24 18:08:07 +0200 | [diff] [blame] | 5874 | spec->init_hook = alc_auto_init_std; |
Takashi Iwai | 1c71615 | 2011-04-07 10:37:16 +0200 | [diff] [blame] | 5875 | spec->shutup = alc_eapd_shutup; |
David Henningsson | 6cb3b70 | 2010-09-09 08:51:44 +0200 | [diff] [blame] | 5876 | |
Kailang Yang | bf1b022 | 2010-10-21 08:49:56 +0200 | [diff] [blame] | 5877 | alc_init_jacks(codec); |
| 5878 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 5879 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5880 | if (!spec->loopback.amplist) |
| 5881 | spec->loopback.amplist = alc662_loopbacks; |
| 5882 | #endif |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5883 | |
| 5884 | return 0; |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5885 | |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5886 | error: |
| 5887 | alc_free(codec); |
| 5888 | return err; |
Kailang Yang | b478b99 | 2011-05-18 11:51:15 +0200 | [diff] [blame] | 5889 | } |
| 5890 | |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5891 | /* |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5892 | * ALC680 support |
| 5893 | */ |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5894 | |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5895 | static int alc680_parse_auto_config(struct hda_codec *codec) |
| 5896 | { |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5897 | return alc_parse_auto_config(codec, NULL, NULL); |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5898 | } |
| 5899 | |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5900 | /* |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5901 | */ |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5902 | static int patch_alc680(struct hda_codec *codec) |
| 5903 | { |
| 5904 | struct alc_spec *spec; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5905 | int err; |
| 5906 | |
| 5907 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5908 | if (spec == NULL) |
| 5909 | return -ENOMEM; |
| 5910 | |
| 5911 | codec->spec = spec; |
| 5912 | |
Takashi Iwai | 1f0f4b8 | 2011-06-27 10:52:59 +0200 | [diff] [blame] | 5913 | /* ALC680 has no aa-loopback mixer */ |
| 5914 | |
Takashi Iwai | 1ebec5f | 2011-08-15 13:21:48 +0200 | [diff] [blame] | 5915 | /* automatic parse from the BIOS config */ |
| 5916 | err = alc680_parse_auto_config(codec); |
| 5917 | if (err < 0) { |
| 5918 | alc_free(codec); |
| 5919 | return err; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5920 | } |
| 5921 | |
Takashi Iwai | 3e6179b | 2011-07-08 16:55:13 +0200 | [diff] [blame] | 5922 | if (!spec->no_analog && !spec->cap_mixer) |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5923 | set_capture_mixer(codec); |
| 5924 | |
| 5925 | spec->vmaster_nid = 0x02; |
| 5926 | |
| 5927 | codec->patch_ops = alc_patch_ops; |
Takashi Iwai | 1ebec5f | 2011-08-15 13:21:48 +0200 | [diff] [blame] | 5928 | spec->init_hook = alc_auto_init_std; |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5929 | |
| 5930 | return 0; |
| 5931 | } |
| 5932 | |
| 5933 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5934 | * patch entries |
| 5935 | */ |
Takashi Iwai | a911132 | 2011-05-02 11:30:18 +0200 | [diff] [blame] | 5936 | static const struct hda_codec_preset snd_hda_preset_realtek[] = { |
Kailang Yang | 296f033 | 2011-05-18 11:52:36 +0200 | [diff] [blame] | 5937 | { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5938 | { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 }, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 5939 | { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 }, |
Kailang Yang | f6a9224 | 2007-12-13 16:52:54 +0100 | [diff] [blame] | 5940 | { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 }, |
Kailang Yang | a361d84 | 2007-06-05 12:30:55 +0200 | [diff] [blame] | 5941 | { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 }, |
Kailang Yang | f6a9224 | 2007-12-13 16:52:54 +0100 | [diff] [blame] | 5942 | { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 }, |
Kailang Yang | ebb83ee | 2009-12-17 12:23:00 +0100 | [diff] [blame] | 5943 | { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 }, |
Kailang Yang | 01afd41 | 2008-10-15 11:22:09 +0200 | [diff] [blame] | 5944 | { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 }, |
Kailang Yang | ebb83ee | 2009-12-17 12:23:00 +0100 | [diff] [blame] | 5945 | { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 }, |
Kailang Yang | 296f033 | 2011-05-18 11:52:36 +0200 | [diff] [blame] | 5946 | { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 5947 | { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660", |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5948 | .patch = patch_alc861 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 5949 | { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd }, |
| 5950 | { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 }, |
| 5951 | { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd }, |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5952 | { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2", |
Takashi Iwai | 4953550 | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5953 | .patch = patch_alc882 }, |
Kailang Yang | bc9f98a | 2007-04-12 13:06:07 +0200 | [diff] [blame] | 5954 | { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1", |
| 5955 | .patch = patch_alc662 }, |
David Henningsson | cc667a7 | 2011-10-18 14:07:51 +0200 | [diff] [blame] | 5956 | { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3", |
| 5957 | .patch = patch_alc662 }, |
Kailang Yang | 6dda9f4 | 2008-05-27 12:05:31 +0200 | [diff] [blame] | 5958 | { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 }, |
Kailang Yang | cec27c8 | 2010-02-04 14:18:18 +0100 | [diff] [blame] | 5959 | { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 }, |
Kailang Yang | 6227cdc | 2010-02-25 08:36:52 +0100 | [diff] [blame] | 5960 | { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 }, |
Kailang Yang | d1eb57f | 2010-06-23 16:25:26 +0200 | [diff] [blame] | 5961 | { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 }, |
Jakub Schmidtke | f32610e | 2007-02-02 18:17:27 +0100 | [diff] [blame] | 5962 | { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5963 | { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, |
Takashi Iwai | 4953550 | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5964 | { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 }, |
Clive Messer | 669faba | 2008-09-30 15:49:13 +0200 | [diff] [blame] | 5965 | { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A", |
Takashi Iwai | 4953550 | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5966 | .patch = patch_alc882 }, |
Takashi Iwai | cb308f9 | 2008-04-16 14:13:29 +0200 | [diff] [blame] | 5967 | { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A", |
Takashi Iwai | 4953550 | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5968 | .patch = patch_alc882 }, |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 5969 | { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5970 | { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 }, |
Kailang Yang | 4442608 | 2008-10-15 11:18:05 +0200 | [diff] [blame] | 5971 | { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", |
Takashi Iwai | 4953550 | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5972 | .patch = patch_alc882 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5973 | { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 }, |
Takashi Iwai | 4953550 | 2009-06-30 15:28:30 +0200 | [diff] [blame] | 5974 | { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 }, |
Kailang Yang | 274693f | 2009-12-03 10:07:50 +0100 | [diff] [blame] | 5975 | { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 }, |
Takashi Iwai | e16fb6d | 2011-10-17 16:39:09 +0200 | [diff] [blame] | 5976 | { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5977 | {} /* terminator */ |
| 5978 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 5979 | |
| 5980 | MODULE_ALIAS("snd-hda-codec-id:10ec*"); |
| 5981 | |
| 5982 | MODULE_LICENSE("GPL"); |
| 5983 | MODULE_DESCRIPTION("Realtek HD-audio codec"); |
| 5984 | |
| 5985 | static struct hda_codec_preset_list realtek_list = { |
| 5986 | .preset = snd_hda_preset_realtek, |
| 5987 | .owner = THIS_MODULE, |
| 5988 | }; |
| 5989 | |
| 5990 | static int __init patch_realtek_init(void) |
| 5991 | { |
| 5992 | return snd_hda_add_codec_preset(&realtek_list); |
| 5993 | } |
| 5994 | |
| 5995 | static void __exit patch_realtek_exit(void) |
| 5996 | { |
| 5997 | snd_hda_delete_codec_preset(&realtek_list); |
| 5998 | } |
| 5999 | |
| 6000 | module_init(patch_realtek_init) |
| 6001 | module_exit(patch_realtek_exit) |