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