Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1 | /* |
| 2 | * HD audio interface patch for Conexant HDA audio codec |
| 3 | * |
| 4 | * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com> |
| 5 | * Takashi Iwai <tiwai@suse.de> |
| 6 | * Tobin Davis <tdavis@dsl-only.net> |
| 7 | * |
| 8 | * This driver is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This driver is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 23 | #include <linux/init.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/pci.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 28 | #include <sound/core.h> |
Ulrich Dangel | bc7a166 | 2009-01-02 19:30:13 +0100 | [diff] [blame] | 29 | #include <sound/jack.h> |
| 30 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 31 | #include "hda_codec.h" |
| 32 | #include "hda_local.h" |
Einar Rünkaru | c0f8faf | 2009-12-16 22:41:36 +0200 | [diff] [blame] | 33 | #include "hda_beep.h" |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 34 | #include "hda_jack.h" |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 35 | |
| 36 | #define CXT_PIN_DIR_IN 0x00 |
| 37 | #define CXT_PIN_DIR_OUT 0x01 |
| 38 | #define CXT_PIN_DIR_INOUT 0x02 |
| 39 | #define CXT_PIN_DIR_IN_NOMICBIAS 0x03 |
| 40 | #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 |
| 41 | |
| 42 | #define CONEXANT_HP_EVENT 0x37 |
| 43 | #define CONEXANT_MIC_EVENT 0x38 |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 44 | #define CONEXANT_LINE_EVENT 0x39 |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 45 | |
Ulrich Dangel | bc7a166 | 2009-01-02 19:30:13 +0100 | [diff] [blame] | 46 | /* Conexant 5051 specific */ |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 47 | |
Takashi Iwai | ecda0cf | 2010-01-24 11:14:36 +0100 | [diff] [blame] | 48 | #define CXT5051_SPDIF_OUT 0x12 |
Ulrich Dangel | bc7a166 | 2009-01-02 19:30:13 +0100 | [diff] [blame] | 49 | #define CXT5051_PORTB_EVENT 0x38 |
| 50 | #define CXT5051_PORTC_EVENT 0x39 |
| 51 | |
Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 52 | #define AUTO_MIC_PORTB (1 << 1) |
| 53 | #define AUTO_MIC_PORTC (1 << 2) |
Ulrich Dangel | bc7a166 | 2009-01-02 19:30:13 +0100 | [diff] [blame] | 54 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 55 | struct pin_dac_pair { |
| 56 | hda_nid_t pin; |
| 57 | hda_nid_t dac; |
| 58 | int type; |
| 59 | }; |
| 60 | |
Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 61 | struct imux_info { |
| 62 | hda_nid_t pin; /* input pin NID */ |
| 63 | hda_nid_t adc; /* connected ADC NID */ |
| 64 | hda_nid_t boost; /* optional boost volume NID */ |
| 65 | int index; /* corresponding to autocfg.input */ |
| 66 | }; |
| 67 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 68 | struct conexant_spec { |
| 69 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 70 | const struct snd_kcontrol_new *mixers[5]; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 71 | int num_mixers; |
Takashi Iwai | dd5746a | 2009-03-10 14:30:40 +0100 | [diff] [blame] | 72 | hda_nid_t vmaster_nid; |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 73 | struct hda_vmaster_mute_hook vmaster_mute; |
Takashi Iwai | f29735c | 2012-03-13 07:55:10 +0100 | [diff] [blame] | 74 | bool vmaster_mute_led; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 75 | |
| 76 | const struct hda_verb *init_verbs[5]; /* initialization verbs |
| 77 | * don't forget NULL |
| 78 | * termination! |
| 79 | */ |
| 80 | unsigned int num_init_verbs; |
| 81 | |
| 82 | /* playback */ |
| 83 | struct hda_multi_out multiout; /* playback set-up |
| 84 | * max_channels, dacs must be set |
| 85 | * dig_out_nid and hp_nid are optional |
| 86 | */ |
| 87 | unsigned int cur_eapd; |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 88 | unsigned int hp_present; |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 89 | unsigned int line_present; |
Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 90 | unsigned int auto_mic; |
Takashi Iwai | f6100bb | 2011-05-13 18:26:39 +0200 | [diff] [blame] | 91 | int auto_mic_ext; /* imux_pins[] index for ext mic */ |
Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 92 | int auto_mic_dock; /* imux_pins[] index for dock mic */ |
| 93 | int auto_mic_int; /* imux_pins[] index for int mic */ |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 94 | unsigned int need_dac_fix; |
Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 95 | hda_nid_t slave_dig_outs[2]; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 96 | |
| 97 | /* capture */ |
| 98 | unsigned int num_adc_nids; |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 99 | const hda_nid_t *adc_nids; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 100 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ |
| 101 | |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 102 | unsigned int cur_adc_idx; |
| 103 | hda_nid_t cur_adc; |
| 104 | unsigned int cur_adc_stream_tag; |
| 105 | unsigned int cur_adc_format; |
| 106 | |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 107 | const struct hda_pcm_stream *capture_stream; |
| 108 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 109 | /* capture source */ |
| 110 | const struct hda_input_mux *input_mux; |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 111 | const hda_nid_t *capsrc_nids; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 112 | unsigned int cur_mux[3]; |
| 113 | |
| 114 | /* channel model */ |
| 115 | const struct hda_channel_mode *channel_mode; |
| 116 | int num_channel_mode; |
| 117 | |
| 118 | /* PCM information */ |
| 119 | struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ |
| 120 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 121 | unsigned int spdif_route; |
| 122 | |
| 123 | /* dynamic controls, init_verbs and input_mux */ |
| 124 | struct auto_pin_cfg autocfg; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 125 | struct hda_input_mux private_imux; |
Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 126 | struct imux_info imux_info[HDA_MAX_NUM_INPUTS]; |
Takashi Iwai | 22ce5f7 | 2011-05-15 12:19:29 +0200 | [diff] [blame] | 127 | hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS]; |
Takashi Iwai | 41923e4 | 2007-10-22 17:20:10 +0200 | [diff] [blame] | 128 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 129 | struct pin_dac_pair dac_info[8]; |
| 130 | int dac_info_filled; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 131 | |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 132 | unsigned int port_d_mode; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 133 | unsigned int auto_mute:1; /* used in auto-parser */ |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 134 | unsigned int detect_line:1; /* Line-out detection enabled */ |
| 135 | unsigned int automute_lines:1; /* automute line-out as well */ |
| 136 | unsigned int automute_hp_lo:1; /* both HP and LO available */ |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 137 | unsigned int dell_automute:1; |
Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 138 | unsigned int dell_vostro:1; |
| 139 | unsigned int ideapad:1; |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 140 | unsigned int thinkpad:1; |
David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 141 | unsigned int hp_laptop:1; |
David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 142 | unsigned int asus:1; |
Takashi Iwai | 254f296 | 2011-10-14 15:22:34 +0200 | [diff] [blame] | 143 | unsigned int pin_eapd_ctrls:1; |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 144 | |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 145 | unsigned int adc_switching:1; |
| 146 | |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 147 | unsigned int ext_mic_present; |
| 148 | unsigned int recording; |
| 149 | void (*capture_prepare)(struct hda_codec *codec); |
| 150 | void (*capture_cleanup)(struct hda_codec *codec); |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 151 | |
| 152 | /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) |
| 153 | * through the microphone jack. |
| 154 | * When the user enables this through a mixer switch, both internal and |
| 155 | * external microphones are disabled. Gain is fixed at 0dB. In this mode, |
| 156 | * we also allow the bias to be configured through a separate mixer |
| 157 | * control. */ |
| 158 | unsigned int dc_enable; |
| 159 | unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ |
| 160 | unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ |
Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 161 | |
| 162 | unsigned int beep_amp; |
Takashi Iwai | 1911059 | 2011-07-11 14:46:44 +0200 | [diff] [blame] | 163 | |
| 164 | /* extra EAPD pins */ |
| 165 | unsigned int num_eapds; |
| 166 | hda_nid_t eapds[4]; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 170 | struct hda_codec *codec, |
| 171 | struct snd_pcm_substream *substream) |
| 172 | { |
| 173 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 174 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 175 | hinfo); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 179 | struct hda_codec *codec, |
| 180 | unsigned int stream_tag, |
| 181 | unsigned int format, |
| 182 | struct snd_pcm_substream *substream) |
| 183 | { |
| 184 | struct conexant_spec *spec = codec->spec; |
| 185 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, |
| 186 | stream_tag, |
| 187 | format, substream); |
| 188 | } |
| 189 | |
| 190 | static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 191 | struct hda_codec *codec, |
| 192 | struct snd_pcm_substream *substream) |
| 193 | { |
| 194 | struct conexant_spec *spec = codec->spec; |
| 195 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
| 196 | } |
| 197 | |
| 198 | /* |
| 199 | * Digital out |
| 200 | */ |
| 201 | static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 202 | struct hda_codec *codec, |
| 203 | struct snd_pcm_substream *substream) |
| 204 | { |
| 205 | struct conexant_spec *spec = codec->spec; |
| 206 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 207 | } |
| 208 | |
| 209 | static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 210 | struct hda_codec *codec, |
| 211 | struct snd_pcm_substream *substream) |
| 212 | { |
| 213 | struct conexant_spec *spec = codec->spec; |
| 214 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 215 | } |
| 216 | |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 217 | static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 218 | struct hda_codec *codec, |
| 219 | unsigned int stream_tag, |
| 220 | unsigned int format, |
| 221 | struct snd_pcm_substream *substream) |
| 222 | { |
| 223 | struct conexant_spec *spec = codec->spec; |
| 224 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 225 | stream_tag, |
| 226 | format, substream); |
| 227 | } |
| 228 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 229 | /* |
| 230 | * Analog capture |
| 231 | */ |
| 232 | static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 233 | struct hda_codec *codec, |
| 234 | unsigned int stream_tag, |
| 235 | unsigned int format, |
| 236 | struct snd_pcm_substream *substream) |
| 237 | { |
| 238 | struct conexant_spec *spec = codec->spec; |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 239 | if (spec->capture_prepare) |
| 240 | spec->capture_prepare(codec); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 241 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], |
| 242 | stream_tag, 0, format); |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 247 | struct hda_codec *codec, |
| 248 | struct snd_pcm_substream *substream) |
| 249 | { |
| 250 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 251 | snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 252 | if (spec->capture_cleanup) |
| 253 | spec->capture_cleanup(codec); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | |
| 258 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 259 | static const struct hda_pcm_stream conexant_pcm_analog_playback = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 260 | .substreams = 1, |
| 261 | .channels_min = 2, |
| 262 | .channels_max = 2, |
| 263 | .nid = 0, /* fill later */ |
| 264 | .ops = { |
| 265 | .open = conexant_playback_pcm_open, |
| 266 | .prepare = conexant_playback_pcm_prepare, |
| 267 | .cleanup = conexant_playback_pcm_cleanup |
| 268 | }, |
| 269 | }; |
| 270 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 271 | static const struct hda_pcm_stream conexant_pcm_analog_capture = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 272 | .substreams = 1, |
| 273 | .channels_min = 2, |
| 274 | .channels_max = 2, |
| 275 | .nid = 0, /* fill later */ |
| 276 | .ops = { |
| 277 | .prepare = conexant_capture_pcm_prepare, |
| 278 | .cleanup = conexant_capture_pcm_cleanup |
| 279 | }, |
| 280 | }; |
| 281 | |
| 282 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 283 | static const struct hda_pcm_stream conexant_pcm_digital_playback = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 284 | .substreams = 1, |
| 285 | .channels_min = 2, |
| 286 | .channels_max = 2, |
| 287 | .nid = 0, /* fill later */ |
| 288 | .ops = { |
| 289 | .open = conexant_dig_playback_pcm_open, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 290 | .close = conexant_dig_playback_pcm_close, |
| 291 | .prepare = conexant_dig_playback_pcm_prepare |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 292 | }, |
| 293 | }; |
| 294 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 295 | static const struct hda_pcm_stream conexant_pcm_digital_capture = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 296 | .substreams = 1, |
| 297 | .channels_min = 2, |
| 298 | .channels_max = 2, |
| 299 | /* NID is set in alc_build_pcms */ |
| 300 | }; |
| 301 | |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 302 | static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 303 | struct hda_codec *codec, |
| 304 | unsigned int stream_tag, |
| 305 | unsigned int format, |
| 306 | struct snd_pcm_substream *substream) |
| 307 | { |
| 308 | struct conexant_spec *spec = codec->spec; |
| 309 | spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; |
| 310 | spec->cur_adc_stream_tag = stream_tag; |
| 311 | spec->cur_adc_format = format; |
| 312 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 317 | struct hda_codec *codec, |
| 318 | struct snd_pcm_substream *substream) |
| 319 | { |
| 320 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 321 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 322 | spec->cur_adc = 0; |
| 323 | return 0; |
| 324 | } |
| 325 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 326 | static const struct hda_pcm_stream cx5051_pcm_analog_capture = { |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 327 | .substreams = 1, |
| 328 | .channels_min = 2, |
| 329 | .channels_max = 2, |
| 330 | .nid = 0, /* fill later */ |
| 331 | .ops = { |
| 332 | .prepare = cx5051_capture_pcm_prepare, |
| 333 | .cleanup = cx5051_capture_pcm_cleanup |
| 334 | }, |
| 335 | }; |
| 336 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 337 | static int conexant_build_pcms(struct hda_codec *codec) |
| 338 | { |
| 339 | struct conexant_spec *spec = codec->spec; |
| 340 | struct hda_pcm *info = spec->pcm_rec; |
| 341 | |
| 342 | codec->num_pcms = 1; |
| 343 | codec->pcm_info = info; |
| 344 | |
| 345 | info->name = "CONEXANT Analog"; |
| 346 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; |
| 347 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
| 348 | spec->multiout.max_channels; |
| 349 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 350 | spec->multiout.dac_nids[0]; |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 351 | if (spec->capture_stream) |
| 352 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream; |
| 353 | else { |
| 354 | if (codec->vendor_id == 0x14f15051) |
| 355 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 356 | cx5051_pcm_analog_capture; |
| 357 | else { |
| 358 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 359 | conexant_pcm_analog_capture; |
| 360 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = |
| 361 | spec->num_adc_nids; |
| 362 | } |
| 363 | } |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 364 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 365 | |
| 366 | if (spec->multiout.dig_out_nid) { |
| 367 | info++; |
| 368 | codec->num_pcms++; |
| 369 | info->name = "Conexant Digital"; |
Takashi Iwai | 7ba72ba | 2008-02-06 14:03:20 +0100 | [diff] [blame] | 370 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 371 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 372 | conexant_pcm_digital_playback; |
| 373 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 374 | spec->multiout.dig_out_nid; |
| 375 | if (spec->dig_in_nid) { |
| 376 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 377 | conexant_pcm_digital_capture; |
| 378 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 379 | spec->dig_in_nid; |
| 380 | } |
Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 381 | if (spec->slave_dig_outs[0]) |
| 382 | codec->slave_dig_outs = spec->slave_dig_outs; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 389 | struct snd_ctl_elem_info *uinfo) |
| 390 | { |
| 391 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 392 | struct conexant_spec *spec = codec->spec; |
| 393 | |
| 394 | return snd_hda_input_mux_info(spec->input_mux, uinfo); |
| 395 | } |
| 396 | |
| 397 | static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 398 | struct snd_ctl_elem_value *ucontrol) |
| 399 | { |
| 400 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 401 | struct conexant_spec *spec = codec->spec; |
| 402 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 403 | |
| 404 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 409 | struct snd_ctl_elem_value *ucontrol) |
| 410 | { |
| 411 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 412 | struct conexant_spec *spec = codec->spec; |
| 413 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 414 | |
| 415 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, |
| 416 | spec->capsrc_nids[adc_idx], |
| 417 | &spec->cur_mux[adc_idx]); |
| 418 | } |
| 419 | |
Takashi Iwai | 4d7fbdb | 2011-07-26 10:33:10 +0200 | [diff] [blame] | 420 | static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg, |
| 421 | unsigned int power_state) |
| 422 | { |
| 423 | if (power_state == AC_PWRST_D3) |
| 424 | msleep(100); |
| 425 | snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, |
| 426 | power_state); |
| 427 | /* partial workaround for "azx_get_response timeout" */ |
| 428 | if (power_state == AC_PWRST_D0) |
| 429 | msleep(10); |
| 430 | snd_hda_codec_set_power_to_all(codec, fg, power_state, true); |
| 431 | } |
| 432 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 433 | static int conexant_init(struct hda_codec *codec) |
| 434 | { |
| 435 | struct conexant_spec *spec = codec->spec; |
| 436 | int i; |
| 437 | |
| 438 | for (i = 0; i < spec->num_init_verbs; i++) |
| 439 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | static void conexant_free(struct hda_codec *codec) |
| 444 | { |
Einar Rünkaru | c0f8faf | 2009-12-16 22:41:36 +0200 | [diff] [blame] | 445 | snd_hda_detach_beep_device(codec); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 446 | kfree(codec->spec); |
| 447 | } |
| 448 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 449 | static const struct snd_kcontrol_new cxt_capture_mixers[] = { |
Takashi Iwai | b880c74 | 2009-03-10 14:41:05 +0100 | [diff] [blame] | 450 | { |
| 451 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 452 | .name = "Capture Source", |
| 453 | .info = conexant_mux_enum_info, |
| 454 | .get = conexant_mux_enum_get, |
| 455 | .put = conexant_mux_enum_put |
| 456 | }, |
| 457 | {} |
| 458 | }; |
| 459 | |
Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 460 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
| 461 | /* additional beep mixers; the actual parameters are overwritten at build */ |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 462 | static const struct snd_kcontrol_new cxt_beep_mixer[] = { |
Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 463 | HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), |
| 464 | HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), |
| 465 | { } /* end */ |
| 466 | }; |
| 467 | #endif |
| 468 | |
Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 469 | static const char * const slave_pfxs[] = { |
| 470 | "Headphone", "Speaker", "Front", "Surround", "CLFE", |
Takashi Iwai | dd5746a | 2009-03-10 14:30:40 +0100 | [diff] [blame] | 471 | NULL |
| 472 | }; |
| 473 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 474 | static int conexant_build_controls(struct hda_codec *codec) |
| 475 | { |
| 476 | struct conexant_spec *spec = codec->spec; |
| 477 | unsigned int i; |
| 478 | int err; |
| 479 | |
| 480 | for (i = 0; i < spec->num_mixers; i++) { |
| 481 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 482 | if (err < 0) |
| 483 | return err; |
| 484 | } |
| 485 | if (spec->multiout.dig_out_nid) { |
| 486 | err = snd_hda_create_spdif_out_ctls(codec, |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 487 | spec->multiout.dig_out_nid, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 488 | spec->multiout.dig_out_nid); |
| 489 | if (err < 0) |
| 490 | return err; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 491 | err = snd_hda_create_spdif_share_sw(codec, |
| 492 | &spec->multiout); |
| 493 | if (err < 0) |
| 494 | return err; |
| 495 | spec->multiout.share_spdif = 1; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 496 | } |
| 497 | if (spec->dig_in_nid) { |
| 498 | err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); |
| 499 | if (err < 0) |
| 500 | return err; |
| 501 | } |
Takashi Iwai | dd5746a | 2009-03-10 14:30:40 +0100 | [diff] [blame] | 502 | |
| 503 | /* if we have no master control, let's create it */ |
| 504 | if (spec->vmaster_nid && |
| 505 | !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { |
| 506 | unsigned int vmaster_tlv[4]; |
| 507 | snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, |
| 508 | HDA_OUTPUT, vmaster_tlv); |
| 509 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", |
Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 510 | vmaster_tlv, slave_pfxs, |
| 511 | "Playback Volume"); |
Takashi Iwai | dd5746a | 2009-03-10 14:30:40 +0100 | [diff] [blame] | 512 | if (err < 0) |
| 513 | return err; |
| 514 | } |
| 515 | if (spec->vmaster_nid && |
| 516 | !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { |
Takashi Iwai | 527c73b | 2012-03-12 12:38:51 +0100 | [diff] [blame] | 517 | err = __snd_hda_add_vmaster(codec, "Master Playback Switch", |
| 518 | NULL, slave_pfxs, |
| 519 | "Playback Switch", true, |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 520 | &spec->vmaster_mute.sw_kctl); |
Takashi Iwai | dd5746a | 2009-03-10 14:30:40 +0100 | [diff] [blame] | 521 | if (err < 0) |
| 522 | return err; |
| 523 | } |
| 524 | |
Takashi Iwai | b880c74 | 2009-03-10 14:41:05 +0100 | [diff] [blame] | 525 | if (spec->input_mux) { |
| 526 | err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); |
| 527 | if (err < 0) |
| 528 | return err; |
| 529 | } |
| 530 | |
Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 531 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
| 532 | /* create beep controls if needed */ |
| 533 | if (spec->beep_amp) { |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 534 | const struct snd_kcontrol_new *knew; |
Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 535 | for (knew = cxt_beep_mixer; knew->name; knew++) { |
| 536 | struct snd_kcontrol *kctl; |
| 537 | kctl = snd_ctl_new1(knew, codec); |
| 538 | if (!kctl) |
| 539 | return -ENOMEM; |
| 540 | kctl->private_value = spec->beep_amp; |
| 541 | err = snd_hda_ctl_add(codec, 0, kctl); |
| 542 | if (err < 0) |
| 543 | return err; |
| 544 | } |
| 545 | } |
| 546 | #endif |
| 547 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 548 | return 0; |
| 549 | } |
| 550 | |
Takashi Iwai | 697c373 | 2010-07-30 11:28:02 +0200 | [diff] [blame] | 551 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 552 | static int conexant_suspend(struct hda_codec *codec, pm_message_t state) |
| 553 | { |
| 554 | snd_hda_shutup_pins(codec); |
| 555 | return 0; |
| 556 | } |
| 557 | #endif |
| 558 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 559 | static const struct hda_codec_ops conexant_patch_ops = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 560 | .build_controls = conexant_build_controls, |
| 561 | .build_pcms = conexant_build_pcms, |
| 562 | .init = conexant_init, |
| 563 | .free = conexant_free, |
Takashi Iwai | 4d7fbdb | 2011-07-26 10:33:10 +0200 | [diff] [blame] | 564 | .set_power_state = conexant_set_power, |
Takashi Iwai | 697c373 | 2010-07-30 11:28:02 +0200 | [diff] [blame] | 565 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 566 | .suspend = conexant_suspend, |
| 567 | #endif |
| 568 | .reboot_notify = snd_hda_shutup_pins, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 569 | }; |
| 570 | |
Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 571 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
| 572 | #define set_beep_amp(spec, nid, idx, dir) \ |
| 573 | ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) |
| 574 | #else |
| 575 | #define set_beep_amp(spec, nid, idx, dir) /* NOP */ |
| 576 | #endif |
| 577 | |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 578 | static int patch_conexant_auto(struct hda_codec *codec); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 579 | /* |
| 580 | * EAPD control |
| 581 | * the private value = nid | (invert << 8) |
| 582 | */ |
| 583 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 584 | #define cxt_eapd_info snd_ctl_boolean_mono_info |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 585 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 586 | static int cxt_eapd_get(struct snd_kcontrol *kcontrol, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 587 | struct snd_ctl_elem_value *ucontrol) |
| 588 | { |
| 589 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 590 | struct conexant_spec *spec = codec->spec; |
| 591 | int invert = (kcontrol->private_value >> 8) & 1; |
| 592 | if (invert) |
| 593 | ucontrol->value.integer.value[0] = !spec->cur_eapd; |
| 594 | else |
| 595 | ucontrol->value.integer.value[0] = spec->cur_eapd; |
| 596 | return 0; |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 597 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 598 | } |
| 599 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 600 | static int cxt_eapd_put(struct snd_kcontrol *kcontrol, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 601 | struct snd_ctl_elem_value *ucontrol) |
| 602 | { |
| 603 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 604 | struct conexant_spec *spec = codec->spec; |
| 605 | int invert = (kcontrol->private_value >> 8) & 1; |
| 606 | hda_nid_t nid = kcontrol->private_value & 0xff; |
| 607 | unsigned int eapd; |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 608 | |
Takashi Iwai | 68ea7b2 | 2007-11-15 15:54:38 +0100 | [diff] [blame] | 609 | eapd = !!ucontrol->value.integer.value[0]; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 610 | if (invert) |
| 611 | eapd = !eapd; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 612 | if (eapd == spec->cur_eapd) |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 613 | return 0; |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 614 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 615 | spec->cur_eapd = eapd; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 616 | snd_hda_codec_write_cache(codec, nid, |
| 617 | 0, AC_VERB_SET_EAPD_BTLENABLE, |
| 618 | eapd ? 0x02 : 0x00); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 619 | return 1; |
| 620 | } |
| 621 | |
Takashi Iwai | 86d72bd | 2006-11-28 11:33:10 +0100 | [diff] [blame] | 622 | /* controls for test mode */ |
| 623 | #ifdef CONFIG_SND_DEBUG |
| 624 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 625 | #define CXT_EAPD_SWITCH(xname, nid, mask) \ |
| 626 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ |
| 627 | .info = cxt_eapd_info, \ |
| 628 | .get = cxt_eapd_get, \ |
| 629 | .put = cxt_eapd_put, \ |
| 630 | .private_value = nid | (mask<<16) } |
| 631 | |
| 632 | |
| 633 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 634 | static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, |
| 635 | struct snd_ctl_elem_info *uinfo) |
| 636 | { |
| 637 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 638 | struct conexant_spec *spec = codec->spec; |
| 639 | return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, |
| 640 | spec->num_channel_mode); |
| 641 | } |
| 642 | |
| 643 | static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, |
| 644 | struct snd_ctl_elem_value *ucontrol) |
| 645 | { |
| 646 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 647 | struct conexant_spec *spec = codec->spec; |
| 648 | return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, |
| 649 | spec->num_channel_mode, |
| 650 | spec->multiout.max_channels); |
| 651 | } |
| 652 | |
| 653 | static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, |
| 654 | struct snd_ctl_elem_value *ucontrol) |
| 655 | { |
| 656 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 657 | struct conexant_spec *spec = codec->spec; |
| 658 | int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, |
| 659 | spec->num_channel_mode, |
| 660 | &spec->multiout.max_channels); |
| 661 | if (err >= 0 && spec->need_dac_fix) |
| 662 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; |
| 663 | return err; |
| 664 | } |
| 665 | |
| 666 | #define CXT_PIN_MODE(xname, nid, dir) \ |
| 667 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ |
| 668 | .info = conexant_ch_mode_info, \ |
| 669 | .get = conexant_ch_mode_get, \ |
| 670 | .put = conexant_ch_mode_put, \ |
| 671 | .private_value = nid | (dir<<16) } |
| 672 | |
Takashi Iwai | 86d72bd | 2006-11-28 11:33:10 +0100 | [diff] [blame] | 673 | #endif /* CONFIG_SND_DEBUG */ |
| 674 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 675 | /* Conexant 5045 specific */ |
| 676 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 677 | static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; |
| 678 | static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; |
| 679 | static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; |
Takashi Iwai | cbef978 | 2008-02-22 18:36:46 +0100 | [diff] [blame] | 680 | #define CXT5045_SPDIF_OUT 0x18 |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 681 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 682 | static const struct hda_channel_mode cxt5045_modes[1] = { |
Tobin Davis | 5cd5752 | 2006-11-20 17:42:09 +0100 | [diff] [blame] | 683 | { 2, NULL }, |
| 684 | }; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 685 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 686 | static const struct hda_input_mux cxt5045_capture_source = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 687 | .num_items = 2, |
| 688 | .items = { |
Michael Karcher | 3edbbb9 | 2012-04-06 15:34:16 +0200 | [diff] [blame] | 689 | { "Internal Mic", 0x1 }, |
| 690 | { "Mic", 0x2 }, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 691 | } |
| 692 | }; |
| 693 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 694 | static const struct hda_input_mux cxt5045_capture_source_benq = { |
Michael Karcher | e6e03da | 2012-04-06 15:34:18 +0200 | [diff] [blame] | 695 | .num_items = 4, |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 696 | .items = { |
Michael Karcher | 3edbbb9 | 2012-04-06 15:34:16 +0200 | [diff] [blame] | 697 | { "Internal Mic", 0x1 }, |
| 698 | { "Mic", 0x2 }, |
| 699 | { "Line", 0x3 }, |
| 700 | { "Mixer", 0x0 }, |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 701 | } |
| 702 | }; |
| 703 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 704 | static const struct hda_input_mux cxt5045_capture_source_hp530 = { |
Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 705 | .num_items = 2, |
| 706 | .items = { |
Michael Karcher | 3edbbb9 | 2012-04-06 15:34:16 +0200 | [diff] [blame] | 707 | { "Mic", 0x1 }, |
| 708 | { "Internal Mic", 0x2 }, |
Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 709 | } |
| 710 | }; |
| 711 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 712 | /* turn on/off EAPD (+ mute HP) as a master switch */ |
| 713 | static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, |
| 714 | struct snd_ctl_elem_value *ucontrol) |
| 715 | { |
| 716 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 717 | struct conexant_spec *spec = codec->spec; |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 718 | unsigned int bits; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 719 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 720 | if (!cxt_eapd_put(kcontrol, ucontrol)) |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 721 | return 0; |
| 722 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 723 | /* toggle internal speakers mute depending of presence of |
| 724 | * the headphone jack |
| 725 | */ |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 726 | bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; |
| 727 | snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, |
| 728 | HDA_AMP_MUTE, bits); |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 729 | |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 730 | bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; |
| 731 | snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, |
| 732 | HDA_AMP_MUTE, bits); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 733 | return 1; |
| 734 | } |
| 735 | |
| 736 | /* bind volumes of both NID 0x10 and 0x11 */ |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 737 | static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = { |
Takashi Iwai | cca3b37 | 2007-08-10 17:12:15 +0200 | [diff] [blame] | 738 | .ops = &snd_hda_bind_vol, |
| 739 | .values = { |
| 740 | HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), |
| 741 | HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), |
| 742 | 0 |
| 743 | }, |
| 744 | }; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 745 | |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 746 | /* toggle input of built-in and mic jack appropriately */ |
| 747 | static void cxt5045_hp_automic(struct hda_codec *codec) |
| 748 | { |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 749 | static const struct hda_verb mic_jack_on[] = { |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 750 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, |
| 751 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, |
| 752 | {} |
| 753 | }; |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 754 | static const struct hda_verb mic_jack_off[] = { |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 755 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, |
| 756 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, |
| 757 | {} |
| 758 | }; |
| 759 | unsigned int present; |
| 760 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 761 | present = snd_hda_jack_detect(codec, 0x12); |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 762 | if (present) |
| 763 | snd_hda_sequence_write(codec, mic_jack_on); |
| 764 | else |
| 765 | snd_hda_sequence_write(codec, mic_jack_off); |
| 766 | } |
| 767 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 768 | |
| 769 | /* mute internal speaker if HP is plugged */ |
| 770 | static void cxt5045_hp_automute(struct hda_codec *codec) |
| 771 | { |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 772 | struct conexant_spec *spec = codec->spec; |
Tobin Davis | dd87da1 | 2007-02-26 16:07:42 +0100 | [diff] [blame] | 773 | unsigned int bits; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 774 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 775 | spec->hp_present = snd_hda_jack_detect(codec, 0x11); |
Tobin Davis | dd87da1 | 2007-02-26 16:07:42 +0100 | [diff] [blame] | 776 | |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 777 | bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; |
| 778 | snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, |
| 779 | HDA_AMP_MUTE, bits); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | /* unsolicited event for HP jack sensing */ |
| 783 | static void cxt5045_hp_unsol_event(struct hda_codec *codec, |
| 784 | unsigned int res) |
| 785 | { |
| 786 | res >>= 26; |
| 787 | switch (res) { |
| 788 | case CONEXANT_HP_EVENT: |
| 789 | cxt5045_hp_automute(codec); |
| 790 | break; |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 791 | case CONEXANT_MIC_EVENT: |
| 792 | cxt5045_hp_automic(codec); |
| 793 | break; |
| 794 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 798 | static const struct snd_kcontrol_new cxt5045_mixers[] = { |
Michael Karcher | cbf2d28 | 2012-04-06 15:34:17 +0200 | [diff] [blame] | 799 | HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT), |
| 800 | HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), |
Takashi Iwai | c8229c3 | 2007-10-19 08:06:21 +0200 | [diff] [blame] | 801 | HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), |
| 802 | HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), |
David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 803 | HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT), |
| 804 | HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT), |
David Henningsson | 8607f7c | 2010-12-20 14:43:54 +0100 | [diff] [blame] | 805 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT), |
| 806 | HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT), |
Takashi Iwai | cca3b37 | 2007-08-10 17:12:15 +0200 | [diff] [blame] | 807 | HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 808 | { |
| 809 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 810 | .name = "Master Playback Switch", |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 811 | .info = cxt_eapd_info, |
| 812 | .get = cxt_eapd_get, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 813 | .put = cxt5045_hp_master_sw_put, |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 814 | .private_value = 0x10, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 815 | }, |
| 816 | |
| 817 | {} |
| 818 | }; |
| 819 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 820 | static const struct snd_kcontrol_new cxt5045_benq_mixers[] = { |
Michael Karcher | 3edbbb9 | 2012-04-06 15:34:16 +0200 | [diff] [blame] | 821 | HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT), |
| 822 | HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT), |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 823 | |
| 824 | {} |
| 825 | }; |
| 826 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 827 | static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = { |
Michael Karcher | cbf2d28 | 2012-04-06 15:34:17 +0200 | [diff] [blame] | 828 | HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT), |
| 829 | HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), |
Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 830 | HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), |
| 831 | HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), |
David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 832 | HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT), |
| 833 | HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT), |
David Henningsson | 8607f7c | 2010-12-20 14:43:54 +0100 | [diff] [blame] | 834 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT), |
| 835 | HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT), |
Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 836 | HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), |
| 837 | { |
| 838 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 839 | .name = "Master Playback Switch", |
| 840 | .info = cxt_eapd_info, |
| 841 | .get = cxt_eapd_get, |
| 842 | .put = cxt5045_hp_master_sw_put, |
| 843 | .private_value = 0x10, |
| 844 | }, |
| 845 | |
| 846 | {} |
| 847 | }; |
| 848 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 849 | static const struct hda_verb cxt5045_init_verbs[] = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 850 | /* Line in, Mic */ |
Takashi Iwai | 4090dff | 2008-07-12 12:02:45 +0200 | [diff] [blame] | 851 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 852 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 853 | /* HP, Amp */ |
Takashi Iwai | c8229c3 | 2007-10-19 08:06:21 +0200 | [diff] [blame] | 854 | {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 855 | {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 856 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, |
| 857 | {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 858 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 859 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 860 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 861 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 862 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 863 | /* Record selector: Internal mic */ |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 864 | {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 865 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 866 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, |
| 867 | /* SPDIF route: PCM */ |
Takashi Iwai | cbef978 | 2008-02-22 18:36:46 +0100 | [diff] [blame] | 868 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 869 | { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 870 | /* EAPD */ |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 871 | {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 872 | { } /* end */ |
| 873 | }; |
| 874 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 875 | static const struct hda_verb cxt5045_benq_init_verbs[] = { |
David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 876 | /* Internal Mic, Mic */ |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 877 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, |
| 878 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, |
| 879 | /* Line In,HP, Amp */ |
| 880 | {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 881 | {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 882 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, |
| 883 | {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 884 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 885 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 886 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 887 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 888 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 889 | /* Record selector: Internal mic */ |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 890 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 891 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, |
| 892 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, |
| 893 | /* SPDIF route: PCM */ |
Takashi Iwai | cbef978 | 2008-02-22 18:36:46 +0100 | [diff] [blame] | 894 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 895 | {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 896 | /* EAPD */ |
| 897 | {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ |
| 898 | { } /* end */ |
| 899 | }; |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 900 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 901 | static const struct hda_verb cxt5045_hp_sense_init_verbs[] = { |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 902 | /* pin sensing on HP jack */ |
| 903 | {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, |
Takashi Iwai | d3091fa | 2007-03-28 15:11:53 +0200 | [diff] [blame] | 904 | { } /* end */ |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 905 | }; |
| 906 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 907 | static const struct hda_verb cxt5045_mic_sense_init_verbs[] = { |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 908 | /* pin sensing on HP jack */ |
| 909 | {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, |
Takashi Iwai | d3091fa | 2007-03-28 15:11:53 +0200 | [diff] [blame] | 910 | { } /* end */ |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 911 | }; |
| 912 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 913 | #ifdef CONFIG_SND_DEBUG |
| 914 | /* Test configuration for debugging, modelled after the ALC260 test |
| 915 | * configuration. |
| 916 | */ |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 917 | static const struct hda_input_mux cxt5045_test_capture_source = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 918 | .num_items = 5, |
| 919 | .items = { |
| 920 | { "MIXER", 0x0 }, |
| 921 | { "MIC1 pin", 0x1 }, |
| 922 | { "LINE1 pin", 0x2 }, |
| 923 | { "HP-OUT pin", 0x3 }, |
| 924 | { "CD pin", 0x4 }, |
| 925 | }, |
| 926 | }; |
| 927 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 928 | static const struct snd_kcontrol_new cxt5045_test_mixer[] = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 929 | |
| 930 | /* Output controls */ |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 931 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), |
| 932 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), |
Michael Karcher | 250f327 | 2012-04-06 15:34:20 +0200 | [diff] [blame] | 933 | HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT), |
| 934 | HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT), |
| 935 | HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT), |
| 936 | HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 937 | |
| 938 | /* Modes for retasking pin widgets */ |
| 939 | CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), |
| 940 | CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), |
| 941 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 942 | /* EAPD Switch Control */ |
| 943 | CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), |
| 944 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 945 | /* Loopback mixer controls */ |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 946 | |
Michael Karcher | 250f327 | 2012-04-06 15:34:20 +0200 | [diff] [blame] | 947 | HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT), |
| 948 | HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT), |
| 949 | HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT), |
| 950 | HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT), |
| 951 | HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT), |
| 952 | HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT), |
| 953 | HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT), |
| 954 | HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT), |
| 955 | HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT), |
| 956 | HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 957 | { |
| 958 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 959 | .name = "Input Source", |
| 960 | .info = conexant_mux_enum_info, |
| 961 | .get = conexant_mux_enum_get, |
| 962 | .put = conexant_mux_enum_put, |
| 963 | }, |
Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 964 | /* Audio input controls */ |
Michael Karcher | cbf2d28 | 2012-04-06 15:34:17 +0200 | [diff] [blame] | 965 | HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT), |
| 966 | HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 967 | { } /* end */ |
| 968 | }; |
| 969 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 970 | static const struct hda_verb cxt5045_test_init_verbs[] = { |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 971 | /* Set connections */ |
| 972 | { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, |
| 973 | { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, |
| 974 | { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 975 | /* Enable retasking pins as output, initially without power amp */ |
| 976 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 977 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 978 | |
| 979 | /* Disable digital (SPDIF) pins initially, but users can enable |
| 980 | * them via a mixer switch. In the case of SPDIF-out, this initverb |
| 981 | * payload also sets the generation to 0, output to be in "consumer" |
| 982 | * PCM format, copyright asserted, no pre-emphasis and no validity |
| 983 | * control. |
| 984 | */ |
Takashi Iwai | cbef978 | 2008-02-22 18:36:46 +0100 | [diff] [blame] | 985 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 986 | {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 987 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 988 | /* Unmute retasking pin widget output buffers since the default |
| 989 | * state appears to be output. As the pin mode is changed by the |
| 990 | * user the pin mode control will take care of enabling the pin's |
| 991 | * input/output buffers as needed. |
| 992 | */ |
| 993 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 994 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 995 | |
| 996 | /* Mute capture amp left and right */ |
| 997 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 998 | |
| 999 | /* Set ADC connection select to match default mixer setting (mic1 |
| 1000 | * pin) |
| 1001 | */ |
Michael Karcher | 250f327 | 2012-04-06 15:34:20 +0200 | [diff] [blame] | 1002 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, |
| 1003 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x01}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1004 | |
| 1005 | /* Mute all inputs to mixer widget (even unconnected ones) */ |
Michael Karcher | 250f327 | 2012-04-06 15:34:20 +0200 | [diff] [blame] | 1006 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */ |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1007 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ |
| 1008 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ |
| 1009 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ |
| 1010 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ |
| 1011 | |
| 1012 | { } |
| 1013 | }; |
| 1014 | #endif |
| 1015 | |
| 1016 | |
| 1017 | /* initialize jack-sensing, too */ |
| 1018 | static int cxt5045_init(struct hda_codec *codec) |
| 1019 | { |
| 1020 | conexant_init(codec); |
| 1021 | cxt5045_hp_automute(codec); |
| 1022 | return 0; |
| 1023 | } |
| 1024 | |
| 1025 | |
| 1026 | enum { |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1027 | CXT5045_LAPTOP_HPSENSE, |
| 1028 | CXT5045_LAPTOP_MICSENSE, |
| 1029 | CXT5045_LAPTOP_HPMICSENSE, |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 1030 | CXT5045_BENQ, |
Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 1031 | CXT5045_LAPTOP_HP530, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1032 | #ifdef CONFIG_SND_DEBUG |
| 1033 | CXT5045_TEST, |
| 1034 | #endif |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 1035 | CXT5045_AUTO, |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1036 | CXT5045_MODELS |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1037 | }; |
| 1038 | |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1039 | static const char * const cxt5045_models[CXT5045_MODELS] = { |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1040 | [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", |
| 1041 | [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", |
| 1042 | [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", |
| 1043 | [CXT5045_BENQ] = "benq", |
Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 1044 | [CXT5045_LAPTOP_HP530] = "laptop-hp530", |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1045 | #ifdef CONFIG_SND_DEBUG |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1046 | [CXT5045_TEST] = "test", |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1047 | #endif |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 1048 | [CXT5045_AUTO] = "auto", |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1049 | }; |
| 1050 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1051 | static const struct snd_pci_quirk cxt5045_cfg_tbl[] = { |
Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 1052 | SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), |
Takashi Iwai | 6a9dccd | 2008-07-01 14:52:05 +0200 | [diff] [blame] | 1053 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 1054 | SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1055 | SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), |
| 1056 | SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), |
Takashi Iwai | 9e46415 | 2008-07-12 12:05:25 +0200 | [diff] [blame] | 1057 | SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", |
| 1058 | CXT5045_LAPTOP_HPMICSENSE), |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1059 | SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), |
| 1060 | SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), |
| 1061 | SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), |
Takashi Iwai | dea0a50 | 2009-02-09 17:14:52 +0100 | [diff] [blame] | 1062 | SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", |
| 1063 | CXT5045_LAPTOP_HPMICSENSE), |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1064 | SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1065 | {} |
| 1066 | }; |
| 1067 | |
| 1068 | static int patch_cxt5045(struct hda_codec *codec) |
| 1069 | { |
| 1070 | struct conexant_spec *spec; |
| 1071 | int board_config; |
| 1072 | |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 1073 | board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, |
| 1074 | cxt5045_models, |
| 1075 | cxt5045_cfg_tbl); |
| 1076 | if (board_config < 0) |
Takashi Iwai | c82693d | 2011-06-28 14:17:17 +0200 | [diff] [blame] | 1077 | board_config = CXT5045_AUTO; /* model=auto as default */ |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 1078 | if (board_config == CXT5045_AUTO) |
| 1079 | return patch_conexant_auto(codec); |
| 1080 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1081 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 1082 | if (!spec) |
| 1083 | return -ENOMEM; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1084 | codec->spec = spec; |
Michael Karcher | 4f32456 | 2012-04-06 15:34:15 +0200 | [diff] [blame] | 1085 | codec->single_adc_amp = 1; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1086 | |
| 1087 | spec->multiout.max_channels = 2; |
| 1088 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); |
| 1089 | spec->multiout.dac_nids = cxt5045_dac_nids; |
| 1090 | spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; |
| 1091 | spec->num_adc_nids = 1; |
| 1092 | spec->adc_nids = cxt5045_adc_nids; |
| 1093 | spec->capsrc_nids = cxt5045_capsrc_nids; |
| 1094 | spec->input_mux = &cxt5045_capture_source; |
| 1095 | spec->num_mixers = 1; |
| 1096 | spec->mixers[0] = cxt5045_mixers; |
| 1097 | spec->num_init_verbs = 1; |
| 1098 | spec->init_verbs[0] = cxt5045_init_verbs; |
| 1099 | spec->spdif_route = 0; |
Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 1100 | spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); |
| 1101 | spec->channel_mode = cxt5045_modes; |
Tobin Davis | 5cd5752 | 2006-11-20 17:42:09 +0100 | [diff] [blame] | 1102 | |
Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 1103 | set_beep_amp(spec, 0x16, 0, 1); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1104 | |
| 1105 | codec->patch_ops = conexant_patch_ops; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1106 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1107 | switch (board_config) { |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1108 | case CXT5045_LAPTOP_HPSENSE: |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1109 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1110 | spec->input_mux = &cxt5045_capture_source; |
| 1111 | spec->num_init_verbs = 2; |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1112 | spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; |
| 1113 | spec->mixers[0] = cxt5045_mixers; |
| 1114 | codec->patch_ops.init = cxt5045_init; |
| 1115 | break; |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1116 | case CXT5045_LAPTOP_MICSENSE: |
Takashi Iwai | 86376df | 2008-07-12 12:04:05 +0200 | [diff] [blame] | 1117 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1118 | spec->input_mux = &cxt5045_capture_source; |
| 1119 | spec->num_init_verbs = 2; |
| 1120 | spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1121 | spec->mixers[0] = cxt5045_mixers; |
| 1122 | codec->patch_ops.init = cxt5045_init; |
| 1123 | break; |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1124 | default: |
| 1125 | case CXT5045_LAPTOP_HPMICSENSE: |
| 1126 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; |
| 1127 | spec->input_mux = &cxt5045_capture_source; |
| 1128 | spec->num_init_verbs = 3; |
| 1129 | spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; |
| 1130 | spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; |
| 1131 | spec->mixers[0] = cxt5045_mixers; |
| 1132 | codec->patch_ops.init = cxt5045_init; |
| 1133 | break; |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 1134 | case CXT5045_BENQ: |
| 1135 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; |
| 1136 | spec->input_mux = &cxt5045_capture_source_benq; |
| 1137 | spec->num_init_verbs = 1; |
| 1138 | spec->init_verbs[0] = cxt5045_benq_init_verbs; |
| 1139 | spec->mixers[0] = cxt5045_mixers; |
| 1140 | spec->mixers[1] = cxt5045_benq_mixers; |
| 1141 | spec->num_mixers = 2; |
| 1142 | codec->patch_ops.init = cxt5045_init; |
| 1143 | break; |
Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 1144 | case CXT5045_LAPTOP_HP530: |
| 1145 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; |
| 1146 | spec->input_mux = &cxt5045_capture_source_hp530; |
| 1147 | spec->num_init_verbs = 2; |
| 1148 | spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; |
| 1149 | spec->mixers[0] = cxt5045_mixers_hp530; |
| 1150 | codec->patch_ops.init = cxt5045_init; |
| 1151 | break; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1152 | #ifdef CONFIG_SND_DEBUG |
| 1153 | case CXT5045_TEST: |
| 1154 | spec->input_mux = &cxt5045_test_capture_source; |
| 1155 | spec->mixers[0] = cxt5045_test_mixer; |
| 1156 | spec->init_verbs[0] = cxt5045_test_init_verbs; |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1157 | break; |
| 1158 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1159 | #endif |
| 1160 | } |
Takashi Iwai | 48ecb7e | 2007-12-17 14:32:49 +0100 | [diff] [blame] | 1161 | |
Takashi Iwai | 031005f | 2008-06-26 14:49:58 +0200 | [diff] [blame] | 1162 | switch (codec->subsystem_id >> 16) { |
| 1163 | case 0x103c: |
Daniel T Chen | 8f0f5ff | 2010-04-28 18:00:11 -0400 | [diff] [blame] | 1164 | case 0x1631: |
Daniel T Chen | 0b587fc | 2009-11-25 18:27:20 -0500 | [diff] [blame] | 1165 | case 0x1734: |
Daniel T Chen | 0ebf9e3 | 2010-05-10 21:50:04 +0200 | [diff] [blame] | 1166 | case 0x17aa: |
| 1167 | /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have |
| 1168 | * really bad sound over 0dB on NID 0x17. Fix max PCM level to |
| 1169 | * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) |
Takashi Iwai | 031005f | 2008-06-26 14:49:58 +0200 | [diff] [blame] | 1170 | */ |
| 1171 | snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, |
| 1172 | (0x14 << AC_AMPCAP_OFFSET_SHIFT) | |
| 1173 | (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 1174 | (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 1175 | (1 << AC_AMPCAP_MUTE_SHIFT)); |
| 1176 | break; |
| 1177 | } |
Takashi Iwai | 48ecb7e | 2007-12-17 14:32:49 +0100 | [diff] [blame] | 1178 | |
Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 1179 | if (spec->beep_amp) |
| 1180 | snd_hda_attach_beep_device(codec, spec->beep_amp); |
| 1181 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | |
| 1186 | /* Conexant 5047 specific */ |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1187 | #define CXT5047_SPDIF_OUT 0x11 |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1188 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1189 | static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ |
| 1190 | static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; |
| 1191 | static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1192 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1193 | static const struct hda_channel_mode cxt5047_modes[1] = { |
Tobin Davis | 5cd5752 | 2006-11-20 17:42:09 +0100 | [diff] [blame] | 1194 | { 2, NULL }, |
| 1195 | }; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1196 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1197 | static const struct hda_input_mux cxt5047_toshiba_capture_source = { |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1198 | .num_items = 2, |
| 1199 | .items = { |
| 1200 | { "ExtMic", 0x2 }, |
| 1201 | { "Line-In", 0x1 }, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1202 | } |
| 1203 | }; |
| 1204 | |
| 1205 | /* turn on/off EAPD (+ mute HP) as a master switch */ |
| 1206 | static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, |
| 1207 | struct snd_ctl_elem_value *ucontrol) |
| 1208 | { |
| 1209 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1210 | struct conexant_spec *spec = codec->spec; |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1211 | unsigned int bits; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1212 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1213 | if (!cxt_eapd_put(kcontrol, ucontrol)) |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1214 | return 0; |
| 1215 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1216 | /* toggle internal speakers mute depending of presence of |
| 1217 | * the headphone jack |
| 1218 | */ |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1219 | bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; |
Takashi Iwai | 3b7523f | 2009-03-12 16:45:01 +0100 | [diff] [blame] | 1220 | /* NOTE: Conexat codec needs the index for *OUTPUT* amp of |
| 1221 | * pin widgets unlike other codecs. In this case, we need to |
| 1222 | * set index 0x01 for the volume from the mixer amp 0x19. |
| 1223 | */ |
Gregorio Guidi | 5d75bc5 | 2009-03-12 16:41:51 +0100 | [diff] [blame] | 1224 | snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1225 | HDA_AMP_MUTE, bits); |
| 1226 | bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; |
| 1227 | snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, |
| 1228 | HDA_AMP_MUTE, bits); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1229 | return 1; |
| 1230 | } |
| 1231 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1232 | /* mute internal speaker if HP is plugged */ |
| 1233 | static void cxt5047_hp_automute(struct hda_codec *codec) |
| 1234 | { |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1235 | struct conexant_spec *spec = codec->spec; |
Tobin Davis | dd87da1 | 2007-02-26 16:07:42 +0100 | [diff] [blame] | 1236 | unsigned int bits; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1237 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1238 | spec->hp_present = snd_hda_jack_detect(codec, 0x13); |
Tobin Davis | dd87da1 | 2007-02-26 16:07:42 +0100 | [diff] [blame] | 1239 | |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1240 | bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; |
Takashi Iwai | 3b7523f | 2009-03-12 16:45:01 +0100 | [diff] [blame] | 1241 | /* See the note in cxt5047_hp_master_sw_put */ |
Gregorio Guidi | 5d75bc5 | 2009-03-12 16:41:51 +0100 | [diff] [blame] | 1242 | snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1243 | HDA_AMP_MUTE, bits); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | /* toggle input of built-in and mic jack appropriately */ |
| 1247 | static void cxt5047_hp_automic(struct hda_codec *codec) |
| 1248 | { |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1249 | static const struct hda_verb mic_jack_on[] = { |
Marc Boucher | 9f113e0 | 2008-01-22 15:18:08 +0100 | [diff] [blame] | 1250 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, |
| 1251 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1252 | {} |
| 1253 | }; |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1254 | static const struct hda_verb mic_jack_off[] = { |
Marc Boucher | 9f113e0 | 2008-01-22 15:18:08 +0100 | [diff] [blame] | 1255 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, |
| 1256 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1257 | {} |
| 1258 | }; |
| 1259 | unsigned int present; |
| 1260 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1261 | present = snd_hda_jack_detect(codec, 0x15); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1262 | if (present) |
| 1263 | snd_hda_sequence_write(codec, mic_jack_on); |
| 1264 | else |
| 1265 | snd_hda_sequence_write(codec, mic_jack_off); |
| 1266 | } |
| 1267 | |
| 1268 | /* unsolicited event for HP jack sensing */ |
| 1269 | static void cxt5047_hp_unsol_event(struct hda_codec *codec, |
| 1270 | unsigned int res) |
| 1271 | { |
Marc Boucher | 9f113e0 | 2008-01-22 15:18:08 +0100 | [diff] [blame] | 1272 | switch (res >> 26) { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1273 | case CONEXANT_HP_EVENT: |
| 1274 | cxt5047_hp_automute(codec); |
| 1275 | break; |
| 1276 | case CONEXANT_MIC_EVENT: |
| 1277 | cxt5047_hp_automic(codec); |
| 1278 | break; |
| 1279 | } |
| 1280 | } |
| 1281 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1282 | static const struct snd_kcontrol_new cxt5047_base_mixers[] = { |
Takashi Iwai | df481e4 | 2009-03-10 15:35:35 +0100 | [diff] [blame] | 1283 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), |
| 1284 | HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), |
David Henningsson | 5f99f86 | 2011-01-04 15:24:24 +0100 | [diff] [blame] | 1285 | HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1286 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), |
| 1287 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), |
| 1288 | HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), |
| 1289 | HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1290 | { |
| 1291 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1292 | .name = "Master Playback Switch", |
| 1293 | .info = cxt_eapd_info, |
| 1294 | .get = cxt_eapd_get, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1295 | .put = cxt5047_hp_master_sw_put, |
| 1296 | .private_value = 0x13, |
| 1297 | }, |
| 1298 | |
| 1299 | {} |
| 1300 | }; |
| 1301 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1302 | static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { |
Takashi Iwai | 3b7523f | 2009-03-12 16:45:01 +0100 | [diff] [blame] | 1303 | /* See the note in cxt5047_hp_master_sw_put */ |
Gregorio Guidi | 5d75bc5 | 2009-03-12 16:41:51 +0100 | [diff] [blame] | 1304 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), |
Takashi Iwai | df481e4 | 2009-03-10 15:35:35 +0100 | [diff] [blame] | 1305 | HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), |
| 1306 | {} |
| 1307 | }; |
| 1308 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1309 | static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1310 | HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1311 | { } /* end */ |
| 1312 | }; |
| 1313 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1314 | static const struct hda_verb cxt5047_init_verbs[] = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1315 | /* Line in, Mic, Built-in Mic */ |
| 1316 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, |
| 1317 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, |
| 1318 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1319 | /* HP, Speaker */ |
Tobin Davis | b7589ce | 2007-04-24 17:56:55 +0200 | [diff] [blame] | 1320 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
Takashi Iwai | 5b3a744 | 2009-03-10 15:10:55 +0100 | [diff] [blame] | 1321 | {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ |
| 1322 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1323 | /* Record selector: Mic */ |
| 1324 | {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, |
| 1325 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, |
| 1326 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, |
| 1327 | {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1328 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, |
| 1329 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, |
| 1330 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, |
| 1331 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1332 | /* SPDIF route: PCM */ |
| 1333 | { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1334 | /* Enable unsolicited events */ |
| 1335 | {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, |
| 1336 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1337 | { } /* end */ |
| 1338 | }; |
| 1339 | |
| 1340 | /* configuration for Toshiba Laptops */ |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1341 | static const struct hda_verb cxt5047_toshiba_init_verbs[] = { |
Takashi Iwai | 3b62886 | 2009-03-10 14:53:54 +0100 | [diff] [blame] | 1342 | {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1343 | {} |
| 1344 | }; |
| 1345 | |
| 1346 | /* Test configuration for debugging, modelled after the ALC260 test |
| 1347 | * configuration. |
| 1348 | */ |
| 1349 | #ifdef CONFIG_SND_DEBUG |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1350 | static const struct hda_input_mux cxt5047_test_capture_source = { |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1351 | .num_items = 4, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1352 | .items = { |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1353 | { "LINE1 pin", 0x0 }, |
| 1354 | { "MIC1 pin", 0x1 }, |
| 1355 | { "MIC2 pin", 0x2 }, |
| 1356 | { "CD pin", 0x3 }, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1357 | }, |
| 1358 | }; |
| 1359 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1360 | static const struct snd_kcontrol_new cxt5047_test_mixer[] = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1361 | |
| 1362 | /* Output only controls */ |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1363 | HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), |
| 1364 | HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), |
| 1365 | HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), |
| 1366 | HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1367 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), |
| 1368 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), |
| 1369 | HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), |
| 1370 | HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1371 | HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), |
| 1372 | HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), |
| 1373 | HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), |
| 1374 | HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1375 | |
| 1376 | /* Modes for retasking pin widgets */ |
| 1377 | CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), |
| 1378 | CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), |
| 1379 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1380 | /* EAPD Switch Control */ |
| 1381 | CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), |
| 1382 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1383 | /* Loopback mixer controls */ |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1384 | HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), |
| 1385 | HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), |
| 1386 | HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), |
| 1387 | HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), |
| 1388 | HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), |
| 1389 | HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), |
| 1390 | HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), |
| 1391 | HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1392 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1393 | HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), |
| 1394 | HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), |
| 1395 | HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), |
| 1396 | HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), |
| 1397 | HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), |
| 1398 | HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), |
| 1399 | HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), |
| 1400 | HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1401 | { |
| 1402 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1403 | .name = "Input Source", |
| 1404 | .info = conexant_mux_enum_info, |
| 1405 | .get = conexant_mux_enum_get, |
| 1406 | .put = conexant_mux_enum_put, |
| 1407 | }, |
Takashi Iwai | 854206b | 2009-11-30 18:22:04 +0100 | [diff] [blame] | 1408 | HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), |
Marc Boucher | 9f113e0 | 2008-01-22 15:18:08 +0100 | [diff] [blame] | 1409 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1410 | { } /* end */ |
| 1411 | }; |
| 1412 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1413 | static const struct hda_verb cxt5047_test_init_verbs[] = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1414 | /* Enable retasking pins as output, initially without power amp */ |
| 1415 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 1416 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 1417 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 1418 | |
| 1419 | /* Disable digital (SPDIF) pins initially, but users can enable |
| 1420 | * them via a mixer switch. In the case of SPDIF-out, this initverb |
| 1421 | * payload also sets the generation to 0, output to be in "consumer" |
| 1422 | * PCM format, copyright asserted, no pre-emphasis and no validity |
| 1423 | * control. |
| 1424 | */ |
| 1425 | {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, |
| 1426 | |
| 1427 | /* Ensure mic1, mic2, line1 pin widgets take input from the |
| 1428 | * OUT1 sum bus when acting as an output. |
| 1429 | */ |
| 1430 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, |
| 1431 | {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, |
| 1432 | |
| 1433 | /* Start with output sum widgets muted and their output gains at min */ |
| 1434 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 1435 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 1436 | |
| 1437 | /* Unmute retasking pin widget output buffers since the default |
| 1438 | * state appears to be output. As the pin mode is changed by the |
| 1439 | * user the pin mode control will take care of enabling the pin's |
| 1440 | * input/output buffers as needed. |
| 1441 | */ |
| 1442 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 1443 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 1444 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 1445 | |
| 1446 | /* Mute capture amp left and right */ |
| 1447 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 1448 | |
| 1449 | /* Set ADC connection select to match default mixer setting (mic1 |
| 1450 | * pin) |
| 1451 | */ |
| 1452 | {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, |
| 1453 | |
| 1454 | /* Mute all inputs to mixer widget (even unconnected ones) */ |
| 1455 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ |
| 1456 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ |
| 1457 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ |
| 1458 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ |
| 1459 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ |
| 1460 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ |
| 1461 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ |
| 1462 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ |
| 1463 | |
| 1464 | { } |
| 1465 | }; |
| 1466 | #endif |
| 1467 | |
| 1468 | |
| 1469 | /* initialize jack-sensing, too */ |
| 1470 | static int cxt5047_hp_init(struct hda_codec *codec) |
| 1471 | { |
| 1472 | conexant_init(codec); |
| 1473 | cxt5047_hp_automute(codec); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1474 | return 0; |
| 1475 | } |
| 1476 | |
| 1477 | |
| 1478 | enum { |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1479 | CXT5047_LAPTOP, /* Laptops w/o EAPD support */ |
| 1480 | CXT5047_LAPTOP_HP, /* Some HP laptops */ |
| 1481 | CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1482 | #ifdef CONFIG_SND_DEBUG |
| 1483 | CXT5047_TEST, |
| 1484 | #endif |
Takashi Iwai | fa5dadc | 2011-05-13 19:33:18 +0200 | [diff] [blame] | 1485 | CXT5047_AUTO, |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1486 | CXT5047_MODELS |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1487 | }; |
| 1488 | |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1489 | static const char * const cxt5047_models[CXT5047_MODELS] = { |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1490 | [CXT5047_LAPTOP] = "laptop", |
| 1491 | [CXT5047_LAPTOP_HP] = "laptop-hp", |
| 1492 | [CXT5047_LAPTOP_EAPD] = "laptop-eapd", |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1493 | #ifdef CONFIG_SND_DEBUG |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1494 | [CXT5047_TEST] = "test", |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1495 | #endif |
Takashi Iwai | fa5dadc | 2011-05-13 19:33:18 +0200 | [diff] [blame] | 1496 | [CXT5047_AUTO] = "auto", |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1497 | }; |
| 1498 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1499 | static const struct snd_pci_quirk cxt5047_cfg_tbl[] = { |
Takashi Iwai | ac3e374 | 2007-12-17 17:14:18 +0100 | [diff] [blame] | 1500 | SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), |
Takashi Iwai | dea0a50 | 2009-02-09 17:14:52 +0100 | [diff] [blame] | 1501 | SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", |
| 1502 | CXT5047_LAPTOP), |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1503 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1504 | {} |
| 1505 | }; |
| 1506 | |
| 1507 | static int patch_cxt5047(struct hda_codec *codec) |
| 1508 | { |
| 1509 | struct conexant_spec *spec; |
| 1510 | int board_config; |
| 1511 | |
Takashi Iwai | fa5dadc | 2011-05-13 19:33:18 +0200 | [diff] [blame] | 1512 | board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, |
| 1513 | cxt5047_models, |
| 1514 | cxt5047_cfg_tbl); |
Takashi Iwai | fa5dadc | 2011-05-13 19:33:18 +0200 | [diff] [blame] | 1515 | if (board_config < 0) |
Takashi Iwai | c82693d | 2011-06-28 14:17:17 +0200 | [diff] [blame] | 1516 | board_config = CXT5047_AUTO; /* model=auto as default */ |
Takashi Iwai | fa5dadc | 2011-05-13 19:33:18 +0200 | [diff] [blame] | 1517 | if (board_config == CXT5047_AUTO) |
| 1518 | return patch_conexant_auto(codec); |
| 1519 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1520 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 1521 | if (!spec) |
| 1522 | return -ENOMEM; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1523 | codec->spec = spec; |
Takashi Iwai | 9421f95 | 2009-03-12 17:06:07 +0100 | [diff] [blame] | 1524 | codec->pin_amp_workaround = 1; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1525 | |
| 1526 | spec->multiout.max_channels = 2; |
| 1527 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); |
| 1528 | spec->multiout.dac_nids = cxt5047_dac_nids; |
| 1529 | spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; |
| 1530 | spec->num_adc_nids = 1; |
| 1531 | spec->adc_nids = cxt5047_adc_nids; |
| 1532 | spec->capsrc_nids = cxt5047_capsrc_nids; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1533 | spec->num_mixers = 1; |
Takashi Iwai | df481e4 | 2009-03-10 15:35:35 +0100 | [diff] [blame] | 1534 | spec->mixers[0] = cxt5047_base_mixers; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1535 | spec->num_init_verbs = 1; |
| 1536 | spec->init_verbs[0] = cxt5047_init_verbs; |
| 1537 | spec->spdif_route = 0; |
Tobin Davis | 5cd5752 | 2006-11-20 17:42:09 +0100 | [diff] [blame] | 1538 | spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), |
| 1539 | spec->channel_mode = cxt5047_modes, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1540 | |
| 1541 | codec->patch_ops = conexant_patch_ops; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1542 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1543 | switch (board_config) { |
| 1544 | case CXT5047_LAPTOP: |
Takashi Iwai | df481e4 | 2009-03-10 15:35:35 +0100 | [diff] [blame] | 1545 | spec->num_mixers = 2; |
| 1546 | spec->mixers[1] = cxt5047_hp_spk_mixers; |
| 1547 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1548 | break; |
| 1549 | case CXT5047_LAPTOP_HP: |
Takashi Iwai | df481e4 | 2009-03-10 15:35:35 +0100 | [diff] [blame] | 1550 | spec->num_mixers = 2; |
| 1551 | spec->mixers[1] = cxt5047_hp_only_mixers; |
Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 1552 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1553 | codec->patch_ops.init = cxt5047_hp_init; |
| 1554 | break; |
| 1555 | case CXT5047_LAPTOP_EAPD: |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1556 | spec->input_mux = &cxt5047_toshiba_capture_source; |
Takashi Iwai | df481e4 | 2009-03-10 15:35:35 +0100 | [diff] [blame] | 1557 | spec->num_mixers = 2; |
| 1558 | spec->mixers[1] = cxt5047_hp_spk_mixers; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1559 | spec->num_init_verbs = 2; |
| 1560 | spec->init_verbs[1] = cxt5047_toshiba_init_verbs; |
Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 1561 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1562 | break; |
| 1563 | #ifdef CONFIG_SND_DEBUG |
| 1564 | case CXT5047_TEST: |
| 1565 | spec->input_mux = &cxt5047_test_capture_source; |
| 1566 | spec->mixers[0] = cxt5047_test_mixer; |
| 1567 | spec->init_verbs[0] = cxt5047_test_init_verbs; |
Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 1568 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1569 | #endif |
| 1570 | } |
Takashi Iwai | dd5746a | 2009-03-10 14:30:40 +0100 | [diff] [blame] | 1571 | spec->vmaster_nid = 0x13; |
Daniel T Chen | 025f206 | 2010-03-21 18:34:43 -0400 | [diff] [blame] | 1572 | |
| 1573 | switch (codec->subsystem_id >> 16) { |
| 1574 | case 0x103c: |
| 1575 | /* HP laptops have really bad sound over 0 dB on NID 0x10. |
| 1576 | * Fix max PCM level to 0 dB (originally it has 0x1e steps |
| 1577 | * with 0 dB offset 0x17) |
| 1578 | */ |
| 1579 | snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, |
| 1580 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | |
| 1581 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 1582 | (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 1583 | (1 << AC_AMPCAP_MUTE_SHIFT)); |
| 1584 | break; |
| 1585 | } |
| 1586 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1587 | return 0; |
| 1588 | } |
| 1589 | |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1590 | /* Conexant 5051 specific */ |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1591 | static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; |
| 1592 | static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1593 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1594 | static const struct hda_channel_mode cxt5051_modes[1] = { |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1595 | { 2, NULL }, |
| 1596 | }; |
| 1597 | |
| 1598 | static void cxt5051_update_speaker(struct hda_codec *codec) |
| 1599 | { |
| 1600 | struct conexant_spec *spec = codec->spec; |
| 1601 | unsigned int pinctl; |
Takashi Iwai | 23d2df5 | 2010-01-24 11:19:27 +0100 | [diff] [blame] | 1602 | /* headphone pin */ |
| 1603 | pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; |
| 1604 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1605 | pinctl); |
| 1606 | /* speaker pin */ |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1607 | pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; |
| 1608 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1609 | pinctl); |
Justin P. Mattock | a80581d | 2012-02-11 05:55:58 -0800 | [diff] [blame] | 1610 | /* on ideapad there is an additional speaker (subwoofer) to mute */ |
Herton Ronaldo Krzesinski | f7154de2 | 2010-06-17 14:15:06 -0300 | [diff] [blame] | 1611 | if (spec->ideapad) |
| 1612 | snd_hda_codec_write(codec, 0x1b, 0, |
| 1613 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1614 | pinctl); |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | /* turn on/off EAPD (+ mute HP) as a master switch */ |
| 1618 | static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, |
| 1619 | struct snd_ctl_elem_value *ucontrol) |
| 1620 | { |
| 1621 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1622 | |
| 1623 | if (!cxt_eapd_put(kcontrol, ucontrol)) |
| 1624 | return 0; |
| 1625 | cxt5051_update_speaker(codec); |
| 1626 | return 1; |
| 1627 | } |
| 1628 | |
| 1629 | /* toggle input of built-in and mic jack appropriately */ |
| 1630 | static void cxt5051_portb_automic(struct hda_codec *codec) |
| 1631 | { |
Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1632 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1633 | unsigned int present; |
| 1634 | |
Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1635 | if (!(spec->auto_mic & AUTO_MIC_PORTB)) |
Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1636 | return; |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1637 | present = snd_hda_jack_detect(codec, 0x17); |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1638 | snd_hda_codec_write(codec, 0x14, 0, |
| 1639 | AC_VERB_SET_CONNECT_SEL, |
| 1640 | present ? 0x01 : 0x00); |
| 1641 | } |
| 1642 | |
| 1643 | /* switch the current ADC according to the jack state */ |
| 1644 | static void cxt5051_portc_automic(struct hda_codec *codec) |
| 1645 | { |
| 1646 | struct conexant_spec *spec = codec->spec; |
| 1647 | unsigned int present; |
| 1648 | hda_nid_t new_adc; |
| 1649 | |
Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1650 | if (!(spec->auto_mic & AUTO_MIC_PORTC)) |
Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1651 | return; |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1652 | present = snd_hda_jack_detect(codec, 0x18); |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1653 | if (present) |
| 1654 | spec->cur_adc_idx = 1; |
| 1655 | else |
| 1656 | spec->cur_adc_idx = 0; |
| 1657 | new_adc = spec->adc_nids[spec->cur_adc_idx]; |
| 1658 | if (spec->cur_adc && spec->cur_adc != new_adc) { |
| 1659 | /* stream is running, let's swap the current ADC */ |
Takashi Iwai | f0cea79 | 2010-08-13 11:56:53 +0200 | [diff] [blame] | 1660 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1661 | spec->cur_adc = new_adc; |
| 1662 | snd_hda_codec_setup_stream(codec, new_adc, |
| 1663 | spec->cur_adc_stream_tag, 0, |
| 1664 | spec->cur_adc_format); |
| 1665 | } |
| 1666 | } |
| 1667 | |
| 1668 | /* mute internal speaker if HP is plugged */ |
| 1669 | static void cxt5051_hp_automute(struct hda_codec *codec) |
| 1670 | { |
| 1671 | struct conexant_spec *spec = codec->spec; |
| 1672 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1673 | spec->hp_present = snd_hda_jack_detect(codec, 0x16); |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1674 | cxt5051_update_speaker(codec); |
| 1675 | } |
| 1676 | |
| 1677 | /* unsolicited event for HP jack sensing */ |
| 1678 | static void cxt5051_hp_unsol_event(struct hda_codec *codec, |
| 1679 | unsigned int res) |
| 1680 | { |
| 1681 | switch (res >> 26) { |
| 1682 | case CONEXANT_HP_EVENT: |
| 1683 | cxt5051_hp_automute(codec); |
| 1684 | break; |
| 1685 | case CXT5051_PORTB_EVENT: |
| 1686 | cxt5051_portb_automic(codec); |
| 1687 | break; |
| 1688 | case CXT5051_PORTC_EVENT: |
| 1689 | cxt5051_portc_automic(codec); |
| 1690 | break; |
| 1691 | } |
| 1692 | } |
| 1693 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1694 | static const struct snd_kcontrol_new cxt5051_playback_mixers[] = { |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1695 | HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), |
| 1696 | { |
| 1697 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1698 | .name = "Master Playback Switch", |
| 1699 | .info = cxt_eapd_info, |
| 1700 | .get = cxt_eapd_get, |
| 1701 | .put = cxt5051_hp_master_sw_put, |
| 1702 | .private_value = 0x1a, |
| 1703 | }, |
Takashi Iwai | 2c7a3fb | 2010-01-24 10:47:02 +0100 | [diff] [blame] | 1704 | {} |
| 1705 | }; |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1706 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1707 | static const struct snd_kcontrol_new cxt5051_capture_mixers[] = { |
Takashi Iwai | 2c7a3fb | 2010-01-24 10:47:02 +0100 | [diff] [blame] | 1708 | HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), |
| 1709 | HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), |
David Henningsson | 8607f7c | 2010-12-20 14:43:54 +0100 | [diff] [blame] | 1710 | HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), |
| 1711 | HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), |
Takashi Iwai | 2c7a3fb | 2010-01-24 10:47:02 +0100 | [diff] [blame] | 1712 | HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), |
| 1713 | HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1714 | {} |
| 1715 | }; |
| 1716 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1717 | static const struct snd_kcontrol_new cxt5051_hp_mixers[] = { |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1718 | HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), |
| 1719 | HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), |
David Henningsson | 8607f7c | 2010-12-20 14:43:54 +0100 | [diff] [blame] | 1720 | HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT), |
| 1721 | HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT), |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1722 | {} |
| 1723 | }; |
| 1724 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1725 | static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { |
Takashi Iwai | 4e4ac60 | 2010-01-23 22:29:54 +0100 | [diff] [blame] | 1726 | HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), |
| 1727 | HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), |
Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1728 | {} |
| 1729 | }; |
| 1730 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1731 | static const struct snd_kcontrol_new cxt5051_f700_mixers[] = { |
Takashi Iwai | 5f6c3de | 2010-01-23 22:19:29 +0100 | [diff] [blame] | 1732 | HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), |
| 1733 | HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), |
Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1734 | {} |
| 1735 | }; |
| 1736 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1737 | static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { |
Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1738 | HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), |
| 1739 | HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), |
David Henningsson | 8607f7c | 2010-12-20 14:43:54 +0100 | [diff] [blame] | 1740 | HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), |
| 1741 | HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), |
Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1742 | {} |
| 1743 | }; |
| 1744 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1745 | static const struct hda_verb cxt5051_init_verbs[] = { |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1746 | /* Line in, Mic */ |
| 1747 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, |
| 1748 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, |
| 1749 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, |
| 1750 | {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, |
| 1751 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, |
| 1752 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, |
| 1753 | /* SPK */ |
| 1754 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 1755 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, |
| 1756 | /* HP, Amp */ |
| 1757 | {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, |
| 1758 | {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, |
| 1759 | /* DAC1 */ |
| 1760 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 1761 | /* Record selector: Internal mic */ |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1762 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, |
| 1763 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, |
| 1764 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, |
| 1765 | /* SPDIF route: PCM */ |
Pierre-Louis Bossart | 1965c44 | 2010-05-06 16:37:03 -0500 | [diff] [blame] | 1766 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1767 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 1768 | /* EAPD */ |
| 1769 | {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ |
| 1770 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1771 | { } /* end */ |
| 1772 | }; |
| 1773 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1774 | static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { |
Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1775 | /* Line in, Mic */ |
| 1776 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, |
| 1777 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, |
| 1778 | {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, |
| 1779 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, |
| 1780 | /* SPK */ |
| 1781 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 1782 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, |
| 1783 | /* HP, Amp */ |
| 1784 | {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, |
| 1785 | {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, |
| 1786 | /* DAC1 */ |
| 1787 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 1788 | /* Record selector: Internal mic */ |
Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1789 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, |
| 1790 | {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 1791 | /* SPDIF route: PCM */ |
| 1792 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 1793 | /* EAPD */ |
| 1794 | {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ |
| 1795 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, |
Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1796 | { } /* end */ |
| 1797 | }; |
| 1798 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1799 | static const struct hda_verb cxt5051_f700_init_verbs[] = { |
Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1800 | /* Line in, Mic */ |
Takashi Iwai | 30ed7ed | 2010-01-28 17:11:45 +0100 | [diff] [blame] | 1801 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, |
Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1802 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, |
| 1803 | {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, |
| 1804 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, |
| 1805 | /* SPK */ |
| 1806 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 1807 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, |
| 1808 | /* HP, Amp */ |
| 1809 | {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, |
| 1810 | {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, |
| 1811 | /* DAC1 */ |
| 1812 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 1813 | /* Record selector: Internal mic */ |
Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1814 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, |
| 1815 | {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 1816 | /* SPDIF route: PCM */ |
| 1817 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 1818 | /* EAPD */ |
| 1819 | {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ |
| 1820 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, |
Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1821 | { } /* end */ |
| 1822 | }; |
| 1823 | |
Takashi Iwai | 6953e55 | 2010-01-24 11:00:27 +0100 | [diff] [blame] | 1824 | static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, |
| 1825 | unsigned int event) |
| 1826 | { |
| 1827 | snd_hda_codec_write(codec, nid, 0, |
| 1828 | AC_VERB_SET_UNSOLICITED_ENABLE, |
| 1829 | AC_USRSP_EN | event); |
Takashi Iwai | 6953e55 | 2010-01-24 11:00:27 +0100 | [diff] [blame] | 1830 | } |
| 1831 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1832 | static const struct hda_verb cxt5051_ideapad_init_verbs[] = { |
Herton Ronaldo Krzesinski | f7154de2 | 2010-06-17 14:15:06 -0300 | [diff] [blame] | 1833 | /* Subwoofer */ |
| 1834 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 1835 | {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, |
| 1836 | { } /* end */ |
| 1837 | }; |
| 1838 | |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1839 | /* initialize jack-sensing, too */ |
| 1840 | static int cxt5051_init(struct hda_codec *codec) |
| 1841 | { |
Takashi Iwai | 6953e55 | 2010-01-24 11:00:27 +0100 | [diff] [blame] | 1842 | struct conexant_spec *spec = codec->spec; |
| 1843 | |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1844 | conexant_init(codec); |
Takashi Iwai | 6953e55 | 2010-01-24 11:00:27 +0100 | [diff] [blame] | 1845 | |
| 1846 | if (spec->auto_mic & AUTO_MIC_PORTB) |
| 1847 | cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); |
| 1848 | if (spec->auto_mic & AUTO_MIC_PORTC) |
| 1849 | cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); |
| 1850 | |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1851 | if (codec->patch_ops.unsol_event) { |
| 1852 | cxt5051_hp_automute(codec); |
| 1853 | cxt5051_portb_automic(codec); |
| 1854 | cxt5051_portc_automic(codec); |
| 1855 | } |
| 1856 | return 0; |
| 1857 | } |
| 1858 | |
| 1859 | |
| 1860 | enum { |
| 1861 | CXT5051_LAPTOP, /* Laptops w/ EAPD support */ |
| 1862 | CXT5051_HP, /* no docking */ |
Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1863 | CXT5051_HP_DV6736, /* HP without mic switch */ |
Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1864 | CXT5051_F700, /* HP Compaq Presario F700 */ |
Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1865 | CXT5051_TOSHIBA, /* Toshiba M300 & co */ |
Herton Ronaldo Krzesinski | f7154de2 | 2010-06-17 14:15:06 -0300 | [diff] [blame] | 1866 | CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 1867 | CXT5051_AUTO, /* auto-parser */ |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1868 | CXT5051_MODELS |
| 1869 | }; |
| 1870 | |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1871 | static const char *const cxt5051_models[CXT5051_MODELS] = { |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1872 | [CXT5051_LAPTOP] = "laptop", |
| 1873 | [CXT5051_HP] = "hp", |
Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1874 | [CXT5051_HP_DV6736] = "hp-dv6736", |
Takashi Iwai | 5f6c3de | 2010-01-23 22:19:29 +0100 | [diff] [blame] | 1875 | [CXT5051_F700] = "hp-700", |
Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1876 | [CXT5051_TOSHIBA] = "toshiba", |
Herton Ronaldo Krzesinski | f7154de2 | 2010-06-17 14:15:06 -0300 | [diff] [blame] | 1877 | [CXT5051_IDEAPAD] = "ideapad", |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 1878 | [CXT5051_AUTO] = "auto", |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1879 | }; |
| 1880 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1881 | static const struct snd_pci_quirk cxt5051_cfg_tbl[] = { |
Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1882 | SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), |
Tony Vroon | 1812e67 | 2009-05-27 21:00:41 +0100 | [diff] [blame] | 1883 | SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), |
Takashi Iwai | 5f6c3de | 2010-01-23 22:19:29 +0100 | [diff] [blame] | 1884 | SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), |
Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1885 | SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1886 | SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", |
| 1887 | CXT5051_LAPTOP), |
| 1888 | SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), |
Herton Ronaldo Krzesinski | f7154de2 | 2010-06-17 14:15:06 -0300 | [diff] [blame] | 1889 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1890 | {} |
| 1891 | }; |
| 1892 | |
| 1893 | static int patch_cxt5051(struct hda_codec *codec) |
| 1894 | { |
| 1895 | struct conexant_spec *spec; |
| 1896 | int board_config; |
| 1897 | |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 1898 | board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, |
| 1899 | cxt5051_models, |
| 1900 | cxt5051_cfg_tbl); |
| 1901 | if (board_config < 0) |
Takashi Iwai | c82693d | 2011-06-28 14:17:17 +0200 | [diff] [blame] | 1902 | board_config = CXT5051_AUTO; /* model=auto as default */ |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 1903 | if (board_config == CXT5051_AUTO) |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 1904 | return patch_conexant_auto(codec); |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 1905 | |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1906 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 1907 | if (!spec) |
| 1908 | return -ENOMEM; |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1909 | codec->spec = spec; |
Takashi Iwai | 9421f95 | 2009-03-12 17:06:07 +0100 | [diff] [blame] | 1910 | codec->pin_amp_workaround = 1; |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1911 | |
| 1912 | codec->patch_ops = conexant_patch_ops; |
| 1913 | codec->patch_ops.init = cxt5051_init; |
| 1914 | |
| 1915 | spec->multiout.max_channels = 2; |
| 1916 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); |
| 1917 | spec->multiout.dac_nids = cxt5051_dac_nids; |
| 1918 | spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; |
| 1919 | spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ |
| 1920 | spec->adc_nids = cxt5051_adc_nids; |
Takashi Iwai | 2c7a3fb | 2010-01-24 10:47:02 +0100 | [diff] [blame] | 1921 | spec->num_mixers = 2; |
| 1922 | spec->mixers[0] = cxt5051_capture_mixers; |
| 1923 | spec->mixers[1] = cxt5051_playback_mixers; |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1924 | spec->num_init_verbs = 1; |
| 1925 | spec->init_verbs[0] = cxt5051_init_verbs; |
| 1926 | spec->spdif_route = 0; |
| 1927 | spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); |
| 1928 | spec->channel_mode = cxt5051_modes; |
| 1929 | spec->cur_adc = 0; |
| 1930 | spec->cur_adc_idx = 0; |
| 1931 | |
Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 1932 | set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); |
| 1933 | |
Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1934 | codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; |
| 1935 | |
Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1936 | spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1937 | switch (board_config) { |
| 1938 | case CXT5051_HP: |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1939 | spec->mixers[0] = cxt5051_hp_mixers; |
| 1940 | break; |
Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1941 | case CXT5051_HP_DV6736: |
| 1942 | spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; |
| 1943 | spec->mixers[0] = cxt5051_hp_dv6736_mixers; |
Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1944 | spec->auto_mic = 0; |
Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1945 | break; |
Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1946 | case CXT5051_F700: |
| 1947 | spec->init_verbs[0] = cxt5051_f700_init_verbs; |
| 1948 | spec->mixers[0] = cxt5051_f700_mixers; |
Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1949 | spec->auto_mic = 0; |
| 1950 | break; |
| 1951 | case CXT5051_TOSHIBA: |
| 1952 | spec->mixers[0] = cxt5051_toshiba_mixers; |
| 1953 | spec->auto_mic = AUTO_MIC_PORTB; |
Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1954 | break; |
Herton Ronaldo Krzesinski | f7154de2 | 2010-06-17 14:15:06 -0300 | [diff] [blame] | 1955 | case CXT5051_IDEAPAD: |
| 1956 | spec->init_verbs[spec->num_init_verbs++] = |
| 1957 | cxt5051_ideapad_init_verbs; |
| 1958 | spec->ideapad = 1; |
| 1959 | break; |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1960 | } |
| 1961 | |
Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 1962 | if (spec->beep_amp) |
| 1963 | snd_hda_attach_beep_device(codec, spec->beep_amp); |
| 1964 | |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1965 | return 0; |
| 1966 | } |
| 1967 | |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 1968 | /* Conexant 5066 specific */ |
| 1969 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1970 | static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; |
| 1971 | static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; |
| 1972 | static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; |
| 1973 | static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 1974 | |
Daniel Drake | dbaccc0 | 2009-11-09 15:17:24 +0000 | [diff] [blame] | 1975 | /* OLPC's microphone port is DC coupled for use with external sensors, |
| 1976 | * therefore we use a 50% mic bias in order to center the input signal with |
| 1977 | * the DC input range of the codec. */ |
| 1978 | #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 |
| 1979 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1980 | static const struct hda_channel_mode cxt5066_modes[1] = { |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 1981 | { 2, NULL }, |
| 1982 | }; |
| 1983 | |
Takashi Iwai | a3de8ab | 2010-12-03 12:29:14 +0100 | [diff] [blame] | 1984 | #define HP_PRESENT_PORT_A (1 << 0) |
| 1985 | #define HP_PRESENT_PORT_D (1 << 1) |
| 1986 | #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A) |
| 1987 | #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D) |
| 1988 | |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 1989 | static void cxt5066_update_speaker(struct hda_codec *codec) |
| 1990 | { |
| 1991 | struct conexant_spec *spec = codec->spec; |
| 1992 | unsigned int pinctl; |
| 1993 | |
John Baboval | 3a25344 | 2010-12-02 11:21:31 -0500 | [diff] [blame] | 1994 | snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", |
| 1995 | spec->hp_present, spec->cur_eapd); |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 1996 | |
| 1997 | /* Port A (HP) */ |
Takashi Iwai | a3de8ab | 2010-12-03 12:29:14 +0100 | [diff] [blame] | 1998 | pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 1999 | snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 2000 | pinctl); |
| 2001 | |
| 2002 | /* Port D (HP/LO) */ |
Takashi Iwai | a3de8ab | 2010-12-03 12:29:14 +0100 | [diff] [blame] | 2003 | pinctl = spec->cur_eapd ? spec->port_d_mode : 0; |
| 2004 | if (spec->dell_automute || spec->thinkpad) { |
| 2005 | /* Mute if Port A is connected */ |
| 2006 | if (hp_port_a_present(spec)) |
John Baboval | 3a25344 | 2010-12-02 11:21:31 -0500 | [diff] [blame] | 2007 | pinctl = 0; |
| 2008 | } else { |
Takashi Iwai | a3de8ab | 2010-12-03 12:29:14 +0100 | [diff] [blame] | 2009 | /* Thinkpad/Dell doesn't give pin-D status */ |
| 2010 | if (!hp_port_d_present(spec)) |
| 2011 | pinctl = 0; |
John Baboval | 3a25344 | 2010-12-02 11:21:31 -0500 | [diff] [blame] | 2012 | } |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2013 | snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 2014 | pinctl); |
| 2015 | |
| 2016 | /* CLASS_D AMP */ |
| 2017 | pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; |
| 2018 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 2019 | pinctl); |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | /* turn on/off EAPD (+ mute HP) as a master switch */ |
| 2023 | static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, |
| 2024 | struct snd_ctl_elem_value *ucontrol) |
| 2025 | { |
| 2026 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2027 | |
| 2028 | if (!cxt_eapd_put(kcontrol, ucontrol)) |
| 2029 | return 0; |
| 2030 | |
| 2031 | cxt5066_update_speaker(codec); |
| 2032 | return 1; |
| 2033 | } |
| 2034 | |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2035 | static const struct hda_input_mux cxt5066_olpc_dc_bias = { |
| 2036 | .num_items = 3, |
| 2037 | .items = { |
| 2038 | { "Off", PIN_IN }, |
| 2039 | { "50%", PIN_VREF50 }, |
| 2040 | { "80%", PIN_VREF80 }, |
| 2041 | }, |
| 2042 | }; |
| 2043 | |
| 2044 | static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) |
| 2045 | { |
| 2046 | struct conexant_spec *spec = codec->spec; |
| 2047 | /* Even though port F is the DC input, the bias is controlled on port B. |
| 2048 | * we also leave that port as an active input (but unselected) in DC mode |
| 2049 | * just in case that is necessary to make the bias setting take effect. */ |
| 2050 | return snd_hda_codec_write_cache(codec, 0x1a, 0, |
| 2051 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 2052 | cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); |
| 2053 | } |
| 2054 | |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2055 | /* OLPC defers mic widget control until when capture is started because the |
| 2056 | * microphone LED comes on as soon as these settings are put in place. if we |
| 2057 | * did this before recording, it would give the false indication that recording |
| 2058 | * is happening when it is not. */ |
| 2059 | static void cxt5066_olpc_select_mic(struct hda_codec *codec) |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2060 | { |
Daniel Drake | dbaccc0 | 2009-11-09 15:17:24 +0000 | [diff] [blame] | 2061 | struct conexant_spec *spec = codec->spec; |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2062 | if (!spec->recording) |
| 2063 | return; |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2064 | |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2065 | if (spec->dc_enable) { |
| 2066 | /* in DC mode we ignore presence detection and just use the jack |
| 2067 | * through our special DC port */ |
| 2068 | const struct hda_verb enable_dc_mode[] = { |
| 2069 | /* disble internal mic, port C */ |
| 2070 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2071 | |
| 2072 | /* enable DC capture, port F */ |
| 2073 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, |
| 2074 | {}, |
| 2075 | }; |
| 2076 | |
| 2077 | snd_hda_sequence_write(codec, enable_dc_mode); |
| 2078 | /* port B input disabled (and bias set) through the following call */ |
| 2079 | cxt5066_set_olpc_dc_bias(codec); |
| 2080 | return; |
| 2081 | } |
| 2082 | |
| 2083 | /* disable DC (port F) */ |
| 2084 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); |
| 2085 | |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2086 | /* external mic, port B */ |
| 2087 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 2088 | spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2089 | |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2090 | /* internal mic, port C */ |
| 2091 | snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 2092 | spec->ext_mic_present ? 0 : PIN_VREF80); |
| 2093 | } |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2094 | |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2095 | /* toggle input of built-in and mic jack appropriately */ |
| 2096 | static void cxt5066_olpc_automic(struct hda_codec *codec) |
| 2097 | { |
| 2098 | struct conexant_spec *spec = codec->spec; |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2099 | unsigned int present; |
| 2100 | |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2101 | if (spec->dc_enable) /* don't do presence detection in DC mode */ |
| 2102 | return; |
| 2103 | |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2104 | present = snd_hda_codec_read(codec, 0x1a, 0, |
| 2105 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
| 2106 | if (present) |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2107 | snd_printdd("CXT5066: external microphone detected\n"); |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2108 | else |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2109 | snd_printdd("CXT5066: external microphone absent\n"); |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2110 | |
| 2111 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, |
| 2112 | present ? 0 : 1); |
| 2113 | spec->ext_mic_present = !!present; |
| 2114 | |
| 2115 | cxt5066_olpc_select_mic(codec); |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2116 | } |
| 2117 | |
Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2118 | /* toggle input of built-in digital mic and mic jack appropriately */ |
| 2119 | static void cxt5066_vostro_automic(struct hda_codec *codec) |
| 2120 | { |
Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2121 | unsigned int present; |
| 2122 | |
| 2123 | struct hda_verb ext_mic_present[] = { |
| 2124 | /* enable external mic, port B */ |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2125 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, |
Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2126 | |
| 2127 | /* switch to external mic input */ |
| 2128 | {0x17, AC_VERB_SET_CONNECT_SEL, 0}, |
| 2129 | {0x14, AC_VERB_SET_CONNECT_SEL, 0}, |
| 2130 | |
| 2131 | /* disable internal digital mic */ |
| 2132 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2133 | {} |
| 2134 | }; |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2135 | static const struct hda_verb ext_mic_absent[] = { |
Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2136 | /* enable internal mic, port C */ |
| 2137 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, |
| 2138 | |
| 2139 | /* switch to internal mic input */ |
| 2140 | {0x14, AC_VERB_SET_CONNECT_SEL, 2}, |
| 2141 | |
| 2142 | /* disable external mic, port B */ |
| 2143 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2144 | {} |
| 2145 | }; |
| 2146 | |
| 2147 | present = snd_hda_jack_detect(codec, 0x1a); |
| 2148 | if (present) { |
| 2149 | snd_printdd("CXT5066: external microphone detected\n"); |
| 2150 | snd_hda_sequence_write(codec, ext_mic_present); |
| 2151 | } else { |
| 2152 | snd_printdd("CXT5066: external microphone absent\n"); |
| 2153 | snd_hda_sequence_write(codec, ext_mic_absent); |
| 2154 | } |
| 2155 | } |
| 2156 | |
Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2157 | /* toggle input of built-in digital mic and mic jack appropriately */ |
| 2158 | static void cxt5066_ideapad_automic(struct hda_codec *codec) |
| 2159 | { |
| 2160 | unsigned int present; |
| 2161 | |
| 2162 | struct hda_verb ext_mic_present[] = { |
| 2163 | {0x14, AC_VERB_SET_CONNECT_SEL, 0}, |
| 2164 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, |
| 2165 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2166 | {} |
| 2167 | }; |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2168 | static const struct hda_verb ext_mic_absent[] = { |
Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2169 | {0x14, AC_VERB_SET_CONNECT_SEL, 2}, |
| 2170 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, |
| 2171 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2172 | {} |
| 2173 | }; |
| 2174 | |
| 2175 | present = snd_hda_jack_detect(codec, 0x1b); |
| 2176 | if (present) { |
| 2177 | snd_printdd("CXT5066: external microphone detected\n"); |
| 2178 | snd_hda_sequence_write(codec, ext_mic_present); |
| 2179 | } else { |
| 2180 | snd_printdd("CXT5066: external microphone absent\n"); |
| 2181 | snd_hda_sequence_write(codec, ext_mic_absent); |
| 2182 | } |
| 2183 | } |
| 2184 | |
David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 2185 | |
| 2186 | /* toggle input of built-in digital mic and mic jack appropriately */ |
| 2187 | static void cxt5066_asus_automic(struct hda_codec *codec) |
| 2188 | { |
| 2189 | unsigned int present; |
| 2190 | |
| 2191 | present = snd_hda_jack_detect(codec, 0x1b); |
| 2192 | snd_printdd("CXT5066: external microphone present=%d\n", present); |
| 2193 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, |
| 2194 | present ? 1 : 0); |
| 2195 | } |
| 2196 | |
| 2197 | |
David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 2198 | /* toggle input of built-in digital mic and mic jack appropriately */ |
| 2199 | static void cxt5066_hp_laptop_automic(struct hda_codec *codec) |
| 2200 | { |
| 2201 | unsigned int present; |
| 2202 | |
| 2203 | present = snd_hda_jack_detect(codec, 0x1b); |
| 2204 | snd_printdd("CXT5066: external microphone present=%d\n", present); |
| 2205 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, |
| 2206 | present ? 1 : 3); |
| 2207 | } |
| 2208 | |
| 2209 | |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2210 | /* toggle input of built-in digital mic and mic jack appropriately |
| 2211 | order is: external mic -> dock mic -> interal mic */ |
| 2212 | static void cxt5066_thinkpad_automic(struct hda_codec *codec) |
| 2213 | { |
| 2214 | unsigned int ext_present, dock_present; |
| 2215 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2216 | static const struct hda_verb ext_mic_present[] = { |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2217 | {0x14, AC_VERB_SET_CONNECT_SEL, 0}, |
| 2218 | {0x17, AC_VERB_SET_CONNECT_SEL, 1}, |
| 2219 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, |
| 2220 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2221 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2222 | {} |
| 2223 | }; |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2224 | static const struct hda_verb dock_mic_present[] = { |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2225 | {0x14, AC_VERB_SET_CONNECT_SEL, 0}, |
| 2226 | {0x17, AC_VERB_SET_CONNECT_SEL, 0}, |
| 2227 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, |
| 2228 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2229 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2230 | {} |
| 2231 | }; |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2232 | static const struct hda_verb ext_mic_absent[] = { |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2233 | {0x14, AC_VERB_SET_CONNECT_SEL, 2}, |
| 2234 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, |
| 2235 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2236 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2237 | {} |
| 2238 | }; |
| 2239 | |
| 2240 | ext_present = snd_hda_jack_detect(codec, 0x1b); |
| 2241 | dock_present = snd_hda_jack_detect(codec, 0x1a); |
| 2242 | if (ext_present) { |
| 2243 | snd_printdd("CXT5066: external microphone detected\n"); |
| 2244 | snd_hda_sequence_write(codec, ext_mic_present); |
| 2245 | } else if (dock_present) { |
| 2246 | snd_printdd("CXT5066: dock microphone detected\n"); |
| 2247 | snd_hda_sequence_write(codec, dock_mic_present); |
| 2248 | } else { |
| 2249 | snd_printdd("CXT5066: external microphone absent\n"); |
| 2250 | snd_hda_sequence_write(codec, ext_mic_absent); |
| 2251 | } |
| 2252 | } |
| 2253 | |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2254 | /* mute internal speaker if HP is plugged */ |
| 2255 | static void cxt5066_hp_automute(struct hda_codec *codec) |
| 2256 | { |
| 2257 | struct conexant_spec *spec = codec->spec; |
| 2258 | unsigned int portA, portD; |
| 2259 | |
| 2260 | /* Port A */ |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 2261 | portA = snd_hda_jack_detect(codec, 0x19); |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2262 | |
| 2263 | /* Port D */ |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 2264 | portD = snd_hda_jack_detect(codec, 0x1c); |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2265 | |
Takashi Iwai | a3de8ab | 2010-12-03 12:29:14 +0100 | [diff] [blame] | 2266 | spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; |
| 2267 | spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2268 | snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", |
| 2269 | portA, portD, spec->hp_present); |
| 2270 | cxt5066_update_speaker(codec); |
| 2271 | } |
| 2272 | |
David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 2273 | /* Dispatch the right mic autoswitch function */ |
| 2274 | static void cxt5066_automic(struct hda_codec *codec) |
| 2275 | { |
| 2276 | struct conexant_spec *spec = codec->spec; |
| 2277 | |
| 2278 | if (spec->dell_vostro) |
| 2279 | cxt5066_vostro_automic(codec); |
| 2280 | else if (spec->ideapad) |
| 2281 | cxt5066_ideapad_automic(codec); |
| 2282 | else if (spec->thinkpad) |
| 2283 | cxt5066_thinkpad_automic(codec); |
| 2284 | else if (spec->hp_laptop) |
| 2285 | cxt5066_hp_laptop_automic(codec); |
David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 2286 | else if (spec->asus) |
| 2287 | cxt5066_asus_automic(codec); |
David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 2288 | } |
| 2289 | |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2290 | /* unsolicited event for jack sensing */ |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2291 | static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2292 | { |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2293 | struct conexant_spec *spec = codec->spec; |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2294 | snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); |
| 2295 | switch (res >> 26) { |
| 2296 | case CONEXANT_HP_EVENT: |
| 2297 | cxt5066_hp_automute(codec); |
| 2298 | break; |
| 2299 | case CONEXANT_MIC_EVENT: |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2300 | /* ignore mic events in DC mode; we're always using the jack */ |
| 2301 | if (!spec->dc_enable) |
| 2302 | cxt5066_olpc_automic(codec); |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2303 | break; |
| 2304 | } |
| 2305 | } |
| 2306 | |
Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2307 | /* unsolicited event for jack sensing */ |
David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 2308 | static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) |
Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2309 | { |
David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 2310 | snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); |
Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2311 | switch (res >> 26) { |
| 2312 | case CONEXANT_HP_EVENT: |
| 2313 | cxt5066_hp_automute(codec); |
| 2314 | break; |
| 2315 | case CONEXANT_MIC_EVENT: |
David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 2316 | cxt5066_automic(codec); |
Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2317 | break; |
| 2318 | } |
| 2319 | } |
| 2320 | |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2321 | |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2322 | static const struct hda_input_mux cxt5066_analog_mic_boost = { |
| 2323 | .num_items = 5, |
| 2324 | .items = { |
| 2325 | { "0dB", 0 }, |
| 2326 | { "10dB", 1 }, |
| 2327 | { "20dB", 2 }, |
| 2328 | { "30dB", 3 }, |
| 2329 | { "40dB", 4 }, |
| 2330 | }, |
| 2331 | }; |
| 2332 | |
Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2333 | static void cxt5066_set_mic_boost(struct hda_codec *codec) |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2334 | { |
| 2335 | struct conexant_spec *spec = codec->spec; |
Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2336 | snd_hda_codec_write_cache(codec, 0x17, 0, |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2337 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 2338 | AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | |
| 2339 | cxt5066_analog_mic_boost.items[spec->mic_boost].index); |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2340 | if (spec->ideapad || spec->thinkpad) { |
Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2341 | /* adjust the internal mic as well...it is not through 0x17 */ |
| 2342 | snd_hda_codec_write_cache(codec, 0x23, 0, |
| 2343 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 2344 | AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | |
| 2345 | cxt5066_analog_mic_boost. |
| 2346 | items[spec->mic_boost].index); |
| 2347 | } |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2348 | } |
| 2349 | |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2350 | static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 2351 | struct snd_ctl_elem_info *uinfo) |
| 2352 | { |
| 2353 | return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); |
| 2354 | } |
| 2355 | |
| 2356 | static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 2357 | struct snd_ctl_elem_value *ucontrol) |
| 2358 | { |
| 2359 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2360 | struct conexant_spec *spec = codec->spec; |
| 2361 | ucontrol->value.enumerated.item[0] = spec->mic_boost; |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2362 | return 0; |
| 2363 | } |
| 2364 | |
| 2365 | static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 2366 | struct snd_ctl_elem_value *ucontrol) |
| 2367 | { |
| 2368 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2369 | struct conexant_spec *spec = codec->spec; |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2370 | const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; |
| 2371 | unsigned int idx; |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2372 | idx = ucontrol->value.enumerated.item[0]; |
| 2373 | if (idx >= imux->num_items) |
| 2374 | idx = imux->num_items - 1; |
| 2375 | |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2376 | spec->mic_boost = idx; |
| 2377 | if (!spec->dc_enable) |
| 2378 | cxt5066_set_mic_boost(codec); |
| 2379 | return 1; |
| 2380 | } |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2381 | |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2382 | static void cxt5066_enable_dc(struct hda_codec *codec) |
| 2383 | { |
| 2384 | const struct hda_verb enable_dc_mode[] = { |
| 2385 | /* disable gain */ |
| 2386 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 2387 | |
| 2388 | /* switch to DC input */ |
| 2389 | {0x17, AC_VERB_SET_CONNECT_SEL, 3}, |
| 2390 | {} |
| 2391 | }; |
| 2392 | |
| 2393 | /* configure as input source */ |
| 2394 | snd_hda_sequence_write(codec, enable_dc_mode); |
| 2395 | cxt5066_olpc_select_mic(codec); /* also sets configured bias */ |
| 2396 | } |
| 2397 | |
| 2398 | static void cxt5066_disable_dc(struct hda_codec *codec) |
| 2399 | { |
| 2400 | /* reconfigure input source */ |
| 2401 | cxt5066_set_mic_boost(codec); |
| 2402 | /* automic also selects the right mic if we're recording */ |
| 2403 | cxt5066_olpc_automic(codec); |
| 2404 | } |
| 2405 | |
| 2406 | static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, |
| 2407 | struct snd_ctl_elem_value *ucontrol) |
| 2408 | { |
| 2409 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2410 | struct conexant_spec *spec = codec->spec; |
| 2411 | ucontrol->value.integer.value[0] = spec->dc_enable; |
| 2412 | return 0; |
| 2413 | } |
| 2414 | |
| 2415 | static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, |
| 2416 | struct snd_ctl_elem_value *ucontrol) |
| 2417 | { |
| 2418 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2419 | struct conexant_spec *spec = codec->spec; |
| 2420 | int dc_enable = !!ucontrol->value.integer.value[0]; |
| 2421 | |
| 2422 | if (dc_enable == spec->dc_enable) |
| 2423 | return 0; |
| 2424 | |
| 2425 | spec->dc_enable = dc_enable; |
| 2426 | if (dc_enable) |
| 2427 | cxt5066_enable_dc(codec); |
| 2428 | else |
| 2429 | cxt5066_disable_dc(codec); |
| 2430 | |
| 2431 | return 1; |
| 2432 | } |
| 2433 | |
| 2434 | static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, |
| 2435 | struct snd_ctl_elem_info *uinfo) |
| 2436 | { |
| 2437 | return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); |
| 2438 | } |
| 2439 | |
| 2440 | static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, |
| 2441 | struct snd_ctl_elem_value *ucontrol) |
| 2442 | { |
| 2443 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2444 | struct conexant_spec *spec = codec->spec; |
| 2445 | ucontrol->value.enumerated.item[0] = spec->dc_input_bias; |
| 2446 | return 0; |
| 2447 | } |
| 2448 | |
| 2449 | static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, |
| 2450 | struct snd_ctl_elem_value *ucontrol) |
| 2451 | { |
| 2452 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2453 | struct conexant_spec *spec = codec->spec; |
| 2454 | const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; |
| 2455 | unsigned int idx; |
| 2456 | |
| 2457 | idx = ucontrol->value.enumerated.item[0]; |
| 2458 | if (idx >= imux->num_items) |
| 2459 | idx = imux->num_items - 1; |
| 2460 | |
| 2461 | spec->dc_input_bias = idx; |
| 2462 | if (spec->dc_enable) |
| 2463 | cxt5066_set_olpc_dc_bias(codec); |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2464 | return 1; |
| 2465 | } |
| 2466 | |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2467 | static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) |
| 2468 | { |
| 2469 | struct conexant_spec *spec = codec->spec; |
| 2470 | /* mark as recording and configure the microphone widget so that the |
| 2471 | * recording LED comes on. */ |
| 2472 | spec->recording = 1; |
| 2473 | cxt5066_olpc_select_mic(codec); |
| 2474 | } |
| 2475 | |
| 2476 | static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) |
| 2477 | { |
| 2478 | struct conexant_spec *spec = codec->spec; |
| 2479 | const struct hda_verb disable_mics[] = { |
| 2480 | /* disable external mic, port B */ |
| 2481 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2482 | |
| 2483 | /* disble internal mic, port C */ |
| 2484 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2485 | |
| 2486 | /* disable DC capture, port F */ |
| 2487 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2488 | {}, |
| 2489 | }; |
| 2490 | |
| 2491 | snd_hda_sequence_write(codec, disable_mics); |
| 2492 | spec->recording = 0; |
| 2493 | } |
| 2494 | |
Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 2495 | static void conexant_check_dig_outs(struct hda_codec *codec, |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2496 | const hda_nid_t *dig_pins, |
Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 2497 | int num_pins) |
| 2498 | { |
| 2499 | struct conexant_spec *spec = codec->spec; |
| 2500 | hda_nid_t *nid_loc = &spec->multiout.dig_out_nid; |
| 2501 | int i; |
| 2502 | |
| 2503 | for (i = 0; i < num_pins; i++, dig_pins++) { |
| 2504 | unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins); |
| 2505 | if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE) |
| 2506 | continue; |
| 2507 | if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) |
| 2508 | continue; |
| 2509 | if (spec->slave_dig_outs[0]) |
| 2510 | nid_loc++; |
| 2511 | else |
| 2512 | nid_loc = spec->slave_dig_outs; |
| 2513 | } |
| 2514 | } |
| 2515 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2516 | static const struct hda_input_mux cxt5066_capture_source = { |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2517 | .num_items = 4, |
| 2518 | .items = { |
| 2519 | { "Mic B", 0 }, |
| 2520 | { "Mic C", 1 }, |
| 2521 | { "Mic E", 2 }, |
| 2522 | { "Mic F", 3 }, |
| 2523 | }, |
| 2524 | }; |
| 2525 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2526 | static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = { |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2527 | .ops = &snd_hda_bind_vol, |
| 2528 | .values = { |
| 2529 | HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), |
| 2530 | HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), |
| 2531 | 0 |
| 2532 | }, |
| 2533 | }; |
| 2534 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2535 | static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = { |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2536 | .ops = &snd_hda_bind_sw, |
| 2537 | .values = { |
| 2538 | HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), |
| 2539 | HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), |
| 2540 | 0 |
| 2541 | }, |
| 2542 | }; |
| 2543 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2544 | static const struct snd_kcontrol_new cxt5066_mixer_master[] = { |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2545 | HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), |
| 2546 | {} |
| 2547 | }; |
| 2548 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2549 | static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2550 | { |
| 2551 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2552 | .name = "Master Playback Volume", |
| 2553 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 2554 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | |
| 2555 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 2556 | .subdevice = HDA_SUBDEV_AMP_FLAG, |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2557 | .info = snd_hda_mixer_amp_volume_info, |
| 2558 | .get = snd_hda_mixer_amp_volume_get, |
| 2559 | .put = snd_hda_mixer_amp_volume_put, |
| 2560 | .tlv = { .c = snd_hda_mixer_amp_tlv }, |
| 2561 | /* offset by 28 volume steps to limit minimum gain to -46dB */ |
| 2562 | .private_value = |
| 2563 | HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), |
| 2564 | }, |
| 2565 | {} |
| 2566 | }; |
| 2567 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2568 | static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2569 | { |
| 2570 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2571 | .name = "DC Mode Enable Switch", |
| 2572 | .info = snd_ctl_boolean_mono_info, |
| 2573 | .get = cxt5066_olpc_dc_get, |
| 2574 | .put = cxt5066_olpc_dc_put, |
| 2575 | }, |
| 2576 | { |
| 2577 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2578 | .name = "DC Input Bias Enum", |
| 2579 | .info = cxt5066_olpc_dc_bias_enum_info, |
| 2580 | .get = cxt5066_olpc_dc_bias_enum_get, |
| 2581 | .put = cxt5066_olpc_dc_bias_enum_put, |
| 2582 | }, |
| 2583 | {} |
| 2584 | }; |
| 2585 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2586 | static const struct snd_kcontrol_new cxt5066_mixers[] = { |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2587 | { |
| 2588 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2589 | .name = "Master Playback Switch", |
| 2590 | .info = cxt_eapd_info, |
| 2591 | .get = cxt_eapd_get, |
| 2592 | .put = cxt5066_hp_master_sw_put, |
| 2593 | .private_value = 0x1d, |
| 2594 | }, |
| 2595 | |
| 2596 | { |
| 2597 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2598 | .name = "Analog Mic Boost Capture Enum", |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2599 | .info = cxt5066_mic_boost_mux_enum_info, |
| 2600 | .get = cxt5066_mic_boost_mux_enum_get, |
| 2601 | .put = cxt5066_mic_boost_mux_enum_put, |
| 2602 | }, |
| 2603 | |
| 2604 | HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), |
| 2605 | HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), |
| 2606 | {} |
| 2607 | }; |
| 2608 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2609 | static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = { |
Einar Rünkaru | 254bba6 | 2009-12-16 22:16:13 +0200 | [diff] [blame] | 2610 | { |
| 2611 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 2612 | .name = "Internal Mic Boost Capture Enum", |
Einar Rünkaru | 254bba6 | 2009-12-16 22:16:13 +0200 | [diff] [blame] | 2613 | .info = cxt5066_mic_boost_mux_enum_info, |
| 2614 | .get = cxt5066_mic_boost_mux_enum_get, |
| 2615 | .put = cxt5066_mic_boost_mux_enum_put, |
| 2616 | .private_value = 0x23 | 0x100, |
| 2617 | }, |
| 2618 | {} |
| 2619 | }; |
| 2620 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2621 | static const struct hda_verb cxt5066_init_verbs[] = { |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2622 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ |
| 2623 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ |
| 2624 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ |
| 2625 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ |
| 2626 | |
| 2627 | /* Speakers */ |
| 2628 | {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 2629 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ |
| 2630 | |
| 2631 | /* HP, Amp */ |
| 2632 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, |
| 2633 | {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ |
| 2634 | |
| 2635 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, |
| 2636 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ |
| 2637 | |
| 2638 | /* DAC1 */ |
| 2639 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 2640 | |
| 2641 | /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ |
| 2642 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, |
| 2643 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 2644 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, |
| 2645 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 2646 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 2647 | |
| 2648 | /* no digital microphone support yet */ |
| 2649 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2650 | |
| 2651 | /* Audio input selector */ |
| 2652 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, |
| 2653 | |
| 2654 | /* SPDIF route: PCM */ |
| 2655 | {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 2656 | {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 2657 | |
| 2658 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 2659 | {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 2660 | |
| 2661 | /* EAPD */ |
| 2662 | {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ |
| 2663 | |
| 2664 | /* not handling these yet */ |
| 2665 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, |
| 2666 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, |
| 2667 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, |
| 2668 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, |
| 2669 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, |
| 2670 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, |
| 2671 | {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, |
| 2672 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, |
| 2673 | { } /* end */ |
| 2674 | }; |
| 2675 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2676 | static const struct hda_verb cxt5066_init_verbs_olpc[] = { |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2677 | /* Port A: headphones */ |
| 2678 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, |
| 2679 | {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ |
| 2680 | |
| 2681 | /* Port B: external microphone */ |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2682 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2683 | |
| 2684 | /* Port C: internal microphone */ |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2685 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2686 | |
| 2687 | /* Port D: unused */ |
| 2688 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2689 | |
| 2690 | /* Port E: unused, but has primary EAPD */ |
| 2691 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2692 | {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ |
| 2693 | |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2694 | /* Port F: external DC input through microphone port */ |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2695 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2696 | |
| 2697 | /* Port G: internal speakers */ |
| 2698 | {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 2699 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ |
| 2700 | |
| 2701 | /* DAC1 */ |
| 2702 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 2703 | |
| 2704 | /* DAC2: unused */ |
| 2705 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, |
| 2706 | |
| 2707 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, |
| 2708 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 2709 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 2710 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 2711 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 2712 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 2713 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 2714 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 2715 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 2716 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 2717 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 2718 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 2719 | |
| 2720 | /* Disable digital microphone port */ |
| 2721 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2722 | |
| 2723 | /* Audio input selectors */ |
| 2724 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, |
| 2725 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, |
| 2726 | |
| 2727 | /* Disable SPDIF */ |
| 2728 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2729 | {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2730 | |
| 2731 | /* enable unsolicited events for Port A and B */ |
| 2732 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, |
| 2733 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, |
| 2734 | { } /* end */ |
| 2735 | }; |
| 2736 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2737 | static const struct hda_verb cxt5066_init_verbs_vostro[] = { |
Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2738 | /* Port A: headphones */ |
| 2739 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2740 | {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ |
| 2741 | |
| 2742 | /* Port B: external microphone */ |
| 2743 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2744 | |
| 2745 | /* Port C: unused */ |
| 2746 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2747 | |
| 2748 | /* Port D: unused */ |
| 2749 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2750 | |
| 2751 | /* Port E: unused, but has primary EAPD */ |
| 2752 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2753 | {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ |
| 2754 | |
| 2755 | /* Port F: unused */ |
| 2756 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2757 | |
| 2758 | /* Port G: internal speakers */ |
| 2759 | {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 2760 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ |
| 2761 | |
| 2762 | /* DAC1 */ |
| 2763 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 2764 | |
| 2765 | /* DAC2: unused */ |
| 2766 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, |
| 2767 | |
| 2768 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 2769 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 2770 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 2771 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 2772 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 2773 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 2774 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 2775 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 2776 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 2777 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 2778 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 2779 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 2780 | |
| 2781 | /* Digital microphone port */ |
| 2782 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, |
| 2783 | |
| 2784 | /* Audio input selectors */ |
| 2785 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, |
| 2786 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, |
| 2787 | |
| 2788 | /* Disable SPDIF */ |
| 2789 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2790 | {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2791 | |
| 2792 | /* enable unsolicited events for Port A and B */ |
| 2793 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, |
| 2794 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, |
| 2795 | { } /* end */ |
| 2796 | }; |
| 2797 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2798 | static const struct hda_verb cxt5066_init_verbs_ideapad[] = { |
Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2799 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ |
| 2800 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ |
| 2801 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ |
| 2802 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ |
| 2803 | |
| 2804 | /* Speakers */ |
| 2805 | {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 2806 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ |
| 2807 | |
| 2808 | /* HP, Amp */ |
| 2809 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, |
| 2810 | {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ |
| 2811 | |
| 2812 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, |
| 2813 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ |
| 2814 | |
| 2815 | /* DAC1 */ |
| 2816 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 2817 | |
| 2818 | /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ |
| 2819 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, |
| 2820 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 2821 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, |
| 2822 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 2823 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 2824 | {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ |
| 2825 | |
| 2826 | /* Audio input selector */ |
| 2827 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, |
| 2828 | {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ |
| 2829 | |
| 2830 | /* SPDIF route: PCM */ |
| 2831 | {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 2832 | {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 2833 | |
| 2834 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 2835 | {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 2836 | |
| 2837 | /* internal microphone */ |
David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 2838 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ |
Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2839 | |
| 2840 | /* EAPD */ |
| 2841 | {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ |
| 2842 | |
| 2843 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, |
| 2844 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, |
| 2845 | { } /* end */ |
| 2846 | }; |
| 2847 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2848 | static const struct hda_verb cxt5066_init_verbs_thinkpad[] = { |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2849 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ |
| 2850 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ |
| 2851 | |
| 2852 | /* Port G: internal speakers */ |
| 2853 | {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 2854 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ |
| 2855 | |
| 2856 | /* Port A: HP, Amp */ |
| 2857 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2858 | {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ |
| 2859 | |
| 2860 | /* Port B: Mic Dock */ |
| 2861 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2862 | |
| 2863 | /* Port C: Mic */ |
| 2864 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2865 | |
| 2866 | /* Port D: HP Dock, Amp */ |
| 2867 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
| 2868 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ |
| 2869 | |
| 2870 | /* DAC1 */ |
| 2871 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 2872 | |
| 2873 | /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ |
| 2874 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, |
| 2875 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 2876 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, |
| 2877 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 2878 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 2879 | {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ |
| 2880 | |
| 2881 | /* Audio input selector */ |
| 2882 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, |
| 2883 | {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ |
| 2884 | |
| 2885 | /* SPDIF route: PCM */ |
| 2886 | {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 2887 | {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 2888 | |
| 2889 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 2890 | {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 2891 | |
| 2892 | /* internal microphone */ |
David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 2893 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2894 | |
| 2895 | /* EAPD */ |
| 2896 | {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ |
| 2897 | |
| 2898 | /* enable unsolicited events for Port A, B, C and D */ |
| 2899 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, |
| 2900 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, |
| 2901 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, |
| 2902 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, |
| 2903 | { } /* end */ |
| 2904 | }; |
| 2905 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2906 | static const struct hda_verb cxt5066_init_verbs_portd_lo[] = { |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2907 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 2908 | { } /* end */ |
| 2909 | }; |
| 2910 | |
David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 2911 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2912 | static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = { |
David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 2913 | {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 2914 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, |
| 2915 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, |
| 2916 | { } /* end */ |
| 2917 | }; |
| 2918 | |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2919 | /* initialize jack-sensing, too */ |
| 2920 | static int cxt5066_init(struct hda_codec *codec) |
| 2921 | { |
| 2922 | snd_printdd("CXT5066: init\n"); |
| 2923 | conexant_init(codec); |
| 2924 | if (codec->patch_ops.unsol_event) { |
| 2925 | cxt5066_hp_automute(codec); |
David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 2926 | cxt5066_automic(codec); |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2927 | } |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2928 | cxt5066_set_mic_boost(codec); |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2929 | return 0; |
| 2930 | } |
| 2931 | |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2932 | static int cxt5066_olpc_init(struct hda_codec *codec) |
| 2933 | { |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2934 | struct conexant_spec *spec = codec->spec; |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2935 | snd_printdd("CXT5066: init\n"); |
| 2936 | conexant_init(codec); |
| 2937 | cxt5066_hp_automute(codec); |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2938 | if (!spec->dc_enable) { |
| 2939 | cxt5066_set_mic_boost(codec); |
| 2940 | cxt5066_olpc_automic(codec); |
| 2941 | } else { |
| 2942 | cxt5066_enable_dc(codec); |
| 2943 | } |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2944 | return 0; |
| 2945 | } |
| 2946 | |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2947 | enum { |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2948 | CXT5066_LAPTOP, /* Laptops w/ EAPD support */ |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2949 | CXT5066_DELL_LAPTOP, /* Dell Laptop */ |
| 2950 | CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ |
David Henningsson | 1feba3b | 2010-09-17 10:52:50 +0200 | [diff] [blame] | 2951 | CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ |
Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2952 | CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2953 | CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ |
David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 2954 | CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */ |
David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 2955 | CXT5066_HP_LAPTOP, /* HP Laptop */ |
Takashi Iwai | fea4a4f | 2011-05-16 11:49:12 +0200 | [diff] [blame] | 2956 | CXT5066_AUTO, /* BIOS auto-parser */ |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2957 | CXT5066_MODELS |
| 2958 | }; |
| 2959 | |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 2960 | static const char * const cxt5066_models[CXT5066_MODELS] = { |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2961 | [CXT5066_LAPTOP] = "laptop", |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2962 | [CXT5066_DELL_LAPTOP] = "dell-laptop", |
| 2963 | [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", |
David Henningsson | 1feba3b | 2010-09-17 10:52:50 +0200 | [diff] [blame] | 2964 | [CXT5066_DELL_VOSTRO] = "dell-vostro", |
Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2965 | [CXT5066_IDEAPAD] = "ideapad", |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2966 | [CXT5066_THINKPAD] = "thinkpad", |
David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 2967 | [CXT5066_ASUS] = "asus", |
David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 2968 | [CXT5066_HP_LAPTOP] = "hp-laptop", |
Takashi Iwai | fea4a4f | 2011-05-16 11:49:12 +0200 | [diff] [blame] | 2969 | [CXT5066_AUTO] = "auto", |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2970 | }; |
| 2971 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2972 | static const struct snd_pci_quirk cxt5066_cfg_tbl[] = { |
David Henningsson | 9966db22 | 2011-06-21 21:01:52 +0200 | [diff] [blame] | 2973 | SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO), |
Takashi Iwai | 00cd0bb | 2010-10-21 09:57:40 +0200 | [diff] [blame] | 2974 | SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), |
David Henningsson | 1feba3b | 2010-09-17 10:52:50 +0200 | [diff] [blame] | 2975 | SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), |
David Henningsson | 8a96b1e | 2010-12-09 07:17:27 +0100 | [diff] [blame] | 2976 | SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), |
Daniel T Chen | ca6cd85 | 2011-01-08 18:25:27 -0500 | [diff] [blame] | 2977 | SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), |
David Henningsson | 1feba3b | 2010-09-17 10:52:50 +0200 | [diff] [blame] | 2978 | SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), |
Anisse Astier | 231f50b | 2010-04-28 18:05:06 +0200 | [diff] [blame] | 2979 | SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), |
David Henningsson | ebbd224 | 2011-02-23 13:15:56 +0100 | [diff] [blame] | 2980 | SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD), |
| 2981 | SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD), |
David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 2982 | SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), |
Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 2983 | SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS), |
David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 2984 | SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), |
Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 2985 | SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), |
Anisse Astier | 2ca9cac | 2010-09-10 15:47:55 +0200 | [diff] [blame] | 2986 | SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), |
Daniel T Chen | c536668 | 2010-05-04 22:07:58 -0400 | [diff] [blame] | 2987 | SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), |
David Henningsson | 5637edb | 2010-09-17 10:58:03 +0200 | [diff] [blame] | 2988 | SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", |
| 2989 | CXT5066_LAPTOP), |
| 2990 | SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), |
Takashi Iwai | 4d15564 | 2010-09-07 11:58:30 +0200 | [diff] [blame] | 2991 | SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), |
Manoj Iyer | ef61d4e | 2010-12-03 18:43:55 -0600 | [diff] [blame] | 2992 | SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), |
David Henningsson | 1959387 | 2011-01-27 10:28:46 +0100 | [diff] [blame] | 2993 | SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), |
David Henningsson | 29c5fbb | 2012-01-23 16:39:55 +0100 | [diff] [blame] | 2994 | SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO), |
Daniel Suchy | ca201c0 | 2011-10-18 11:09:44 +0200 | [diff] [blame] | 2995 | SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO), |
David Henningsson | 8401265 | 2011-03-31 09:36:19 +0200 | [diff] [blame] | 2996 | SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), |
David Henningsson | b2cb129 | 2011-04-05 07:55:24 +0200 | [diff] [blame] | 2997 | SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), |
David Henningsson | d2859fd | 2011-05-23 08:26:16 +0200 | [diff] [blame] | 2998 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS), |
David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 2999 | SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), |
Takashi Iwai | af4ccf4 | 2011-05-25 07:33:20 +0200 | [diff] [blame] | 3000 | SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO), |
Daniel T Chen | 7ab1fc0 | 2011-06-10 10:14:01 -0400 | [diff] [blame] | 3001 | SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO), |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3002 | {} |
| 3003 | }; |
| 3004 | |
| 3005 | static int patch_cxt5066(struct hda_codec *codec) |
| 3006 | { |
| 3007 | struct conexant_spec *spec; |
| 3008 | int board_config; |
| 3009 | |
Takashi Iwai | fea4a4f | 2011-05-16 11:49:12 +0200 | [diff] [blame] | 3010 | board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, |
| 3011 | cxt5066_models, cxt5066_cfg_tbl); |
Takashi Iwai | fea4a4f | 2011-05-16 11:49:12 +0200 | [diff] [blame] | 3012 | if (board_config < 0) |
Takashi Iwai | c82693d | 2011-06-28 14:17:17 +0200 | [diff] [blame] | 3013 | board_config = CXT5066_AUTO; /* model=auto as default */ |
Takashi Iwai | fea4a4f | 2011-05-16 11:49:12 +0200 | [diff] [blame] | 3014 | if (board_config == CXT5066_AUTO) |
| 3015 | return patch_conexant_auto(codec); |
| 3016 | |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3017 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 3018 | if (!spec) |
| 3019 | return -ENOMEM; |
| 3020 | codec->spec = spec; |
| 3021 | |
| 3022 | codec->patch_ops = conexant_patch_ops; |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 3023 | codec->patch_ops.init = conexant_init; |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3024 | |
| 3025 | spec->dell_automute = 0; |
| 3026 | spec->multiout.max_channels = 2; |
| 3027 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); |
| 3028 | spec->multiout.dac_nids = cxt5066_dac_nids; |
Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 3029 | conexant_check_dig_outs(codec, cxt5066_digout_pin_nids, |
| 3030 | ARRAY_SIZE(cxt5066_digout_pin_nids)); |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3031 | spec->num_adc_nids = 1; |
| 3032 | spec->adc_nids = cxt5066_adc_nids; |
| 3033 | spec->capsrc_nids = cxt5066_capsrc_nids; |
| 3034 | spec->input_mux = &cxt5066_capture_source; |
| 3035 | |
| 3036 | spec->port_d_mode = PIN_HP; |
| 3037 | |
| 3038 | spec->num_init_verbs = 1; |
| 3039 | spec->init_verbs[0] = cxt5066_init_verbs; |
| 3040 | spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); |
| 3041 | spec->channel_mode = cxt5066_modes; |
| 3042 | spec->cur_adc = 0; |
| 3043 | spec->cur_adc_idx = 0; |
| 3044 | |
Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 3045 | set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); |
| 3046 | |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3047 | switch (board_config) { |
| 3048 | default: |
| 3049 | case CXT5066_LAPTOP: |
| 3050 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; |
| 3051 | spec->mixers[spec->num_mixers++] = cxt5066_mixers; |
| 3052 | break; |
| 3053 | case CXT5066_DELL_LAPTOP: |
| 3054 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; |
| 3055 | spec->mixers[spec->num_mixers++] = cxt5066_mixers; |
| 3056 | |
| 3057 | spec->port_d_mode = PIN_OUT; |
| 3058 | spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; |
| 3059 | spec->num_init_verbs++; |
| 3060 | spec->dell_automute = 1; |
| 3061 | break; |
David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 3062 | case CXT5066_ASUS: |
David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 3063 | case CXT5066_HP_LAPTOP: |
| 3064 | codec->patch_ops.init = cxt5066_init; |
David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 3065 | codec->patch_ops.unsol_event = cxt5066_unsol_event; |
David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 3066 | spec->init_verbs[spec->num_init_verbs] = |
| 3067 | cxt5066_init_verbs_hp_laptop; |
| 3068 | spec->num_init_verbs++; |
David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 3069 | spec->hp_laptop = board_config == CXT5066_HP_LAPTOP; |
| 3070 | spec->asus = board_config == CXT5066_ASUS; |
David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 3071 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; |
| 3072 | spec->mixers[spec->num_mixers++] = cxt5066_mixers; |
| 3073 | /* no S/PDIF out */ |
Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 3074 | if (board_config == CXT5066_HP_LAPTOP) |
| 3075 | spec->multiout.dig_out_nid = 0; |
David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 3076 | /* input source automatically selected */ |
| 3077 | spec->input_mux = NULL; |
| 3078 | spec->port_d_mode = 0; |
| 3079 | spec->mic_boost = 3; /* default 30dB gain */ |
| 3080 | break; |
| 3081 | |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3082 | case CXT5066_OLPC_XO_1_5: |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 3083 | codec->patch_ops.init = cxt5066_olpc_init; |
| 3084 | codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3085 | spec->init_verbs[0] = cxt5066_init_verbs_olpc; |
| 3086 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 3087 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3088 | spec->mixers[spec->num_mixers++] = cxt5066_mixers; |
| 3089 | spec->port_d_mode = 0; |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 3090 | spec->mic_boost = 3; /* default 30dB gain */ |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3091 | |
| 3092 | /* no S/PDIF out */ |
| 3093 | spec->multiout.dig_out_nid = 0; |
| 3094 | |
| 3095 | /* input source automatically selected */ |
| 3096 | spec->input_mux = NULL; |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 3097 | |
| 3098 | /* our capture hooks which allow us to turn on the microphone LED |
| 3099 | * at the right time */ |
| 3100 | spec->capture_prepare = cxt5066_olpc_capture_prepare; |
| 3101 | spec->capture_cleanup = cxt5066_olpc_capture_cleanup; |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3102 | break; |
David Henningsson | 1feba3b | 2010-09-17 10:52:50 +0200 | [diff] [blame] | 3103 | case CXT5066_DELL_VOSTRO: |
Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 3104 | codec->patch_ops.init = cxt5066_init; |
David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 3105 | codec->patch_ops.unsol_event = cxt5066_unsol_event; |
Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 3106 | spec->init_verbs[0] = cxt5066_init_verbs_vostro; |
| 3107 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; |
| 3108 | spec->mixers[spec->num_mixers++] = cxt5066_mixers; |
Einar Rünkaru | 254bba6 | 2009-12-16 22:16:13 +0200 | [diff] [blame] | 3109 | spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; |
Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 3110 | spec->port_d_mode = 0; |
Einar Rünkaru | 254bba6 | 2009-12-16 22:16:13 +0200 | [diff] [blame] | 3111 | spec->dell_vostro = 1; |
Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 3112 | spec->mic_boost = 3; /* default 30dB gain */ |
Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 3113 | |
| 3114 | /* no S/PDIF out */ |
| 3115 | spec->multiout.dig_out_nid = 0; |
| 3116 | |
| 3117 | /* input source automatically selected */ |
| 3118 | spec->input_mux = NULL; |
| 3119 | break; |
Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 3120 | case CXT5066_IDEAPAD: |
| 3121 | codec->patch_ops.init = cxt5066_init; |
David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 3122 | codec->patch_ops.unsol_event = cxt5066_unsol_event; |
Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 3123 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; |
| 3124 | spec->mixers[spec->num_mixers++] = cxt5066_mixers; |
| 3125 | spec->init_verbs[0] = cxt5066_init_verbs_ideapad; |
| 3126 | spec->port_d_mode = 0; |
| 3127 | spec->ideapad = 1; |
| 3128 | spec->mic_boost = 2; /* default 20dB gain */ |
| 3129 | |
| 3130 | /* no S/PDIF out */ |
| 3131 | spec->multiout.dig_out_nid = 0; |
| 3132 | |
| 3133 | /* input source automatically selected */ |
| 3134 | spec->input_mux = NULL; |
| 3135 | break; |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 3136 | case CXT5066_THINKPAD: |
| 3137 | codec->patch_ops.init = cxt5066_init; |
David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 3138 | codec->patch_ops.unsol_event = cxt5066_unsol_event; |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 3139 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; |
| 3140 | spec->mixers[spec->num_mixers++] = cxt5066_mixers; |
| 3141 | spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; |
| 3142 | spec->thinkpad = 1; |
| 3143 | spec->port_d_mode = PIN_OUT; |
| 3144 | spec->mic_boost = 2; /* default 20dB gain */ |
| 3145 | |
| 3146 | /* no S/PDIF out */ |
| 3147 | spec->multiout.dig_out_nid = 0; |
| 3148 | |
| 3149 | /* input source automatically selected */ |
| 3150 | spec->input_mux = NULL; |
| 3151 | break; |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3152 | } |
| 3153 | |
Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 3154 | if (spec->beep_amp) |
| 3155 | snd_hda_attach_beep_device(codec, spec->beep_amp); |
| 3156 | |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3157 | return 0; |
| 3158 | } |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 3159 | |
| 3160 | /* |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3161 | * Automatic parser for CX20641 & co |
| 3162 | */ |
| 3163 | |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3164 | static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 3165 | struct hda_codec *codec, |
| 3166 | unsigned int stream_tag, |
| 3167 | unsigned int format, |
| 3168 | struct snd_pcm_substream *substream) |
| 3169 | { |
| 3170 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 3171 | hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc; |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3172 | if (spec->adc_switching) { |
| 3173 | spec->cur_adc = adc; |
| 3174 | spec->cur_adc_stream_tag = stream_tag; |
| 3175 | spec->cur_adc_format = format; |
| 3176 | } |
| 3177 | snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format); |
| 3178 | return 0; |
| 3179 | } |
| 3180 | |
| 3181 | static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 3182 | struct hda_codec *codec, |
| 3183 | struct snd_pcm_substream *substream) |
| 3184 | { |
| 3185 | struct conexant_spec *spec = codec->spec; |
| 3186 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
| 3187 | spec->cur_adc = 0; |
| 3188 | return 0; |
| 3189 | } |
| 3190 | |
| 3191 | static const struct hda_pcm_stream cx_auto_pcm_analog_capture = { |
| 3192 | .substreams = 1, |
| 3193 | .channels_min = 2, |
| 3194 | .channels_max = 2, |
| 3195 | .nid = 0, /* fill later */ |
| 3196 | .ops = { |
| 3197 | .prepare = cx_auto_capture_pcm_prepare, |
| 3198 | .cleanup = cx_auto_capture_pcm_cleanup |
| 3199 | }, |
| 3200 | }; |
| 3201 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 3202 | static const hda_nid_t cx_auto_adc_nids[] = { 0x14 }; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3203 | |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 3204 | #define get_connection_index(codec, mux, nid)\ |
| 3205 | snd_hda_get_conn_index(codec, mux, nid, 0) |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3206 | |
| 3207 | /* get an unassigned DAC from the given list. |
| 3208 | * Return the nid if found and reduce the DAC list, or return zero if |
| 3209 | * not found |
| 3210 | */ |
| 3211 | static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, |
| 3212 | hda_nid_t *dacs, int *num_dacs) |
| 3213 | { |
| 3214 | int i, nums = *num_dacs; |
| 3215 | hda_nid_t ret = 0; |
| 3216 | |
| 3217 | for (i = 0; i < nums; i++) { |
| 3218 | if (get_connection_index(codec, pin, dacs[i]) >= 0) { |
| 3219 | ret = dacs[i]; |
| 3220 | break; |
| 3221 | } |
| 3222 | } |
| 3223 | if (!ret) |
| 3224 | return 0; |
| 3225 | if (--nums > 0) |
| 3226 | memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); |
| 3227 | *num_dacs = nums; |
| 3228 | return ret; |
| 3229 | } |
| 3230 | |
| 3231 | #define MAX_AUTO_DACS 5 |
| 3232 | |
Takashi Iwai | 1f015f5 | 2011-08-23 14:57:08 +0200 | [diff] [blame] | 3233 | #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */ |
| 3234 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3235 | /* fill analog DAC list from the widget tree */ |
| 3236 | static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) |
| 3237 | { |
| 3238 | hda_nid_t nid, end_nid; |
| 3239 | int nums = 0; |
| 3240 | |
| 3241 | end_nid = codec->start_nid + codec->num_nodes; |
| 3242 | for (nid = codec->start_nid; nid < end_nid; nid++) { |
| 3243 | unsigned int wcaps = get_wcaps(codec, nid); |
| 3244 | unsigned int type = get_wcaps_type(wcaps); |
| 3245 | if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { |
| 3246 | dacs[nums++] = nid; |
| 3247 | if (nums >= MAX_AUTO_DACS) |
| 3248 | break; |
| 3249 | } |
| 3250 | } |
| 3251 | return nums; |
| 3252 | } |
| 3253 | |
| 3254 | /* fill pin_dac_pair list from the pin and dac list */ |
| 3255 | static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, |
| 3256 | int num_pins, hda_nid_t *dacs, int *rest, |
David Henningsson | 468c545 | 2011-08-25 13:16:02 +0200 | [diff] [blame] | 3257 | struct pin_dac_pair *filled, int nums, |
| 3258 | int type) |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3259 | { |
David Henningsson | 468c545 | 2011-08-25 13:16:02 +0200 | [diff] [blame] | 3260 | int i, start = nums; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3261 | |
David Henningsson | 468c545 | 2011-08-25 13:16:02 +0200 | [diff] [blame] | 3262 | for (i = 0; i < num_pins; i++, nums++) { |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3263 | filled[nums].pin = pins[i]; |
| 3264 | filled[nums].type = type; |
| 3265 | filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); |
David Henningsson | 468c545 | 2011-08-25 13:16:02 +0200 | [diff] [blame] | 3266 | if (filled[nums].dac) |
| 3267 | continue; |
| 3268 | if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) { |
| 3269 | filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG; |
| 3270 | continue; |
| 3271 | } |
| 3272 | if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) { |
Takashi Iwai | 1f015f5 | 2011-08-23 14:57:08 +0200 | [diff] [blame] | 3273 | filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG; |
David Henningsson | 468c545 | 2011-08-25 13:16:02 +0200 | [diff] [blame] | 3274 | continue; |
| 3275 | } |
| 3276 | snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3277 | } |
| 3278 | return nums; |
| 3279 | } |
| 3280 | |
| 3281 | /* parse analog output paths */ |
| 3282 | static void cx_auto_parse_output(struct hda_codec *codec) |
| 3283 | { |
| 3284 | struct conexant_spec *spec = codec->spec; |
| 3285 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3286 | hda_nid_t dacs[MAX_AUTO_DACS]; |
| 3287 | int i, j, nums, rest; |
| 3288 | |
| 3289 | rest = fill_cx_auto_dacs(codec, dacs); |
| 3290 | /* parse all analog output pins */ |
| 3291 | nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, |
David Henningsson | 468c545 | 2011-08-25 13:16:02 +0200 | [diff] [blame] | 3292 | dacs, &rest, spec->dac_info, 0, |
| 3293 | AUTO_PIN_LINE_OUT); |
| 3294 | nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, |
| 3295 | dacs, &rest, spec->dac_info, nums, |
| 3296 | AUTO_PIN_HP_OUT); |
| 3297 | nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, |
| 3298 | dacs, &rest, spec->dac_info, nums, |
| 3299 | AUTO_PIN_SPEAKER_OUT); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3300 | spec->dac_info_filled = nums; |
| 3301 | /* fill multiout struct */ |
| 3302 | for (i = 0; i < nums; i++) { |
| 3303 | hda_nid_t dac = spec->dac_info[i].dac; |
Takashi Iwai | 1f015f5 | 2011-08-23 14:57:08 +0200 | [diff] [blame] | 3304 | if (!dac || (dac & DAC_SLAVE_FLAG)) |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3305 | continue; |
| 3306 | switch (spec->dac_info[i].type) { |
| 3307 | case AUTO_PIN_LINE_OUT: |
| 3308 | spec->private_dac_nids[spec->multiout.num_dacs] = dac; |
| 3309 | spec->multiout.num_dacs++; |
| 3310 | break; |
| 3311 | case AUTO_PIN_HP_OUT: |
| 3312 | case AUTO_PIN_SPEAKER_OUT: |
| 3313 | if (!spec->multiout.hp_nid) { |
| 3314 | spec->multiout.hp_nid = dac; |
| 3315 | break; |
| 3316 | } |
| 3317 | for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) |
| 3318 | if (!spec->multiout.extra_out_nid[j]) { |
| 3319 | spec->multiout.extra_out_nid[j] = dac; |
| 3320 | break; |
| 3321 | } |
| 3322 | break; |
| 3323 | } |
| 3324 | } |
| 3325 | spec->multiout.dac_nids = spec->private_dac_nids; |
David Henningsson | 8972495 | 2011-02-16 21:34:04 +0100 | [diff] [blame] | 3326 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3327 | |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3328 | for (i = 0; i < cfg->hp_outs; i++) { |
| 3329 | if (is_jack_detectable(codec, cfg->hp_pins[i])) { |
| 3330 | spec->auto_mute = 1; |
| 3331 | break; |
| 3332 | } |
| 3333 | } |
Takashi Iwai | e2df82f | 2011-05-24 11:49:12 +0200 | [diff] [blame] | 3334 | if (spec->auto_mute && |
| 3335 | cfg->line_out_pins[0] && |
| 3336 | cfg->line_out_type != AUTO_PIN_SPEAKER_OUT && |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3337 | cfg->line_out_pins[0] != cfg->hp_pins[0] && |
| 3338 | cfg->line_out_pins[0] != cfg->speaker_pins[0]) { |
| 3339 | for (i = 0; i < cfg->line_outs; i++) { |
| 3340 | if (is_jack_detectable(codec, cfg->line_out_pins[i])) { |
| 3341 | spec->detect_line = 1; |
| 3342 | break; |
| 3343 | } |
| 3344 | } |
| 3345 | spec->automute_lines = spec->detect_line; |
| 3346 | } |
| 3347 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3348 | spec->vmaster_nid = spec->private_dac_nids[0]; |
| 3349 | } |
| 3350 | |
Takashi Iwai | da33986 | 2011-05-13 16:24:15 +0200 | [diff] [blame] | 3351 | static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, |
| 3352 | hda_nid_t *pins, bool on); |
| 3353 | |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3354 | static void do_automute(struct hda_codec *codec, int num_pins, |
| 3355 | hda_nid_t *pins, bool on) |
| 3356 | { |
Takashi Iwai | 254f296 | 2011-10-14 15:22:34 +0200 | [diff] [blame] | 3357 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3358 | int i; |
| 3359 | for (i = 0; i < num_pins; i++) |
| 3360 | snd_hda_codec_write(codec, pins[i], 0, |
| 3361 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 3362 | on ? PIN_OUT : 0); |
Takashi Iwai | 254f296 | 2011-10-14 15:22:34 +0200 | [diff] [blame] | 3363 | if (spec->pin_eapd_ctrls) |
| 3364 | cx_auto_turn_eapd(codec, num_pins, pins, on); |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) |
| 3368 | { |
| 3369 | int i, present = 0; |
| 3370 | |
| 3371 | for (i = 0; i < num_pins; i++) { |
| 3372 | hda_nid_t nid = pins[i]; |
| 3373 | if (!nid || !is_jack_detectable(codec, nid)) |
| 3374 | break; |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3375 | present |= snd_hda_jack_detect(codec, nid); |
| 3376 | } |
| 3377 | return present; |
| 3378 | } |
| 3379 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3380 | /* auto-mute/unmute speaker and line outs according to headphone jack */ |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3381 | static void cx_auto_update_speakers(struct hda_codec *codec) |
| 3382 | { |
| 3383 | struct conexant_spec *spec = codec->spec; |
| 3384 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | e2df82f | 2011-05-24 11:49:12 +0200 | [diff] [blame] | 3385 | int on = 1; |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3386 | |
Takashi Iwai | e2df82f | 2011-05-24 11:49:12 +0200 | [diff] [blame] | 3387 | /* turn on HP EAPD when HP jacks are present */ |
Takashi Iwai | 254f296 | 2011-10-14 15:22:34 +0200 | [diff] [blame] | 3388 | if (spec->pin_eapd_ctrls) { |
| 3389 | if (spec->auto_mute) |
| 3390 | on = spec->hp_present; |
| 3391 | cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on); |
| 3392 | } |
| 3393 | |
Takashi Iwai | e2df82f | 2011-05-24 11:49:12 +0200 | [diff] [blame] | 3394 | /* mute speakers in auto-mode if HP or LO jacks are plugged */ |
| 3395 | if (spec->auto_mute) |
| 3396 | on = !(spec->hp_present || |
| 3397 | (spec->detect_line && spec->line_present)); |
| 3398 | do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on); |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3399 | |
| 3400 | /* toggle line-out mutes if needed, too */ |
| 3401 | /* if LO is a copy of either HP or Speaker, don't need to handle it */ |
| 3402 | if (cfg->line_out_pins[0] == cfg->hp_pins[0] || |
| 3403 | cfg->line_out_pins[0] == cfg->speaker_pins[0]) |
| 3404 | return; |
Takashi Iwai | e2df82f | 2011-05-24 11:49:12 +0200 | [diff] [blame] | 3405 | if (spec->auto_mute) { |
| 3406 | /* mute LO in auto-mode when HP jack is present */ |
| 3407 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT || |
| 3408 | spec->automute_lines) |
| 3409 | on = !spec->hp_present; |
| 3410 | else |
| 3411 | on = 1; |
| 3412 | } |
| 3413 | do_automute(codec, cfg->line_outs, cfg->line_out_pins, on); |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3414 | } |
| 3415 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3416 | static void cx_auto_hp_automute(struct hda_codec *codec) |
| 3417 | { |
| 3418 | struct conexant_spec *spec = codec->spec; |
| 3419 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3420 | |
| 3421 | if (!spec->auto_mute) |
| 3422 | return; |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3423 | spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins); |
| 3424 | cx_auto_update_speakers(codec); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3425 | } |
| 3426 | |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3427 | static void cx_auto_line_automute(struct hda_codec *codec) |
| 3428 | { |
| 3429 | struct conexant_spec *spec = codec->spec; |
| 3430 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3431 | |
| 3432 | if (!spec->auto_mute || !spec->detect_line) |
| 3433 | return; |
| 3434 | spec->line_present = detect_jacks(codec, cfg->line_outs, |
| 3435 | cfg->line_out_pins); |
| 3436 | cx_auto_update_speakers(codec); |
| 3437 | } |
| 3438 | |
| 3439 | static int cx_automute_mode_info(struct snd_kcontrol *kcontrol, |
| 3440 | struct snd_ctl_elem_info *uinfo) |
| 3441 | { |
| 3442 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3443 | struct conexant_spec *spec = codec->spec; |
| 3444 | static const char * const texts2[] = { |
| 3445 | "Disabled", "Enabled" |
| 3446 | }; |
| 3447 | static const char * const texts3[] = { |
Takashi Iwai | e49a343 | 2012-03-01 18:14:41 +0100 | [diff] [blame] | 3448 | "Disabled", "Speaker Only", "Line Out+Speaker" |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3449 | }; |
| 3450 | const char * const *texts; |
| 3451 | |
| 3452 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 3453 | uinfo->count = 1; |
| 3454 | if (spec->automute_hp_lo) { |
| 3455 | uinfo->value.enumerated.items = 3; |
| 3456 | texts = texts3; |
| 3457 | } else { |
| 3458 | uinfo->value.enumerated.items = 2; |
| 3459 | texts = texts2; |
| 3460 | } |
| 3461 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 3462 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
| 3463 | strcpy(uinfo->value.enumerated.name, |
| 3464 | texts[uinfo->value.enumerated.item]); |
| 3465 | return 0; |
| 3466 | } |
| 3467 | |
| 3468 | static int cx_automute_mode_get(struct snd_kcontrol *kcontrol, |
| 3469 | struct snd_ctl_elem_value *ucontrol) |
| 3470 | { |
| 3471 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3472 | struct conexant_spec *spec = codec->spec; |
| 3473 | unsigned int val; |
| 3474 | if (!spec->auto_mute) |
| 3475 | val = 0; |
| 3476 | else if (!spec->automute_lines) |
| 3477 | val = 1; |
| 3478 | else |
| 3479 | val = 2; |
| 3480 | ucontrol->value.enumerated.item[0] = val; |
| 3481 | return 0; |
| 3482 | } |
| 3483 | |
| 3484 | static int cx_automute_mode_put(struct snd_kcontrol *kcontrol, |
| 3485 | struct snd_ctl_elem_value *ucontrol) |
| 3486 | { |
| 3487 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3488 | struct conexant_spec *spec = codec->spec; |
| 3489 | |
| 3490 | switch (ucontrol->value.enumerated.item[0]) { |
| 3491 | case 0: |
| 3492 | if (!spec->auto_mute) |
| 3493 | return 0; |
| 3494 | spec->auto_mute = 0; |
| 3495 | break; |
| 3496 | case 1: |
| 3497 | if (spec->auto_mute && !spec->automute_lines) |
| 3498 | return 0; |
| 3499 | spec->auto_mute = 1; |
| 3500 | spec->automute_lines = 0; |
| 3501 | break; |
| 3502 | case 2: |
| 3503 | if (!spec->automute_hp_lo) |
| 3504 | return -EINVAL; |
| 3505 | if (spec->auto_mute && spec->automute_lines) |
| 3506 | return 0; |
| 3507 | spec->auto_mute = 1; |
| 3508 | spec->automute_lines = 1; |
| 3509 | break; |
| 3510 | default: |
| 3511 | return -EINVAL; |
| 3512 | } |
| 3513 | cx_auto_update_speakers(codec); |
| 3514 | return 1; |
| 3515 | } |
| 3516 | |
| 3517 | static const struct snd_kcontrol_new cx_automute_mode_enum[] = { |
| 3518 | { |
| 3519 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3520 | .name = "Auto-Mute Mode", |
| 3521 | .info = cx_automute_mode_info, |
| 3522 | .get = cx_automute_mode_get, |
| 3523 | .put = cx_automute_mode_put, |
| 3524 | }, |
| 3525 | { } |
| 3526 | }; |
| 3527 | |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3528 | static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 3529 | struct snd_ctl_elem_info *uinfo) |
| 3530 | { |
| 3531 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3532 | struct conexant_spec *spec = codec->spec; |
| 3533 | |
| 3534 | return snd_hda_input_mux_info(&spec->private_imux, uinfo); |
| 3535 | } |
| 3536 | |
| 3537 | static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 3538 | struct snd_ctl_elem_value *ucontrol) |
| 3539 | { |
| 3540 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3541 | struct conexant_spec *spec = codec->spec; |
| 3542 | |
| 3543 | ucontrol->value.enumerated.item[0] = spec->cur_mux[0]; |
| 3544 | return 0; |
| 3545 | } |
| 3546 | |
Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3547 | /* look for the route the given pin from mux and return the index; |
| 3548 | * if do_select is set, actually select the route. |
| 3549 | */ |
| 3550 | static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux, |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 3551 | hda_nid_t pin, hda_nid_t *srcp, |
| 3552 | bool do_select, int depth) |
Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3553 | { |
| 3554 | hda_nid_t conn[HDA_MAX_NUM_INPUTS]; |
| 3555 | int i, nums; |
| 3556 | |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 3557 | switch (get_wcaps_type(get_wcaps(codec, mux))) { |
| 3558 | case AC_WID_AUD_IN: |
| 3559 | case AC_WID_AUD_SEL: |
| 3560 | case AC_WID_AUD_MIX: |
| 3561 | break; |
| 3562 | default: |
| 3563 | return -1; |
| 3564 | } |
| 3565 | |
Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3566 | nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); |
| 3567 | for (i = 0; i < nums; i++) |
| 3568 | if (conn[i] == pin) { |
| 3569 | if (do_select) |
| 3570 | snd_hda_codec_write(codec, mux, 0, |
| 3571 | AC_VERB_SET_CONNECT_SEL, i); |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 3572 | if (srcp) |
| 3573 | *srcp = mux; |
Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3574 | return i; |
| 3575 | } |
| 3576 | depth++; |
| 3577 | if (depth == 2) |
| 3578 | return -1; |
| 3579 | for (i = 0; i < nums; i++) { |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 3580 | int ret = __select_input_connection(codec, conn[i], pin, srcp, |
Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3581 | do_select, depth); |
| 3582 | if (ret >= 0) { |
| 3583 | if (do_select) |
| 3584 | snd_hda_codec_write(codec, mux, 0, |
| 3585 | AC_VERB_SET_CONNECT_SEL, i); |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 3586 | return i; |
Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3587 | } |
| 3588 | } |
| 3589 | return -1; |
| 3590 | } |
| 3591 | |
| 3592 | static void select_input_connection(struct hda_codec *codec, hda_nid_t mux, |
| 3593 | hda_nid_t pin) |
| 3594 | { |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 3595 | __select_input_connection(codec, mux, pin, NULL, true, 0); |
Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3596 | } |
| 3597 | |
| 3598 | static int get_input_connection(struct hda_codec *codec, hda_nid_t mux, |
| 3599 | hda_nid_t pin) |
| 3600 | { |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 3601 | return __select_input_connection(codec, mux, pin, NULL, false, 0); |
Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3602 | } |
| 3603 | |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3604 | static int cx_auto_mux_enum_update(struct hda_codec *codec, |
| 3605 | const struct hda_input_mux *imux, |
| 3606 | unsigned int idx) |
| 3607 | { |
| 3608 | struct conexant_spec *spec = codec->spec; |
| 3609 | hda_nid_t adc; |
Takashi Iwai | 313d2c0 | 2011-05-23 20:27:02 +0200 | [diff] [blame] | 3610 | int changed = 1; |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3611 | |
| 3612 | if (!imux->num_items) |
| 3613 | return 0; |
| 3614 | if (idx >= imux->num_items) |
| 3615 | idx = imux->num_items - 1; |
| 3616 | if (spec->cur_mux[0] == idx) |
Takashi Iwai | 313d2c0 | 2011-05-23 20:27:02 +0200 | [diff] [blame] | 3617 | changed = 0; |
Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 3618 | adc = spec->imux_info[idx].adc; |
| 3619 | select_input_connection(codec, spec->imux_info[idx].adc, |
| 3620 | spec->imux_info[idx].pin); |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3621 | if (spec->cur_adc && spec->cur_adc != adc) { |
| 3622 | /* stream is running, let's swap the current ADC */ |
| 3623 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); |
| 3624 | spec->cur_adc = adc; |
| 3625 | snd_hda_codec_setup_stream(codec, adc, |
| 3626 | spec->cur_adc_stream_tag, 0, |
| 3627 | spec->cur_adc_format); |
| 3628 | } |
| 3629 | spec->cur_mux[0] = idx; |
Takashi Iwai | 313d2c0 | 2011-05-23 20:27:02 +0200 | [diff] [blame] | 3630 | return changed; |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3631 | } |
| 3632 | |
| 3633 | static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 3634 | struct snd_ctl_elem_value *ucontrol) |
| 3635 | { |
| 3636 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3637 | struct conexant_spec *spec = codec->spec; |
| 3638 | |
| 3639 | return cx_auto_mux_enum_update(codec, &spec->private_imux, |
| 3640 | ucontrol->value.enumerated.item[0]); |
| 3641 | } |
| 3642 | |
| 3643 | static const struct snd_kcontrol_new cx_auto_capture_mixers[] = { |
| 3644 | { |
| 3645 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3646 | .name = "Capture Source", |
| 3647 | .info = cx_auto_mux_enum_info, |
| 3648 | .get = cx_auto_mux_enum_get, |
| 3649 | .put = cx_auto_mux_enum_put |
| 3650 | }, |
| 3651 | {} |
| 3652 | }; |
| 3653 | |
Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3654 | static bool select_automic(struct hda_codec *codec, int idx, bool detect) |
| 3655 | { |
| 3656 | struct conexant_spec *spec = codec->spec; |
| 3657 | if (idx < 0) |
| 3658 | return false; |
| 3659 | if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin)) |
| 3660 | return false; |
| 3661 | cx_auto_mux_enum_update(codec, &spec->private_imux, idx); |
| 3662 | return true; |
| 3663 | } |
| 3664 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3665 | /* automatic switch internal and external mic */ |
| 3666 | static void cx_auto_automic(struct hda_codec *codec) |
| 3667 | { |
| 3668 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3669 | |
| 3670 | if (!spec->auto_mic) |
| 3671 | return; |
Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3672 | if (!select_automic(codec, spec->auto_mic_ext, true)) |
| 3673 | if (!select_automic(codec, spec->auto_mic_dock, true)) |
| 3674 | select_automic(codec, spec->auto_mic_int, false); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3675 | } |
| 3676 | |
| 3677 | static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) |
| 3678 | { |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 3679 | switch (snd_hda_jack_get_action(codec, res >> 26)) { |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3680 | case CONEXANT_HP_EVENT: |
| 3681 | cx_auto_hp_automute(codec); |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3682 | break; |
| 3683 | case CONEXANT_LINE_EVENT: |
| 3684 | cx_auto_line_automute(codec); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3685 | break; |
| 3686 | case CONEXANT_MIC_EVENT: |
| 3687 | cx_auto_automic(codec); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3688 | break; |
| 3689 | } |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 3690 | snd_hda_jack_report_sync(codec); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3691 | } |
| 3692 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3693 | /* check whether the pin config is suitable for auto-mic switching; |
Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3694 | * auto-mic is enabled only when one int-mic and one ext- and/or |
| 3695 | * one dock-mic exist |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3696 | */ |
| 3697 | static void cx_auto_check_auto_mic(struct hda_codec *codec) |
| 3698 | { |
| 3699 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3700 | int pset[INPUT_PIN_ATTR_NORMAL + 1]; |
| 3701 | int i; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3702 | |
Takashi Iwai | 506a419 | 2011-05-23 20:07:15 +0200 | [diff] [blame] | 3703 | for (i = 0; i < ARRAY_SIZE(pset); i++) |
Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3704 | pset[i] = -1; |
| 3705 | for (i = 0; i < spec->private_imux.num_items; i++) { |
| 3706 | hda_nid_t pin = spec->imux_info[i].pin; |
| 3707 | unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); |
Takashi Iwai | b55fcb5 | 2011-05-17 12:57:46 +0200 | [diff] [blame] | 3708 | int type, attr; |
Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3709 | attr = snd_hda_get_input_pin_attr(def_conf); |
| 3710 | if (attr == INPUT_PIN_ATTR_UNUSED) |
Takashi Iwai | b55fcb5 | 2011-05-17 12:57:46 +0200 | [diff] [blame] | 3711 | return; /* invalid entry */ |
Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3712 | if (attr > INPUT_PIN_ATTR_NORMAL) |
| 3713 | attr = INPUT_PIN_ATTR_NORMAL; |
| 3714 | if (attr != INPUT_PIN_ATTR_INT && |
| 3715 | !is_jack_detectable(codec, pin)) |
Takashi Iwai | b55fcb5 | 2011-05-17 12:57:46 +0200 | [diff] [blame] | 3716 | return; /* non-detectable pin */ |
| 3717 | type = get_defcfg_device(def_conf); |
| 3718 | if (type != AC_JACK_MIC_IN && |
| 3719 | (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN)) |
| 3720 | return; /* no valid input type */ |
Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3721 | if (pset[attr] >= 0) |
| 3722 | return; /* already occupied */ |
| 3723 | pset[attr] = i; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3724 | } |
Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3725 | if (pset[INPUT_PIN_ATTR_INT] < 0 || |
| 3726 | (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK])) |
| 3727 | return; /* no input to switch*/ |
| 3728 | spec->auto_mic = 1; |
| 3729 | spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL]; |
| 3730 | spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK]; |
| 3731 | spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT]; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | static void cx_auto_parse_input(struct hda_codec *codec) |
| 3735 | { |
| 3736 | struct conexant_spec *spec = codec->spec; |
| 3737 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3738 | struct hda_input_mux *imux; |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3739 | int i, j; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3740 | |
| 3741 | imux = &spec->private_imux; |
| 3742 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3743 | for (j = 0; j < spec->num_adc_nids; j++) { |
| 3744 | hda_nid_t adc = spec->adc_nids[j]; |
Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3745 | int idx = get_input_connection(codec, adc, |
| 3746 | cfg->inputs[i].pin); |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3747 | if (idx >= 0) { |
| 3748 | const char *label; |
| 3749 | label = hda_get_autocfg_input_label(codec, cfg, i); |
Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 3750 | spec->imux_info[imux->num_items].index = i; |
| 3751 | spec->imux_info[imux->num_items].boost = 0; |
| 3752 | spec->imux_info[imux->num_items].adc = adc; |
| 3753 | spec->imux_info[imux->num_items].pin = |
Takashi Iwai | f6100bb | 2011-05-13 18:26:39 +0200 | [diff] [blame] | 3754 | cfg->inputs[i].pin; |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3755 | snd_hda_add_imux_item(imux, label, idx, NULL); |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3756 | break; |
| 3757 | } |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3758 | } |
| 3759 | } |
Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3760 | if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items) |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3761 | cx_auto_check_auto_mic(codec); |
Takashi Iwai | 7675535 | 2011-08-24 10:53:10 +0200 | [diff] [blame] | 3762 | if (imux->num_items > 1) { |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3763 | for (i = 1; i < imux->num_items; i++) { |
Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 3764 | if (spec->imux_info[i].adc != spec->imux_info[0].adc) { |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3765 | spec->adc_switching = 1; |
| 3766 | break; |
| 3767 | } |
| 3768 | } |
| 3769 | } |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | /* get digital-input audio widget corresponding to the given pin */ |
| 3773 | static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) |
| 3774 | { |
| 3775 | hda_nid_t nid, end_nid; |
| 3776 | |
| 3777 | end_nid = codec->start_nid + codec->num_nodes; |
| 3778 | for (nid = codec->start_nid; nid < end_nid; nid++) { |
| 3779 | unsigned int wcaps = get_wcaps(codec, nid); |
| 3780 | unsigned int type = get_wcaps_type(wcaps); |
| 3781 | if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { |
| 3782 | if (get_connection_index(codec, nid, pin) >= 0) |
| 3783 | return nid; |
| 3784 | } |
| 3785 | } |
| 3786 | return 0; |
| 3787 | } |
| 3788 | |
| 3789 | static void cx_auto_parse_digital(struct hda_codec *codec) |
| 3790 | { |
| 3791 | struct conexant_spec *spec = codec->spec; |
| 3792 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3793 | hda_nid_t nid; |
| 3794 | |
| 3795 | if (cfg->dig_outs && |
| 3796 | snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) |
| 3797 | spec->multiout.dig_out_nid = nid; |
| 3798 | if (cfg->dig_in_pin) |
| 3799 | spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); |
| 3800 | } |
| 3801 | |
| 3802 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
| 3803 | static void cx_auto_parse_beep(struct hda_codec *codec) |
| 3804 | { |
| 3805 | struct conexant_spec *spec = codec->spec; |
| 3806 | hda_nid_t nid, end_nid; |
| 3807 | |
| 3808 | end_nid = codec->start_nid + codec->num_nodes; |
| 3809 | for (nid = codec->start_nid; nid < end_nid; nid++) |
| 3810 | if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { |
| 3811 | set_beep_amp(spec, nid, 0, HDA_OUTPUT); |
| 3812 | break; |
| 3813 | } |
| 3814 | } |
| 3815 | #else |
| 3816 | #define cx_auto_parse_beep(codec) |
| 3817 | #endif |
| 3818 | |
Takashi Iwai | 254f296 | 2011-10-14 15:22:34 +0200 | [diff] [blame] | 3819 | /* parse EAPDs */ |
Takashi Iwai | 1911059 | 2011-07-11 14:46:44 +0200 | [diff] [blame] | 3820 | static void cx_auto_parse_eapd(struct hda_codec *codec) |
| 3821 | { |
| 3822 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | 1911059 | 2011-07-11 14:46:44 +0200 | [diff] [blame] | 3823 | hda_nid_t nid, end_nid; |
| 3824 | |
| 3825 | end_nid = codec->start_nid + codec->num_nodes; |
| 3826 | for (nid = codec->start_nid; nid < end_nid; nid++) { |
| 3827 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) |
| 3828 | continue; |
| 3829 | if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) |
| 3830 | continue; |
Takashi Iwai | 1911059 | 2011-07-11 14:46:44 +0200 | [diff] [blame] | 3831 | spec->eapds[spec->num_eapds++] = nid; |
| 3832 | if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) |
| 3833 | break; |
| 3834 | } |
Takashi Iwai | 254f296 | 2011-10-14 15:22:34 +0200 | [diff] [blame] | 3835 | |
| 3836 | /* NOTE: below is a wild guess; if we have more than two EAPDs, |
| 3837 | * it's a new chip, where EAPDs are supposed to be associated to |
| 3838 | * pins, and we can control EAPD per pin. |
| 3839 | * OTOH, if only one or two EAPDs are found, it's an old chip, |
| 3840 | * thus it might control over all pins. |
| 3841 | */ |
| 3842 | spec->pin_eapd_ctrls = spec->num_eapds > 2; |
Takashi Iwai | 1911059 | 2011-07-11 14:46:44 +0200 | [diff] [blame] | 3843 | } |
| 3844 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3845 | static int cx_auto_parse_auto_config(struct hda_codec *codec) |
| 3846 | { |
| 3847 | struct conexant_spec *spec = codec->spec; |
| 3848 | int err; |
| 3849 | |
| 3850 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 3851 | if (err < 0) |
| 3852 | return err; |
| 3853 | |
| 3854 | cx_auto_parse_output(codec); |
| 3855 | cx_auto_parse_input(codec); |
| 3856 | cx_auto_parse_digital(codec); |
| 3857 | cx_auto_parse_beep(codec); |
Takashi Iwai | 1911059 | 2011-07-11 14:46:44 +0200 | [diff] [blame] | 3858 | cx_auto_parse_eapd(codec); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3859 | return 0; |
| 3860 | } |
| 3861 | |
Takashi Iwai | da33986 | 2011-05-13 16:24:15 +0200 | [diff] [blame] | 3862 | static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, |
| 3863 | hda_nid_t *pins, bool on) |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3864 | { |
| 3865 | int i; |
| 3866 | for (i = 0; i < num_pins; i++) { |
| 3867 | if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) |
| 3868 | snd_hda_codec_write(codec, pins[i], 0, |
Takashi Iwai | da33986 | 2011-05-13 16:24:15 +0200 | [diff] [blame] | 3869 | AC_VERB_SET_EAPD_BTLENABLE, |
| 3870 | on ? 0x02 : 0); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3871 | } |
| 3872 | } |
| 3873 | |
| 3874 | static void select_connection(struct hda_codec *codec, hda_nid_t pin, |
| 3875 | hda_nid_t src) |
| 3876 | { |
| 3877 | int idx = get_connection_index(codec, pin, src); |
| 3878 | if (idx >= 0) |
| 3879 | snd_hda_codec_write(codec, pin, 0, |
| 3880 | AC_VERB_SET_CONNECT_SEL, idx); |
| 3881 | } |
| 3882 | |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 3883 | static void mute_outputs(struct hda_codec *codec, int num_nids, |
| 3884 | const hda_nid_t *nids) |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3885 | { |
Takashi Iwai | 0ad1b5b | 2011-05-13 16:43:12 +0200 | [diff] [blame] | 3886 | int i, val; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3887 | |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 3888 | for (i = 0; i < num_nids; i++) { |
| 3889 | hda_nid_t nid = nids[i]; |
| 3890 | if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) |
| 3891 | continue; |
Takashi Iwai | 0ad1b5b | 2011-05-13 16:43:12 +0200 | [diff] [blame] | 3892 | if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE) |
| 3893 | val = AMP_OUT_MUTE; |
| 3894 | else |
| 3895 | val = AMP_OUT_ZERO; |
| 3896 | snd_hda_codec_write(codec, nid, 0, |
| 3897 | AC_VERB_SET_AMP_GAIN_MUTE, val); |
| 3898 | } |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 3899 | } |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3900 | |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3901 | static void enable_unsol_pins(struct hda_codec *codec, int num_pins, |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 3902 | hda_nid_t *pins, unsigned int action) |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3903 | { |
| 3904 | int i; |
| 3905 | for (i = 0; i < num_pins; i++) |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 3906 | snd_hda_jack_detect_enable(codec, pins[i], action); |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3907 | } |
| 3908 | |
Takashi Iwai | 07cafff | 2012-02-20 12:30:59 +0100 | [diff] [blame] | 3909 | static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 3910 | { |
| 3911 | int i; |
| 3912 | for (i = 0; i < nums; i++) |
| 3913 | if (list[i] == nid) |
| 3914 | return true; |
| 3915 | return false; |
| 3916 | } |
| 3917 | |
| 3918 | /* is the given NID found in any of autocfg items? */ |
| 3919 | static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid) |
| 3920 | { |
| 3921 | int i; |
| 3922 | |
| 3923 | if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) || |
| 3924 | found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) || |
| 3925 | found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) || |
| 3926 | found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs)) |
| 3927 | return true; |
| 3928 | for (i = 0; i < cfg->num_inputs; i++) |
| 3929 | if (cfg->inputs[i].pin == nid) |
| 3930 | return true; |
| 3931 | if (cfg->dig_in_pin == nid) |
| 3932 | return true; |
| 3933 | return false; |
| 3934 | } |
| 3935 | |
| 3936 | /* clear unsol-event tags on unused pins; Conexant codecs seem to leave |
| 3937 | * invalid unsol tags by some reason |
| 3938 | */ |
| 3939 | static void clear_unsol_on_unused_pins(struct hda_codec *codec) |
| 3940 | { |
| 3941 | struct conexant_spec *spec = codec->spec; |
| 3942 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3943 | int i; |
| 3944 | |
| 3945 | for (i = 0; i < codec->init_pins.used; i++) { |
| 3946 | struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); |
| 3947 | if (!found_in_autocfg(cfg, pin->nid)) |
| 3948 | snd_hda_codec_write(codec, pin->nid, 0, |
| 3949 | AC_VERB_SET_UNSOLICITED_ENABLE, 0); |
| 3950 | } |
| 3951 | } |
| 3952 | |
Takashi Iwai | 527c73b | 2012-03-12 12:38:51 +0100 | [diff] [blame] | 3953 | /* turn on/off EAPD according to Master switch */ |
| 3954 | static void cx_auto_vmaster_hook(void *private_data, int enabled) |
| 3955 | { |
| 3956 | struct hda_codec *codec = private_data; |
| 3957 | struct conexant_spec *spec = codec->spec; |
| 3958 | |
| 3959 | if (enabled && spec->pin_eapd_ctrls) { |
| 3960 | cx_auto_update_speakers(codec); |
| 3961 | return; |
| 3962 | } |
| 3963 | cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled); |
| 3964 | } |
| 3965 | |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 3966 | static void cx_auto_init_output(struct hda_codec *codec) |
| 3967 | { |
| 3968 | struct conexant_spec *spec = codec->spec; |
| 3969 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3970 | hda_nid_t nid; |
| 3971 | int i; |
| 3972 | |
| 3973 | mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids); |
Takashi Iwai | ca3649d | 2012-04-19 15:15:25 +0200 | [diff] [blame] | 3974 | for (i = 0; i < cfg->hp_outs; i++) { |
| 3975 | unsigned int val = PIN_OUT; |
| 3976 | if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) & |
| 3977 | AC_PINCAP_HP_DRV) |
| 3978 | val |= AC_PINCTL_HP_EN; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3979 | snd_hda_codec_write(codec, cfg->hp_pins[i], 0, |
Takashi Iwai | ca3649d | 2012-04-19 15:15:25 +0200 | [diff] [blame] | 3980 | AC_VERB_SET_PIN_WIDGET_CONTROL, val); |
| 3981 | } |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 3982 | mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); |
| 3983 | mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); |
| 3984 | mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3985 | for (i = 0; i < spec->dac_info_filled; i++) { |
| 3986 | nid = spec->dac_info[i].dac; |
| 3987 | if (!nid) |
| 3988 | nid = spec->multiout.dac_nids[0]; |
Takashi Iwai | 1f015f5 | 2011-08-23 14:57:08 +0200 | [diff] [blame] | 3989 | else if (nid & DAC_SLAVE_FLAG) |
| 3990 | nid &= ~DAC_SLAVE_FLAG; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3991 | select_connection(codec, spec->dac_info[i].pin, nid); |
| 3992 | } |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3993 | if (spec->auto_mute) { |
| 3994 | enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins, |
| 3995 | CONEXANT_HP_EVENT); |
| 3996 | spec->hp_present = detect_jacks(codec, cfg->hp_outs, |
| 3997 | cfg->hp_pins); |
| 3998 | if (spec->detect_line) { |
| 3999 | enable_unsol_pins(codec, cfg->line_outs, |
| 4000 | cfg->line_out_pins, |
| 4001 | CONEXANT_LINE_EVENT); |
| 4002 | spec->line_present = |
| 4003 | detect_jacks(codec, cfg->line_outs, |
| 4004 | cfg->line_out_pins); |
| 4005 | } |
| 4006 | } |
| 4007 | cx_auto_update_speakers(codec); |
Takashi Iwai | 254f296 | 2011-10-14 15:22:34 +0200 | [diff] [blame] | 4008 | /* turn on all EAPDs if no individual EAPD control is available */ |
| 4009 | if (!spec->pin_eapd_ctrls) |
| 4010 | cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); |
Takashi Iwai | 07cafff | 2012-02-20 12:30:59 +0100 | [diff] [blame] | 4011 | clear_unsol_on_unused_pins(codec); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | static void cx_auto_init_input(struct hda_codec *codec) |
| 4015 | { |
| 4016 | struct conexant_spec *spec = codec->spec; |
| 4017 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 0ad1b5b | 2011-05-13 16:43:12 +0200 | [diff] [blame] | 4018 | int i, val; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4019 | |
Takashi Iwai | 0ad1b5b | 2011-05-13 16:43:12 +0200 | [diff] [blame] | 4020 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 4021 | hda_nid_t nid = spec->adc_nids[i]; |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 4022 | if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) |
| 4023 | continue; |
Takashi Iwai | 0ad1b5b | 2011-05-13 16:43:12 +0200 | [diff] [blame] | 4024 | if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE) |
| 4025 | val = AMP_IN_MUTE(0); |
| 4026 | else |
| 4027 | val = AMP_IN_UNMUTE(0); |
| 4028 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 4029 | val); |
| 4030 | } |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4031 | |
| 4032 | for (i = 0; i < cfg->num_inputs; i++) { |
| 4033 | unsigned int type; |
| 4034 | if (cfg->inputs[i].type == AUTO_PIN_MIC) |
| 4035 | type = PIN_VREF80; |
| 4036 | else |
| 4037 | type = PIN_IN; |
| 4038 | snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, |
| 4039 | AC_VERB_SET_PIN_WIDGET_CONTROL, type); |
| 4040 | } |
| 4041 | |
| 4042 | if (spec->auto_mic) { |
Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 4043 | if (spec->auto_mic_ext >= 0) { |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 4044 | snd_hda_jack_detect_enable(codec, |
| 4045 | cfg->inputs[spec->auto_mic_ext].pin, |
| 4046 | CONEXANT_MIC_EVENT); |
Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 4047 | } |
| 4048 | if (spec->auto_mic_dock >= 0) { |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 4049 | snd_hda_jack_detect_enable(codec, |
| 4050 | cfg->inputs[spec->auto_mic_dock].pin, |
| 4051 | CONEXANT_MIC_EVENT); |
Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 4052 | } |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4053 | cx_auto_automic(codec); |
| 4054 | } else { |
Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4055 | select_input_connection(codec, spec->imux_info[0].adc, |
| 4056 | spec->imux_info[0].pin); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4057 | } |
| 4058 | } |
| 4059 | |
| 4060 | static void cx_auto_init_digital(struct hda_codec *codec) |
| 4061 | { |
| 4062 | struct conexant_spec *spec = codec->spec; |
| 4063 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 4064 | |
| 4065 | if (spec->multiout.dig_out_nid) |
| 4066 | snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, |
| 4067 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); |
| 4068 | if (spec->dig_in_nid) |
| 4069 | snd_hda_codec_write(codec, cfg->dig_in_pin, 0, |
| 4070 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); |
| 4071 | } |
| 4072 | |
| 4073 | static int cx_auto_init(struct hda_codec *codec) |
| 4074 | { |
Takashi Iwai | 527c73b | 2012-03-12 12:38:51 +0100 | [diff] [blame] | 4075 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4076 | /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ |
| 4077 | cx_auto_init_output(codec); |
| 4078 | cx_auto_init_input(codec); |
| 4079 | cx_auto_init_digital(codec); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 4080 | snd_hda_jack_report_sync(codec); |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 4081 | snd_hda_sync_vmaster_hook(&spec->vmaster_mute); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4082 | return 0; |
| 4083 | } |
| 4084 | |
David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4085 | static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4086 | const char *dir, int cidx, |
David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4087 | hda_nid_t nid, int hda_dir, int amp_idx) |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4088 | { |
| 4089 | static char name[32]; |
| 4090 | static struct snd_kcontrol_new knew[] = { |
| 4091 | HDA_CODEC_VOLUME(name, 0, 0, 0), |
| 4092 | HDA_CODEC_MUTE(name, 0, 0, 0), |
| 4093 | }; |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 4094 | static const char * const sfx[2] = { "Volume", "Switch" }; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4095 | int i, err; |
| 4096 | |
| 4097 | for (i = 0; i < 2; i++) { |
| 4098 | struct snd_kcontrol *kctl; |
David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4099 | knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx, |
| 4100 | hda_dir); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4101 | knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; |
| 4102 | knew[i].index = cidx; |
| 4103 | snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); |
| 4104 | kctl = snd_ctl_new1(&knew[i], codec); |
| 4105 | if (!kctl) |
| 4106 | return -ENOMEM; |
| 4107 | err = snd_hda_ctl_add(codec, nid, kctl); |
| 4108 | if (err < 0) |
| 4109 | return err; |
Takashi Iwai | 3868137 | 2012-02-27 15:00:58 +0100 | [diff] [blame] | 4110 | if (!(query_amp_caps(codec, nid, hda_dir) & |
| 4111 | (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))) |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4112 | break; |
| 4113 | } |
| 4114 | return 0; |
| 4115 | } |
| 4116 | |
David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4117 | #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ |
| 4118 | cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0) |
| 4119 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4120 | #define cx_auto_add_pb_volume(codec, nid, str, idx) \ |
| 4121 | cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) |
| 4122 | |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 4123 | static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac, |
| 4124 | hda_nid_t pin, const char *name, int idx) |
| 4125 | { |
| 4126 | unsigned int caps; |
David Henningsson | 468c545 | 2011-08-25 13:16:02 +0200 | [diff] [blame] | 4127 | if (dac && !(dac & DAC_SLAVE_FLAG)) { |
| 4128 | caps = query_amp_caps(codec, dac, HDA_OUTPUT); |
| 4129 | if (caps & AC_AMPCAP_NUM_STEPS) |
| 4130 | return cx_auto_add_pb_volume(codec, dac, name, idx); |
| 4131 | } |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 4132 | caps = query_amp_caps(codec, pin, HDA_OUTPUT); |
| 4133 | if (caps & AC_AMPCAP_NUM_STEPS) |
| 4134 | return cx_auto_add_pb_volume(codec, pin, name, idx); |
| 4135 | return 0; |
| 4136 | } |
| 4137 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4138 | static int cx_auto_build_output_controls(struct hda_codec *codec) |
| 4139 | { |
| 4140 | struct conexant_spec *spec = codec->spec; |
| 4141 | int i, err; |
| 4142 | int num_line = 0, num_hp = 0, num_spk = 0; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 4143 | static const char * const texts[3] = { "Front", "Surround", "CLFE" }; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4144 | |
| 4145 | if (spec->dac_info_filled == 1) |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 4146 | return try_add_pb_volume(codec, spec->dac_info[0].dac, |
| 4147 | spec->dac_info[0].pin, |
| 4148 | "Master", 0); |
| 4149 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4150 | for (i = 0; i < spec->dac_info_filled; i++) { |
| 4151 | const char *label; |
| 4152 | int idx, type; |
Takashi Iwai | 1f015f5 | 2011-08-23 14:57:08 +0200 | [diff] [blame] | 4153 | hda_nid_t dac = spec->dac_info[i].dac; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4154 | type = spec->dac_info[i].type; |
| 4155 | if (type == AUTO_PIN_LINE_OUT) |
| 4156 | type = spec->autocfg.line_out_type; |
| 4157 | switch (type) { |
| 4158 | case AUTO_PIN_LINE_OUT: |
| 4159 | default: |
| 4160 | label = texts[num_line++]; |
| 4161 | idx = 0; |
| 4162 | break; |
| 4163 | case AUTO_PIN_HP_OUT: |
| 4164 | label = "Headphone"; |
| 4165 | idx = num_hp++; |
| 4166 | break; |
| 4167 | case AUTO_PIN_SPEAKER_OUT: |
| 4168 | label = "Speaker"; |
| 4169 | idx = num_spk++; |
| 4170 | break; |
| 4171 | } |
Takashi Iwai | 1f015f5 | 2011-08-23 14:57:08 +0200 | [diff] [blame] | 4172 | err = try_add_pb_volume(codec, dac, |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 4173 | spec->dac_info[i].pin, |
| 4174 | label, idx); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4175 | if (err < 0) |
| 4176 | return err; |
| 4177 | } |
Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 4178 | |
| 4179 | if (spec->auto_mute) { |
| 4180 | err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum); |
| 4181 | if (err < 0) |
| 4182 | return err; |
| 4183 | } |
| 4184 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4185 | return 0; |
| 4186 | } |
| 4187 | |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4188 | static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, |
| 4189 | const char *label, const char *pfx, |
| 4190 | int cidx) |
| 4191 | { |
| 4192 | struct conexant_spec *spec = codec->spec; |
| 4193 | int i; |
| 4194 | |
| 4195 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 4196 | hda_nid_t adc_nid = spec->adc_nids[i]; |
Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 4197 | int idx = get_input_connection(codec, adc_nid, nid); |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4198 | if (idx < 0) |
| 4199 | continue; |
Michael Karcher | 4f32456 | 2012-04-06 15:34:15 +0200 | [diff] [blame] | 4200 | if (codec->single_adc_amp) |
Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4201 | idx = 0; |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4202 | return cx_auto_add_volume_idx(codec, label, pfx, |
| 4203 | cidx, adc_nid, HDA_INPUT, idx); |
| 4204 | } |
| 4205 | return 0; |
| 4206 | } |
| 4207 | |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4208 | static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx, |
| 4209 | const char *label, int cidx) |
| 4210 | { |
| 4211 | struct conexant_spec *spec = codec->spec; |
| 4212 | hda_nid_t mux, nid; |
Takashi Iwai | f975930 | 2011-05-16 11:45:15 +0200 | [diff] [blame] | 4213 | int i, con; |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4214 | |
Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4215 | nid = spec->imux_info[idx].pin; |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4216 | if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) |
| 4217 | return cx_auto_add_volume(codec, label, " Boost", cidx, |
| 4218 | nid, HDA_INPUT); |
Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4219 | con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, |
| 4220 | &mux, false, 0); |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4221 | if (con < 0) |
| 4222 | return 0; |
Takashi Iwai | f975930 | 2011-05-16 11:45:15 +0200 | [diff] [blame] | 4223 | for (i = 0; i < idx; i++) { |
Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4224 | if (spec->imux_info[i].boost == mux) |
Takashi Iwai | f975930 | 2011-05-16 11:45:15 +0200 | [diff] [blame] | 4225 | return 0; /* already present */ |
| 4226 | } |
| 4227 | |
| 4228 | if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) { |
Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4229 | spec->imux_info[idx].boost = mux; |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4230 | return cx_auto_add_volume(codec, label, " Boost", 0, |
| 4231 | mux, HDA_OUTPUT); |
Takashi Iwai | f975930 | 2011-05-16 11:45:15 +0200 | [diff] [blame] | 4232 | } |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4233 | return 0; |
| 4234 | } |
| 4235 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4236 | static int cx_auto_build_input_controls(struct hda_codec *codec) |
| 4237 | { |
| 4238 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4239 | struct hda_input_mux *imux = &spec->private_imux; |
| 4240 | const char *prev_label; |
| 4241 | int input_conn[HDA_MAX_NUM_INPUTS]; |
Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4242 | int i, j, err, cidx; |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4243 | int multi_connection; |
| 4244 | |
Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4245 | if (!imux->num_items) |
| 4246 | return 0; |
| 4247 | |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4248 | multi_connection = 0; |
| 4249 | for (i = 0; i < imux->num_items; i++) { |
Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4250 | cidx = get_input_connection(codec, spec->imux_info[i].adc, |
| 4251 | spec->imux_info[i].pin); |
Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4252 | if (cidx < 0) |
| 4253 | continue; |
| 4254 | input_conn[i] = spec->imux_info[i].adc; |
Michael Karcher | 4f32456 | 2012-04-06 15:34:15 +0200 | [diff] [blame] | 4255 | if (!codec->single_adc_amp) |
Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4256 | input_conn[i] |= cidx << 8; |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4257 | if (i > 0 && input_conn[i] != input_conn[0]) |
| 4258 | multi_connection = 1; |
| 4259 | } |
David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4260 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4261 | prev_label = NULL; |
| 4262 | cidx = 0; |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4263 | for (i = 0; i < imux->num_items; i++) { |
Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4264 | hda_nid_t nid = spec->imux_info[i].pin; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4265 | const char *label; |
David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4266 | |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4267 | label = hda_get_autocfg_input_label(codec, &spec->autocfg, |
Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4268 | spec->imux_info[i].index); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4269 | if (label == prev_label) |
| 4270 | cidx++; |
| 4271 | else |
| 4272 | cidx = 0; |
| 4273 | prev_label = label; |
David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4274 | |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4275 | err = cx_auto_add_boost_volume(codec, i, label, cidx); |
| 4276 | if (err < 0) |
| 4277 | return err; |
David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4278 | |
Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4279 | if (!multi_connection) { |
Takashi Iwai | f975930 | 2011-05-16 11:45:15 +0200 | [diff] [blame] | 4280 | if (i > 0) |
| 4281 | continue; |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4282 | err = cx_auto_add_capture_volume(codec, nid, |
| 4283 | "Capture", "", cidx); |
| 4284 | } else { |
Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4285 | bool dup_found = false; |
| 4286 | for (j = 0; j < i; j++) { |
| 4287 | if (input_conn[j] == input_conn[i]) { |
| 4288 | dup_found = true; |
| 4289 | break; |
| 4290 | } |
| 4291 | } |
| 4292 | if (dup_found) |
| 4293 | continue; |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4294 | err = cx_auto_add_capture_volume(codec, nid, |
| 4295 | label, " Capture", cidx); |
David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4296 | } |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4297 | if (err < 0) |
| 4298 | return err; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4299 | } |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4300 | |
| 4301 | if (spec->private_imux.num_items > 1 && !spec->auto_mic) { |
| 4302 | err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers); |
| 4303 | if (err < 0) |
| 4304 | return err; |
| 4305 | } |
| 4306 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4307 | return 0; |
| 4308 | } |
| 4309 | |
| 4310 | static int cx_auto_build_controls(struct hda_codec *codec) |
| 4311 | { |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 4312 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4313 | int err; |
| 4314 | |
| 4315 | err = cx_auto_build_output_controls(codec); |
| 4316 | if (err < 0) |
| 4317 | return err; |
| 4318 | err = cx_auto_build_input_controls(codec); |
| 4319 | if (err < 0) |
| 4320 | return err; |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 4321 | err = conexant_build_controls(codec); |
| 4322 | if (err < 0) |
| 4323 | return err; |
| 4324 | err = snd_hda_jack_add_kctls(codec, &spec->autocfg); |
| 4325 | if (err < 0) |
| 4326 | return err; |
Takashi Iwai | f29735c | 2012-03-13 07:55:10 +0100 | [diff] [blame] | 4327 | if (spec->vmaster_mute.sw_kctl) { |
| 4328 | spec->vmaster_mute.hook = cx_auto_vmaster_hook; |
| 4329 | err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, |
| 4330 | spec->vmaster_mute_led); |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 4331 | if (err < 0) |
| 4332 | return err; |
Takashi Iwai | 527c73b | 2012-03-12 12:38:51 +0100 | [diff] [blame] | 4333 | } |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 4334 | return 0; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4335 | } |
| 4336 | |
Takashi Iwai | 22ce5f7 | 2011-05-15 12:19:29 +0200 | [diff] [blame] | 4337 | static int cx_auto_search_adcs(struct hda_codec *codec) |
| 4338 | { |
| 4339 | struct conexant_spec *spec = codec->spec; |
| 4340 | hda_nid_t nid, end_nid; |
| 4341 | |
| 4342 | end_nid = codec->start_nid + codec->num_nodes; |
| 4343 | for (nid = codec->start_nid; nid < end_nid; nid++) { |
| 4344 | unsigned int caps = get_wcaps(codec, nid); |
| 4345 | if (get_wcaps_type(caps) != AC_WID_AUD_IN) |
| 4346 | continue; |
| 4347 | if (caps & AC_WCAP_DIGITAL) |
| 4348 | continue; |
| 4349 | if (snd_BUG_ON(spec->num_adc_nids >= |
| 4350 | ARRAY_SIZE(spec->private_adc_nids))) |
| 4351 | break; |
| 4352 | spec->private_adc_nids[spec->num_adc_nids++] = nid; |
| 4353 | } |
| 4354 | spec->adc_nids = spec->private_adc_nids; |
| 4355 | return 0; |
| 4356 | } |
| 4357 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 4358 | static const struct hda_codec_ops cx_auto_patch_ops = { |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4359 | .build_controls = cx_auto_build_controls, |
| 4360 | .build_pcms = conexant_build_pcms, |
| 4361 | .init = cx_auto_init, |
| 4362 | .free = conexant_free, |
| 4363 | .unsol_event = cx_auto_unsol_event, |
| 4364 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4365 | .suspend = conexant_suspend, |
| 4366 | #endif |
| 4367 | .reboot_notify = snd_hda_shutup_pins, |
| 4368 | }; |
| 4369 | |
Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4370 | /* |
| 4371 | * pin fix-up |
| 4372 | */ |
| 4373 | struct cxt_pincfg { |
| 4374 | hda_nid_t nid; |
| 4375 | u32 val; |
| 4376 | }; |
| 4377 | |
| 4378 | static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg) |
| 4379 | { |
| 4380 | for (; cfg->nid; cfg++) |
| 4381 | snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); |
| 4382 | |
| 4383 | } |
| 4384 | |
| 4385 | static void apply_pin_fixup(struct hda_codec *codec, |
| 4386 | const struct snd_pci_quirk *quirk, |
| 4387 | const struct cxt_pincfg **table) |
| 4388 | { |
| 4389 | quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk); |
| 4390 | if (quirk) { |
| 4391 | snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n", |
| 4392 | quirk->name); |
| 4393 | apply_pincfg(codec, table[quirk->value]); |
| 4394 | } |
| 4395 | } |
| 4396 | |
| 4397 | enum { |
| 4398 | CXT_PINCFG_LENOVO_X200, |
Takashi Iwai | d70f363 | 2012-04-19 15:18:08 +0200 | [diff] [blame] | 4399 | CXT_PINCFG_LENOVO_TP410, |
Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4400 | }; |
| 4401 | |
Takashi Iwai | d70f363 | 2012-04-19 15:18:08 +0200 | [diff] [blame] | 4402 | /* ThinkPad X200 & co with cxt5051 */ |
Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4403 | static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = { |
| 4404 | { 0x16, 0x042140ff }, /* HP (seq# overridden) */ |
| 4405 | { 0x17, 0x21a11000 }, /* dock-mic */ |
| 4406 | { 0x19, 0x2121103f }, /* dock-HP */ |
Takashi Iwai | 3e93f5e | 2012-02-28 21:49:55 +0100 | [diff] [blame] | 4407 | { 0x1c, 0x21440100 }, /* dock SPDIF out */ |
Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4408 | {} |
| 4409 | }; |
| 4410 | |
Takashi Iwai | d70f363 | 2012-04-19 15:18:08 +0200 | [diff] [blame] | 4411 | /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */ |
| 4412 | static const struct cxt_pincfg cxt_pincfg_lenovo_tp410[] = { |
| 4413 | { 0x19, 0x042110ff }, /* HP (seq# overridden) */ |
| 4414 | { 0x1a, 0x21a190f0 }, /* dock-mic */ |
| 4415 | { 0x1c, 0x212140ff }, /* dock-HP */ |
| 4416 | {} |
Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4417 | }; |
| 4418 | |
Takashi Iwai | d70f363 | 2012-04-19 15:18:08 +0200 | [diff] [blame] | 4419 | static const struct cxt_pincfg *cxt_pincfg_tbl[] = { |
| 4420 | [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200, |
| 4421 | [CXT_PINCFG_LENOVO_TP410] = cxt_pincfg_lenovo_tp410, |
| 4422 | }; |
| 4423 | |
| 4424 | static const struct snd_pci_quirk cxt5051_fixups[] = { |
Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4425 | SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200), |
| 4426 | {} |
| 4427 | }; |
| 4428 | |
Takashi Iwai | d70f363 | 2012-04-19 15:18:08 +0200 | [diff] [blame] | 4429 | static const struct snd_pci_quirk cxt5066_fixups[] = { |
| 4430 | SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410), |
| 4431 | SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410), |
| 4432 | SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410), |
| 4433 | SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410), |
| 4434 | SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410), |
| 4435 | {} |
| 4436 | }; |
| 4437 | |
Takashi Iwai | 3868137 | 2012-02-27 15:00:58 +0100 | [diff] [blame] | 4438 | /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches |
| 4439 | * can be created (bko#42825) |
| 4440 | */ |
| 4441 | static void add_cx5051_fake_mutes(struct hda_codec *codec) |
| 4442 | { |
| 4443 | static hda_nid_t out_nids[] = { |
| 4444 | 0x10, 0x11, 0 |
| 4445 | }; |
| 4446 | hda_nid_t *p; |
| 4447 | |
| 4448 | for (p = out_nids; *p; p++) |
| 4449 | snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT, |
| 4450 | AC_AMPCAP_MIN_MUTE | |
| 4451 | query_amp_caps(codec, *p, HDA_OUTPUT)); |
| 4452 | } |
| 4453 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4454 | static int patch_conexant_auto(struct hda_codec *codec) |
| 4455 | { |
| 4456 | struct conexant_spec *spec; |
| 4457 | int err; |
| 4458 | |
Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 4459 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 4460 | codec->chip_name); |
| 4461 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4462 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4463 | if (!spec) |
| 4464 | return -ENOMEM; |
| 4465 | codec->spec = spec; |
Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4466 | |
Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4467 | switch (codec->vendor_id) { |
| 4468 | case 0x14f15045: |
Michael Karcher | 4f32456 | 2012-04-06 15:34:15 +0200 | [diff] [blame] | 4469 | codec->single_adc_amp = 1; |
Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4470 | break; |
Takashi Iwai | 3868137 | 2012-02-27 15:00:58 +0100 | [diff] [blame] | 4471 | case 0x14f15051: |
| 4472 | add_cx5051_fake_mutes(codec); |
Michael Karcher | 51969d6 | 2012-04-06 15:34:19 +0200 | [diff] [blame] | 4473 | codec->pin_amp_workaround = 1; |
Takashi Iwai | d70f363 | 2012-04-19 15:18:08 +0200 | [diff] [blame] | 4474 | apply_pin_fixup(codec, cxt5051_fixups, cxt_pincfg_tbl); |
Takashi Iwai | 3868137 | 2012-02-27 15:00:58 +0100 | [diff] [blame] | 4475 | break; |
Michael Karcher | 51969d6 | 2012-04-06 15:34:19 +0200 | [diff] [blame] | 4476 | default: |
| 4477 | codec->pin_amp_workaround = 1; |
Takashi Iwai | d70f363 | 2012-04-19 15:18:08 +0200 | [diff] [blame] | 4478 | apply_pin_fixup(codec, cxt5066_fixups, cxt_pincfg_tbl); |
Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4479 | } |
| 4480 | |
Takashi Iwai | f29735c | 2012-03-13 07:55:10 +0100 | [diff] [blame] | 4481 | /* Show mute-led control only on HP laptops |
| 4482 | * This is a sort of white-list: on HP laptops, EAPD corresponds |
| 4483 | * only to the mute-LED without actualy amp function. Meanwhile, |
| 4484 | * others may use EAPD really as an amp switch, so it might be |
| 4485 | * not good to expose it blindly. |
Takashi Iwai | 527c73b | 2012-03-12 12:38:51 +0100 | [diff] [blame] | 4486 | */ |
Takashi Iwai | f29735c | 2012-03-13 07:55:10 +0100 | [diff] [blame] | 4487 | switch (codec->subsystem_id >> 16) { |
| 4488 | case 0x103c: |
| 4489 | spec->vmaster_mute_led = 1; |
| 4490 | break; |
| 4491 | } |
Takashi Iwai | 527c73b | 2012-03-12 12:38:51 +0100 | [diff] [blame] | 4492 | |
Takashi Iwai | 22ce5f7 | 2011-05-15 12:19:29 +0200 | [diff] [blame] | 4493 | err = cx_auto_search_adcs(codec); |
| 4494 | if (err < 0) |
| 4495 | return err; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4496 | err = cx_auto_parse_auto_config(codec); |
| 4497 | if (err < 0) { |
| 4498 | kfree(codec->spec); |
| 4499 | codec->spec = NULL; |
| 4500 | return err; |
| 4501 | } |
Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4502 | spec->capture_stream = &cx_auto_pcm_analog_capture; |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4503 | codec->patch_ops = cx_auto_patch_ops; |
| 4504 | if (spec->beep_amp) |
| 4505 | snd_hda_attach_beep_device(codec, spec->beep_amp); |
Takashi Iwai | 4f2864a | 2012-01-25 11:54:19 +0100 | [diff] [blame] | 4506 | |
| 4507 | /* Some laptops with Conexant chips show stalls in S3 resume, |
| 4508 | * which falls into the single-cmd mode. |
| 4509 | * Better to make reset, then. |
| 4510 | */ |
| 4511 | if (!codec->bus->sync_write) { |
| 4512 | snd_printd("hda_codec: " |
| 4513 | "Enable sync_write for stable communication\n"); |
| 4514 | codec->bus->sync_write = 1; |
| 4515 | codec->bus->allow_bus_reset = 1; |
| 4516 | } |
| 4517 | |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4518 | return 0; |
| 4519 | } |
| 4520 | |
| 4521 | /* |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 4522 | */ |
| 4523 | |
Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 4524 | static const struct hda_codec_preset snd_hda_preset_conexant[] = { |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 4525 | { .id = 0x14f15045, .name = "CX20549 (Venice)", |
| 4526 | .patch = patch_cxt5045 }, |
| 4527 | { .id = 0x14f15047, .name = "CX20551 (Waikiki)", |
| 4528 | .patch = patch_cxt5047 }, |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 4529 | { .id = 0x14f15051, .name = "CX20561 (Hermosa)", |
| 4530 | .patch = patch_cxt5051 }, |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 4531 | { .id = 0x14f15066, .name = "CX20582 (Pebble)", |
| 4532 | .patch = patch_cxt5066 }, |
Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 4533 | { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", |
| 4534 | .patch = patch_cxt5066 }, |
Takashi Iwai | 850eab9 | 2010-08-09 13:44:27 +0200 | [diff] [blame] | 4535 | { .id = 0x14f15068, .name = "CX20584", |
| 4536 | .patch = patch_cxt5066 }, |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 4537 | { .id = 0x14f15069, .name = "CX20585", |
| 4538 | .patch = patch_cxt5066 }, |
David Henningsson | f0ca89b | 2011-06-21 20:51:34 +0200 | [diff] [blame] | 4539 | { .id = 0x14f1506c, .name = "CX20588", |
| 4540 | .patch = patch_cxt5066 }, |
David Henningsson | 6da8b51 | 2011-02-08 07:16:06 +0100 | [diff] [blame] | 4541 | { .id = 0x14f1506e, .name = "CX20590", |
| 4542 | .patch = patch_cxt5066 }, |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4543 | { .id = 0x14f15097, .name = "CX20631", |
| 4544 | .patch = patch_conexant_auto }, |
| 4545 | { .id = 0x14f15098, .name = "CX20632", |
| 4546 | .patch = patch_conexant_auto }, |
| 4547 | { .id = 0x14f150a1, .name = "CX20641", |
| 4548 | .patch = patch_conexant_auto }, |
| 4549 | { .id = 0x14f150a2, .name = "CX20642", |
| 4550 | .patch = patch_conexant_auto }, |
| 4551 | { .id = 0x14f150ab, .name = "CX20651", |
| 4552 | .patch = patch_conexant_auto }, |
| 4553 | { .id = 0x14f150ac, .name = "CX20652", |
| 4554 | .patch = patch_conexant_auto }, |
| 4555 | { .id = 0x14f150b8, .name = "CX20664", |
| 4556 | .patch = patch_conexant_auto }, |
| 4557 | { .id = 0x14f150b9, .name = "CX20665", |
| 4558 | .patch = patch_conexant_auto }, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 4559 | {} /* terminator */ |
| 4560 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 4561 | |
| 4562 | MODULE_ALIAS("snd-hda-codec-id:14f15045"); |
| 4563 | MODULE_ALIAS("snd-hda-codec-id:14f15047"); |
| 4564 | MODULE_ALIAS("snd-hda-codec-id:14f15051"); |
Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 4565 | MODULE_ALIAS("snd-hda-codec-id:14f15066"); |
Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 4566 | MODULE_ALIAS("snd-hda-codec-id:14f15067"); |
Takashi Iwai | 850eab9 | 2010-08-09 13:44:27 +0200 | [diff] [blame] | 4567 | MODULE_ALIAS("snd-hda-codec-id:14f15068"); |
Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 4568 | MODULE_ALIAS("snd-hda-codec-id:14f15069"); |
David Henningsson | f0ca89b | 2011-06-21 20:51:34 +0200 | [diff] [blame] | 4569 | MODULE_ALIAS("snd-hda-codec-id:14f1506c"); |
David Henningsson | 6da8b51 | 2011-02-08 07:16:06 +0100 | [diff] [blame] | 4570 | MODULE_ALIAS("snd-hda-codec-id:14f1506e"); |
Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4571 | MODULE_ALIAS("snd-hda-codec-id:14f15097"); |
| 4572 | MODULE_ALIAS("snd-hda-codec-id:14f15098"); |
| 4573 | MODULE_ALIAS("snd-hda-codec-id:14f150a1"); |
| 4574 | MODULE_ALIAS("snd-hda-codec-id:14f150a2"); |
| 4575 | MODULE_ALIAS("snd-hda-codec-id:14f150ab"); |
| 4576 | MODULE_ALIAS("snd-hda-codec-id:14f150ac"); |
| 4577 | MODULE_ALIAS("snd-hda-codec-id:14f150b8"); |
| 4578 | MODULE_ALIAS("snd-hda-codec-id:14f150b9"); |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 4579 | |
| 4580 | MODULE_LICENSE("GPL"); |
| 4581 | MODULE_DESCRIPTION("Conexant HD-audio codec"); |
| 4582 | |
| 4583 | static struct hda_codec_preset_list conexant_list = { |
| 4584 | .preset = snd_hda_preset_conexant, |
| 4585 | .owner = THIS_MODULE, |
| 4586 | }; |
| 4587 | |
| 4588 | static int __init patch_conexant_init(void) |
| 4589 | { |
| 4590 | return snd_hda_add_codec_preset(&conexant_list); |
| 4591 | } |
| 4592 | |
| 4593 | static void __exit patch_conexant_exit(void) |
| 4594 | { |
| 4595 | snd_hda_delete_codec_preset(&conexant_list); |
| 4596 | } |
| 4597 | |
| 4598 | module_init(patch_conexant_init) |
| 4599 | module_exit(patch_conexant_exit) |