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