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