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