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> |
| 28 | #include "hda_codec.h" |
| 29 | #include "hda_local.h" |
Harvey Harrison | 3c9a320 | 2008-02-29 11:59:26 +0100 | [diff] [blame] | 30 | #include "hda_patch.h" |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 31 | |
| 32 | #define CXT_PIN_DIR_IN 0x00 |
| 33 | #define CXT_PIN_DIR_OUT 0x01 |
| 34 | #define CXT_PIN_DIR_INOUT 0x02 |
| 35 | #define CXT_PIN_DIR_IN_NOMICBIAS 0x03 |
| 36 | #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 |
| 37 | |
| 38 | #define CONEXANT_HP_EVENT 0x37 |
| 39 | #define CONEXANT_MIC_EVENT 0x38 |
| 40 | |
| 41 | |
| 42 | |
| 43 | struct conexant_spec { |
| 44 | |
| 45 | struct snd_kcontrol_new *mixers[5]; |
| 46 | int num_mixers; |
| 47 | |
| 48 | const struct hda_verb *init_verbs[5]; /* initialization verbs |
| 49 | * don't forget NULL |
| 50 | * termination! |
| 51 | */ |
| 52 | unsigned int num_init_verbs; |
| 53 | |
| 54 | /* playback */ |
| 55 | struct hda_multi_out multiout; /* playback set-up |
| 56 | * max_channels, dacs must be set |
| 57 | * dig_out_nid and hp_nid are optional |
| 58 | */ |
| 59 | unsigned int cur_eapd; |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 60 | unsigned int hp_present; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 61 | unsigned int need_dac_fix; |
| 62 | |
| 63 | /* capture */ |
| 64 | unsigned int num_adc_nids; |
| 65 | hda_nid_t *adc_nids; |
| 66 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ |
| 67 | |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 68 | unsigned int cur_adc_idx; |
| 69 | hda_nid_t cur_adc; |
| 70 | unsigned int cur_adc_stream_tag; |
| 71 | unsigned int cur_adc_format; |
| 72 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 73 | /* capture source */ |
| 74 | const struct hda_input_mux *input_mux; |
| 75 | hda_nid_t *capsrc_nids; |
| 76 | unsigned int cur_mux[3]; |
| 77 | |
| 78 | /* channel model */ |
| 79 | const struct hda_channel_mode *channel_mode; |
| 80 | int num_channel_mode; |
| 81 | |
| 82 | /* PCM information */ |
| 83 | struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ |
| 84 | |
| 85 | struct mutex amp_mutex; /* PCM volume/mute control mutex */ |
| 86 | unsigned int spdif_route; |
| 87 | |
| 88 | /* dynamic controls, init_verbs and input_mux */ |
| 89 | struct auto_pin_cfg autocfg; |
| 90 | unsigned int num_kctl_alloc, num_kctl_used; |
| 91 | struct snd_kcontrol_new *kctl_alloc; |
| 92 | struct hda_input_mux private_imux; |
Takashi Iwai | 41923e4 | 2007-10-22 17:20:10 +0200 | [diff] [blame] | 93 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 94 | |
| 95 | }; |
| 96 | |
| 97 | static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 98 | struct hda_codec *codec, |
| 99 | struct snd_pcm_substream *substream) |
| 100 | { |
| 101 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 102 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 103 | hinfo); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 107 | struct hda_codec *codec, |
| 108 | unsigned int stream_tag, |
| 109 | unsigned int format, |
| 110 | struct snd_pcm_substream *substream) |
| 111 | { |
| 112 | struct conexant_spec *spec = codec->spec; |
| 113 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, |
| 114 | stream_tag, |
| 115 | format, substream); |
| 116 | } |
| 117 | |
| 118 | static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 119 | struct hda_codec *codec, |
| 120 | struct snd_pcm_substream *substream) |
| 121 | { |
| 122 | struct conexant_spec *spec = codec->spec; |
| 123 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Digital out |
| 128 | */ |
| 129 | static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 130 | struct hda_codec *codec, |
| 131 | struct snd_pcm_substream *substream) |
| 132 | { |
| 133 | struct conexant_spec *spec = codec->spec; |
| 134 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 135 | } |
| 136 | |
| 137 | static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 138 | struct hda_codec *codec, |
| 139 | struct snd_pcm_substream *substream) |
| 140 | { |
| 141 | struct conexant_spec *spec = codec->spec; |
| 142 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 143 | } |
| 144 | |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 145 | static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 146 | struct hda_codec *codec, |
| 147 | unsigned int stream_tag, |
| 148 | unsigned int format, |
| 149 | struct snd_pcm_substream *substream) |
| 150 | { |
| 151 | struct conexant_spec *spec = codec->spec; |
| 152 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 153 | stream_tag, |
| 154 | format, substream); |
| 155 | } |
| 156 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 157 | /* |
| 158 | * Analog capture |
| 159 | */ |
| 160 | static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 161 | struct hda_codec *codec, |
| 162 | unsigned int stream_tag, |
| 163 | unsigned int format, |
| 164 | struct snd_pcm_substream *substream) |
| 165 | { |
| 166 | struct conexant_spec *spec = codec->spec; |
| 167 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], |
| 168 | stream_tag, 0, format); |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 173 | struct hda_codec *codec, |
| 174 | struct snd_pcm_substream *substream) |
| 175 | { |
| 176 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame^] | 177 | snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | |
| 182 | |
| 183 | static struct hda_pcm_stream conexant_pcm_analog_playback = { |
| 184 | .substreams = 1, |
| 185 | .channels_min = 2, |
| 186 | .channels_max = 2, |
| 187 | .nid = 0, /* fill later */ |
| 188 | .ops = { |
| 189 | .open = conexant_playback_pcm_open, |
| 190 | .prepare = conexant_playback_pcm_prepare, |
| 191 | .cleanup = conexant_playback_pcm_cleanup |
| 192 | }, |
| 193 | }; |
| 194 | |
| 195 | static struct hda_pcm_stream conexant_pcm_analog_capture = { |
| 196 | .substreams = 1, |
| 197 | .channels_min = 2, |
| 198 | .channels_max = 2, |
| 199 | .nid = 0, /* fill later */ |
| 200 | .ops = { |
| 201 | .prepare = conexant_capture_pcm_prepare, |
| 202 | .cleanup = conexant_capture_pcm_cleanup |
| 203 | }, |
| 204 | }; |
| 205 | |
| 206 | |
| 207 | static struct hda_pcm_stream conexant_pcm_digital_playback = { |
| 208 | .substreams = 1, |
| 209 | .channels_min = 2, |
| 210 | .channels_max = 2, |
| 211 | .nid = 0, /* fill later */ |
| 212 | .ops = { |
| 213 | .open = conexant_dig_playback_pcm_open, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 214 | .close = conexant_dig_playback_pcm_close, |
| 215 | .prepare = conexant_dig_playback_pcm_prepare |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 216 | }, |
| 217 | }; |
| 218 | |
| 219 | static struct hda_pcm_stream conexant_pcm_digital_capture = { |
| 220 | .substreams = 1, |
| 221 | .channels_min = 2, |
| 222 | .channels_max = 2, |
| 223 | /* NID is set in alc_build_pcms */ |
| 224 | }; |
| 225 | |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 226 | static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 227 | struct hda_codec *codec, |
| 228 | unsigned int stream_tag, |
| 229 | unsigned int format, |
| 230 | struct snd_pcm_substream *substream) |
| 231 | { |
| 232 | struct conexant_spec *spec = codec->spec; |
| 233 | spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; |
| 234 | spec->cur_adc_stream_tag = stream_tag; |
| 235 | spec->cur_adc_format = format; |
| 236 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 241 | struct hda_codec *codec, |
| 242 | struct snd_pcm_substream *substream) |
| 243 | { |
| 244 | struct conexant_spec *spec = codec->spec; |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame^] | 245 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 246 | spec->cur_adc = 0; |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | static struct hda_pcm_stream cx5051_pcm_analog_capture = { |
| 251 | .substreams = 1, |
| 252 | .channels_min = 2, |
| 253 | .channels_max = 2, |
| 254 | .nid = 0, /* fill later */ |
| 255 | .ops = { |
| 256 | .prepare = cx5051_capture_pcm_prepare, |
| 257 | .cleanup = cx5051_capture_pcm_cleanup |
| 258 | }, |
| 259 | }; |
| 260 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 261 | static int conexant_build_pcms(struct hda_codec *codec) |
| 262 | { |
| 263 | struct conexant_spec *spec = codec->spec; |
| 264 | struct hda_pcm *info = spec->pcm_rec; |
| 265 | |
| 266 | codec->num_pcms = 1; |
| 267 | codec->pcm_info = info; |
| 268 | |
| 269 | info->name = "CONEXANT Analog"; |
| 270 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; |
| 271 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
| 272 | spec->multiout.max_channels; |
| 273 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 274 | spec->multiout.dac_nids[0]; |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 275 | if (codec->vendor_id == 0x14f15051) |
| 276 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 277 | cx5051_pcm_analog_capture; |
| 278 | else |
| 279 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 280 | conexant_pcm_analog_capture; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 281 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids; |
| 282 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 283 | |
| 284 | if (spec->multiout.dig_out_nid) { |
| 285 | info++; |
| 286 | codec->num_pcms++; |
| 287 | info->name = "Conexant Digital"; |
Takashi Iwai | 7ba72ba | 2008-02-06 14:03:20 +0100 | [diff] [blame] | 288 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 289 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 290 | conexant_pcm_digital_playback; |
| 291 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 292 | spec->multiout.dig_out_nid; |
| 293 | if (spec->dig_in_nid) { |
| 294 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 295 | conexant_pcm_digital_capture; |
| 296 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 297 | spec->dig_in_nid; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 305 | struct snd_ctl_elem_info *uinfo) |
| 306 | { |
| 307 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 308 | struct conexant_spec *spec = codec->spec; |
| 309 | |
| 310 | return snd_hda_input_mux_info(spec->input_mux, uinfo); |
| 311 | } |
| 312 | |
| 313 | static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 314 | struct snd_ctl_elem_value *ucontrol) |
| 315 | { |
| 316 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 317 | struct conexant_spec *spec = codec->spec; |
| 318 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 319 | |
| 320 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
| 321 | return 0; |
| 322 | } |
| 323 | |
| 324 | static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 325 | struct snd_ctl_elem_value *ucontrol) |
| 326 | { |
| 327 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 328 | struct conexant_spec *spec = codec->spec; |
| 329 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 330 | |
| 331 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, |
| 332 | spec->capsrc_nids[adc_idx], |
| 333 | &spec->cur_mux[adc_idx]); |
| 334 | } |
| 335 | |
| 336 | static int conexant_init(struct hda_codec *codec) |
| 337 | { |
| 338 | struct conexant_spec *spec = codec->spec; |
| 339 | int i; |
| 340 | |
| 341 | for (i = 0; i < spec->num_init_verbs; i++) |
| 342 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | static void conexant_free(struct hda_codec *codec) |
| 347 | { |
| 348 | struct conexant_spec *spec = codec->spec; |
| 349 | unsigned int i; |
| 350 | |
| 351 | if (spec->kctl_alloc) { |
| 352 | for (i = 0; i < spec->num_kctl_used; i++) |
| 353 | kfree(spec->kctl_alloc[i].name); |
| 354 | kfree(spec->kctl_alloc); |
| 355 | } |
| 356 | |
| 357 | kfree(codec->spec); |
| 358 | } |
| 359 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 360 | static int conexant_build_controls(struct hda_codec *codec) |
| 361 | { |
| 362 | struct conexant_spec *spec = codec->spec; |
| 363 | unsigned int i; |
| 364 | int err; |
| 365 | |
| 366 | for (i = 0; i < spec->num_mixers; i++) { |
| 367 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 368 | if (err < 0) |
| 369 | return err; |
| 370 | } |
| 371 | if (spec->multiout.dig_out_nid) { |
| 372 | err = snd_hda_create_spdif_out_ctls(codec, |
| 373 | spec->multiout.dig_out_nid); |
| 374 | if (err < 0) |
| 375 | return err; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 376 | err = snd_hda_create_spdif_share_sw(codec, |
| 377 | &spec->multiout); |
| 378 | if (err < 0) |
| 379 | return err; |
| 380 | spec->multiout.share_spdif = 1; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 381 | } |
| 382 | if (spec->dig_in_nid) { |
| 383 | err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); |
| 384 | if (err < 0) |
| 385 | return err; |
| 386 | } |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | static struct hda_codec_ops conexant_patch_ops = { |
| 391 | .build_controls = conexant_build_controls, |
| 392 | .build_pcms = conexant_build_pcms, |
| 393 | .init = conexant_init, |
| 394 | .free = conexant_free, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 395 | }; |
| 396 | |
| 397 | /* |
| 398 | * EAPD control |
| 399 | * the private value = nid | (invert << 8) |
| 400 | */ |
| 401 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 402 | #define cxt_eapd_info snd_ctl_boolean_mono_info |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 403 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 404 | static int cxt_eapd_get(struct snd_kcontrol *kcontrol, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 405 | struct snd_ctl_elem_value *ucontrol) |
| 406 | { |
| 407 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 408 | struct conexant_spec *spec = codec->spec; |
| 409 | int invert = (kcontrol->private_value >> 8) & 1; |
| 410 | if (invert) |
| 411 | ucontrol->value.integer.value[0] = !spec->cur_eapd; |
| 412 | else |
| 413 | ucontrol->value.integer.value[0] = spec->cur_eapd; |
| 414 | return 0; |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 415 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 416 | } |
| 417 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 418 | static int cxt_eapd_put(struct snd_kcontrol *kcontrol, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 419 | struct snd_ctl_elem_value *ucontrol) |
| 420 | { |
| 421 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 422 | struct conexant_spec *spec = codec->spec; |
| 423 | int invert = (kcontrol->private_value >> 8) & 1; |
| 424 | hda_nid_t nid = kcontrol->private_value & 0xff; |
| 425 | unsigned int eapd; |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 426 | |
Takashi Iwai | 68ea7b2 | 2007-11-15 15:54:38 +0100 | [diff] [blame] | 427 | eapd = !!ucontrol->value.integer.value[0]; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 428 | if (invert) |
| 429 | eapd = !eapd; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 430 | if (eapd == spec->cur_eapd) |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 431 | return 0; |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 432 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 433 | spec->cur_eapd = eapd; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 434 | snd_hda_codec_write_cache(codec, nid, |
| 435 | 0, AC_VERB_SET_EAPD_BTLENABLE, |
| 436 | eapd ? 0x02 : 0x00); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 437 | return 1; |
| 438 | } |
| 439 | |
Takashi Iwai | 86d72bd | 2006-11-28 11:33:10 +0100 | [diff] [blame] | 440 | /* controls for test mode */ |
| 441 | #ifdef CONFIG_SND_DEBUG |
| 442 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 443 | #define CXT_EAPD_SWITCH(xname, nid, mask) \ |
| 444 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ |
| 445 | .info = cxt_eapd_info, \ |
| 446 | .get = cxt_eapd_get, \ |
| 447 | .put = cxt_eapd_put, \ |
| 448 | .private_value = nid | (mask<<16) } |
| 449 | |
| 450 | |
| 451 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 452 | static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, |
| 453 | struct snd_ctl_elem_info *uinfo) |
| 454 | { |
| 455 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 456 | struct conexant_spec *spec = codec->spec; |
| 457 | return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, |
| 458 | spec->num_channel_mode); |
| 459 | } |
| 460 | |
| 461 | static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, |
| 462 | struct snd_ctl_elem_value *ucontrol) |
| 463 | { |
| 464 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 465 | struct conexant_spec *spec = codec->spec; |
| 466 | return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, |
| 467 | spec->num_channel_mode, |
| 468 | spec->multiout.max_channels); |
| 469 | } |
| 470 | |
| 471 | static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, |
| 472 | struct snd_ctl_elem_value *ucontrol) |
| 473 | { |
| 474 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 475 | struct conexant_spec *spec = codec->spec; |
| 476 | int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, |
| 477 | spec->num_channel_mode, |
| 478 | &spec->multiout.max_channels); |
| 479 | if (err >= 0 && spec->need_dac_fix) |
| 480 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; |
| 481 | return err; |
| 482 | } |
| 483 | |
| 484 | #define CXT_PIN_MODE(xname, nid, dir) \ |
| 485 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ |
| 486 | .info = conexant_ch_mode_info, \ |
| 487 | .get = conexant_ch_mode_get, \ |
| 488 | .put = conexant_ch_mode_put, \ |
| 489 | .private_value = nid | (dir<<16) } |
| 490 | |
Takashi Iwai | 86d72bd | 2006-11-28 11:33:10 +0100 | [diff] [blame] | 491 | #endif /* CONFIG_SND_DEBUG */ |
| 492 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 493 | /* Conexant 5045 specific */ |
| 494 | |
| 495 | static hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; |
| 496 | static hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; |
| 497 | static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; |
Takashi Iwai | cbef978 | 2008-02-22 18:36:46 +0100 | [diff] [blame] | 498 | #define CXT5045_SPDIF_OUT 0x18 |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 499 | |
Tobin Davis | 5cd5752 | 2006-11-20 17:42:09 +0100 | [diff] [blame] | 500 | static struct hda_channel_mode cxt5045_modes[1] = { |
| 501 | { 2, NULL }, |
| 502 | }; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 503 | |
| 504 | static struct hda_input_mux cxt5045_capture_source = { |
| 505 | .num_items = 2, |
| 506 | .items = { |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 507 | { "IntMic", 0x1 }, |
Jiang zhe | f4beee9 | 2008-01-17 11:19:26 +0100 | [diff] [blame] | 508 | { "ExtMic", 0x2 }, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 509 | } |
| 510 | }; |
| 511 | |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 512 | static struct hda_input_mux cxt5045_capture_source_benq = { |
| 513 | .num_items = 3, |
| 514 | .items = { |
| 515 | { "IntMic", 0x1 }, |
| 516 | { "ExtMic", 0x2 }, |
| 517 | { "LineIn", 0x3 }, |
| 518 | } |
| 519 | }; |
| 520 | |
Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 521 | static struct hda_input_mux cxt5045_capture_source_hp530 = { |
| 522 | .num_items = 2, |
| 523 | .items = { |
| 524 | { "ExtMic", 0x1 }, |
| 525 | { "IntMic", 0x2 }, |
| 526 | } |
| 527 | }; |
| 528 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 529 | /* turn on/off EAPD (+ mute HP) as a master switch */ |
| 530 | static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, |
| 531 | struct snd_ctl_elem_value *ucontrol) |
| 532 | { |
| 533 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 534 | struct conexant_spec *spec = codec->spec; |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 535 | unsigned int bits; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 536 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 537 | if (!cxt_eapd_put(kcontrol, ucontrol)) |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 538 | return 0; |
| 539 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 540 | /* toggle internal speakers mute depending of presence of |
| 541 | * the headphone jack |
| 542 | */ |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 543 | bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; |
| 544 | snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, |
| 545 | HDA_AMP_MUTE, bits); |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 546 | |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 547 | bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; |
| 548 | snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, |
| 549 | HDA_AMP_MUTE, bits); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 550 | return 1; |
| 551 | } |
| 552 | |
| 553 | /* bind volumes of both NID 0x10 and 0x11 */ |
Takashi Iwai | cca3b37 | 2007-08-10 17:12:15 +0200 | [diff] [blame] | 554 | static struct hda_bind_ctls cxt5045_hp_bind_master_vol = { |
| 555 | .ops = &snd_hda_bind_vol, |
| 556 | .values = { |
| 557 | HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), |
| 558 | HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), |
| 559 | 0 |
| 560 | }, |
| 561 | }; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 562 | |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 563 | /* toggle input of built-in and mic jack appropriately */ |
| 564 | static void cxt5045_hp_automic(struct hda_codec *codec) |
| 565 | { |
| 566 | static struct hda_verb mic_jack_on[] = { |
| 567 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, |
| 568 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, |
| 569 | {} |
| 570 | }; |
| 571 | static struct hda_verb mic_jack_off[] = { |
| 572 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, |
| 573 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, |
| 574 | {} |
| 575 | }; |
| 576 | unsigned int present; |
| 577 | |
| 578 | present = snd_hda_codec_read(codec, 0x12, 0, |
| 579 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
| 580 | if (present) |
| 581 | snd_hda_sequence_write(codec, mic_jack_on); |
| 582 | else |
| 583 | snd_hda_sequence_write(codec, mic_jack_off); |
| 584 | } |
| 585 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 586 | |
| 587 | /* mute internal speaker if HP is plugged */ |
| 588 | static void cxt5045_hp_automute(struct hda_codec *codec) |
| 589 | { |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 590 | struct conexant_spec *spec = codec->spec; |
Tobin Davis | dd87da1 | 2007-02-26 16:07:42 +0100 | [diff] [blame] | 591 | unsigned int bits; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 592 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 593 | spec->hp_present = snd_hda_codec_read(codec, 0x11, 0, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 594 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
Tobin Davis | dd87da1 | 2007-02-26 16:07:42 +0100 | [diff] [blame] | 595 | |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 596 | bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; |
| 597 | snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, |
| 598 | HDA_AMP_MUTE, bits); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /* unsolicited event for HP jack sensing */ |
| 602 | static void cxt5045_hp_unsol_event(struct hda_codec *codec, |
| 603 | unsigned int res) |
| 604 | { |
| 605 | res >>= 26; |
| 606 | switch (res) { |
| 607 | case CONEXANT_HP_EVENT: |
| 608 | cxt5045_hp_automute(codec); |
| 609 | break; |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 610 | case CONEXANT_MIC_EVENT: |
| 611 | cxt5045_hp_automic(codec); |
| 612 | break; |
| 613 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 614 | } |
| 615 | } |
| 616 | |
| 617 | static struct snd_kcontrol_new cxt5045_mixers[] = { |
| 618 | { |
| 619 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 620 | .name = "Capture Source", |
| 621 | .info = conexant_mux_enum_info, |
| 622 | .get = conexant_mux_enum_get, |
| 623 | .put = conexant_mux_enum_put |
| 624 | }, |
Takashi Iwai | c8229c3 | 2007-10-19 08:06:21 +0200 | [diff] [blame] | 625 | HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), |
| 626 | HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), |
| 627 | HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), |
| 628 | HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), |
| 629 | HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), |
| 630 | HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), |
| 631 | HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT), |
| 632 | HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT), |
| 633 | HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT), |
| 634 | HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT), |
Takashi Iwai | cca3b37 | 2007-08-10 17:12:15 +0200 | [diff] [blame] | 635 | HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 636 | { |
| 637 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 638 | .name = "Master Playback Switch", |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 639 | .info = cxt_eapd_info, |
| 640 | .get = cxt_eapd_get, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 641 | .put = cxt5045_hp_master_sw_put, |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 642 | .private_value = 0x10, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 643 | }, |
| 644 | |
| 645 | {} |
| 646 | }; |
| 647 | |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 648 | static struct snd_kcontrol_new cxt5045_benq_mixers[] = { |
| 649 | HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), |
| 650 | HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), |
| 651 | HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), |
| 652 | HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), |
| 653 | |
| 654 | {} |
| 655 | }; |
| 656 | |
Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 657 | static struct snd_kcontrol_new cxt5045_mixers_hp530[] = { |
| 658 | { |
| 659 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 660 | .name = "Capture Source", |
| 661 | .info = conexant_mux_enum_info, |
| 662 | .get = conexant_mux_enum_get, |
| 663 | .put = conexant_mux_enum_put |
| 664 | }, |
| 665 | HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), |
| 666 | HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), |
| 667 | HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), |
| 668 | HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), |
| 669 | HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), |
| 670 | HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), |
| 671 | HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT), |
| 672 | HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT), |
| 673 | HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT), |
| 674 | HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT), |
| 675 | HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), |
| 676 | { |
| 677 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 678 | .name = "Master Playback Switch", |
| 679 | .info = cxt_eapd_info, |
| 680 | .get = cxt_eapd_get, |
| 681 | .put = cxt5045_hp_master_sw_put, |
| 682 | .private_value = 0x10, |
| 683 | }, |
| 684 | |
| 685 | {} |
| 686 | }; |
| 687 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 688 | static struct hda_verb cxt5045_init_verbs[] = { |
| 689 | /* Line in, Mic */ |
| 690 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 691 | {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] | 692 | /* HP, Amp */ |
Takashi Iwai | c8229c3 | 2007-10-19 08:06:21 +0200 | [diff] [blame] | 693 | {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 694 | {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 695 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, |
| 696 | {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 697 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 698 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 699 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 700 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 701 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 702 | /* Record selector: Int mic */ |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 703 | {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 704 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 705 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, |
| 706 | /* SPDIF route: PCM */ |
Takashi Iwai | cbef978 | 2008-02-22 18:36:46 +0100 | [diff] [blame] | 707 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 708 | { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 709 | /* EAPD */ |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 710 | {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 711 | { } /* end */ |
| 712 | }; |
| 713 | |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 714 | static struct hda_verb cxt5045_benq_init_verbs[] = { |
| 715 | /* Int Mic, Mic */ |
| 716 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, |
| 717 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, |
| 718 | /* Line In,HP, Amp */ |
| 719 | {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 720 | {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 721 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, |
| 722 | {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 723 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 724 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 725 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 726 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 727 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 728 | /* Record selector: Int mic */ |
| 729 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 730 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, |
| 731 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, |
| 732 | /* SPDIF route: PCM */ |
Takashi Iwai | cbef978 | 2008-02-22 18:36:46 +0100 | [diff] [blame] | 733 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 734 | {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 735 | /* EAPD */ |
| 736 | {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ |
| 737 | { } /* end */ |
| 738 | }; |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 739 | |
| 740 | static struct hda_verb cxt5045_hp_sense_init_verbs[] = { |
| 741 | /* pin sensing on HP jack */ |
| 742 | {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, |
Takashi Iwai | d3091fa | 2007-03-28 15:11:53 +0200 | [diff] [blame] | 743 | { } /* end */ |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 744 | }; |
| 745 | |
| 746 | static struct hda_verb cxt5045_mic_sense_init_verbs[] = { |
| 747 | /* pin sensing on HP jack */ |
| 748 | {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, |
Takashi Iwai | d3091fa | 2007-03-28 15:11:53 +0200 | [diff] [blame] | 749 | { } /* end */ |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 750 | }; |
| 751 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 752 | #ifdef CONFIG_SND_DEBUG |
| 753 | /* Test configuration for debugging, modelled after the ALC260 test |
| 754 | * configuration. |
| 755 | */ |
| 756 | static struct hda_input_mux cxt5045_test_capture_source = { |
| 757 | .num_items = 5, |
| 758 | .items = { |
| 759 | { "MIXER", 0x0 }, |
| 760 | { "MIC1 pin", 0x1 }, |
| 761 | { "LINE1 pin", 0x2 }, |
| 762 | { "HP-OUT pin", 0x3 }, |
| 763 | { "CD pin", 0x4 }, |
| 764 | }, |
| 765 | }; |
| 766 | |
| 767 | static struct snd_kcontrol_new cxt5045_test_mixer[] = { |
| 768 | |
| 769 | /* Output controls */ |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 770 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), |
| 771 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 772 | HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), |
| 773 | HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), |
| 774 | HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), |
| 775 | HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 776 | |
| 777 | /* Modes for retasking pin widgets */ |
| 778 | CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), |
| 779 | CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), |
| 780 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 781 | /* EAPD Switch Control */ |
| 782 | CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), |
| 783 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 784 | /* Loopback mixer controls */ |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 785 | |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 786 | HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), |
| 787 | HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), |
| 788 | HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), |
| 789 | HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), |
| 790 | HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), |
| 791 | HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), |
| 792 | HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), |
| 793 | HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), |
| 794 | HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), |
| 795 | HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 796 | { |
| 797 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 798 | .name = "Input Source", |
| 799 | .info = conexant_mux_enum_info, |
| 800 | .get = conexant_mux_enum_get, |
| 801 | .put = conexant_mux_enum_put, |
| 802 | }, |
Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 803 | /* Audio input controls */ |
| 804 | HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), |
| 805 | HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), |
| 806 | HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), |
| 807 | HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), |
| 808 | HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), |
| 809 | HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), |
| 810 | HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), |
| 811 | HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), |
| 812 | HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), |
| 813 | HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 814 | { } /* end */ |
| 815 | }; |
| 816 | |
| 817 | static struct hda_verb cxt5045_test_init_verbs[] = { |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 818 | /* Set connections */ |
| 819 | { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, |
| 820 | { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, |
| 821 | { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 822 | /* Enable retasking pins as output, initially without power amp */ |
| 823 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 824 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 825 | |
| 826 | /* Disable digital (SPDIF) pins initially, but users can enable |
| 827 | * them via a mixer switch. In the case of SPDIF-out, this initverb |
| 828 | * payload also sets the generation to 0, output to be in "consumer" |
| 829 | * PCM format, copyright asserted, no pre-emphasis and no validity |
| 830 | * control. |
| 831 | */ |
Takashi Iwai | cbef978 | 2008-02-22 18:36:46 +0100 | [diff] [blame] | 832 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 833 | {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 834 | |
| 835 | /* Start with output sum widgets muted and their output gains at min */ |
| 836 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 837 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 838 | |
| 839 | /* Unmute retasking pin widget output buffers since the default |
| 840 | * state appears to be output. As the pin mode is changed by the |
| 841 | * user the pin mode control will take care of enabling the pin's |
| 842 | * input/output buffers as needed. |
| 843 | */ |
| 844 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 845 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 846 | |
| 847 | /* Mute capture amp left and right */ |
| 848 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 849 | |
| 850 | /* Set ADC connection select to match default mixer setting (mic1 |
| 851 | * pin) |
| 852 | */ |
| 853 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 854 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 855 | |
| 856 | /* Mute all inputs to mixer widget (even unconnected ones) */ |
| 857 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ |
| 858 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ |
| 859 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ |
| 860 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ |
| 861 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ |
| 862 | |
| 863 | { } |
| 864 | }; |
| 865 | #endif |
| 866 | |
| 867 | |
| 868 | /* initialize jack-sensing, too */ |
| 869 | static int cxt5045_init(struct hda_codec *codec) |
| 870 | { |
| 871 | conexant_init(codec); |
| 872 | cxt5045_hp_automute(codec); |
| 873 | return 0; |
| 874 | } |
| 875 | |
| 876 | |
| 877 | enum { |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 878 | CXT5045_LAPTOP_HPSENSE, |
| 879 | CXT5045_LAPTOP_MICSENSE, |
| 880 | CXT5045_LAPTOP_HPMICSENSE, |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 881 | CXT5045_BENQ, |
Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 882 | CXT5045_LAPTOP_HP530, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 883 | #ifdef CONFIG_SND_DEBUG |
| 884 | CXT5045_TEST, |
| 885 | #endif |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 886 | CXT5045_MODELS |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 887 | }; |
| 888 | |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 889 | static const char *cxt5045_models[CXT5045_MODELS] = { |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 890 | [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", |
| 891 | [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", |
| 892 | [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", |
| 893 | [CXT5045_BENQ] = "benq", |
Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 894 | [CXT5045_LAPTOP_HP530] = "laptop-hp530", |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 895 | #ifdef CONFIG_SND_DEBUG |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 896 | [CXT5045_TEST] = "test", |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 897 | #endif |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 898 | }; |
| 899 | |
| 900 | static struct snd_pci_quirk cxt5045_cfg_tbl[] = { |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 901 | SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE), |
| 902 | SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE), |
| 903 | SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE), |
| 904 | SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE), |
| 905 | SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE), |
| 906 | SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE), |
Takashi Iwai | 0f6a515 | 2008-01-29 13:26:04 +0100 | [diff] [blame] | 907 | SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE), |
Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 908 | SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 909 | SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE), |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 910 | SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 911 | SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), |
| 912 | SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), |
| 913 | SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP_HPSENSE), |
| 914 | SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), |
| 915 | SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), |
| 916 | SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), |
| 917 | SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE), |
| 918 | SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE), |
| 919 | SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 920 | {} |
| 921 | }; |
| 922 | |
| 923 | static int patch_cxt5045(struct hda_codec *codec) |
| 924 | { |
| 925 | struct conexant_spec *spec; |
| 926 | int board_config; |
| 927 | |
| 928 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 929 | if (!spec) |
| 930 | return -ENOMEM; |
| 931 | mutex_init(&spec->amp_mutex); |
| 932 | codec->spec = spec; |
| 933 | |
| 934 | spec->multiout.max_channels = 2; |
| 935 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); |
| 936 | spec->multiout.dac_nids = cxt5045_dac_nids; |
| 937 | spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; |
| 938 | spec->num_adc_nids = 1; |
| 939 | spec->adc_nids = cxt5045_adc_nids; |
| 940 | spec->capsrc_nids = cxt5045_capsrc_nids; |
| 941 | spec->input_mux = &cxt5045_capture_source; |
| 942 | spec->num_mixers = 1; |
| 943 | spec->mixers[0] = cxt5045_mixers; |
| 944 | spec->num_init_verbs = 1; |
| 945 | spec->init_verbs[0] = cxt5045_init_verbs; |
| 946 | spec->spdif_route = 0; |
Tobin Davis | 5cd5752 | 2006-11-20 17:42:09 +0100 | [diff] [blame] | 947 | spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes), |
| 948 | spec->channel_mode = cxt5045_modes, |
| 949 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 950 | |
| 951 | codec->patch_ops = conexant_patch_ops; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 952 | |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 953 | board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, |
| 954 | cxt5045_models, |
| 955 | cxt5045_cfg_tbl); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 956 | switch (board_config) { |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 957 | case CXT5045_LAPTOP_HPSENSE: |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 958 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 959 | spec->input_mux = &cxt5045_capture_source; |
| 960 | spec->num_init_verbs = 2; |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 961 | spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; |
| 962 | spec->mixers[0] = cxt5045_mixers; |
| 963 | codec->patch_ops.init = cxt5045_init; |
| 964 | break; |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 965 | case CXT5045_LAPTOP_MICSENSE: |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 966 | spec->input_mux = &cxt5045_capture_source; |
| 967 | spec->num_init_verbs = 2; |
| 968 | spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 969 | spec->mixers[0] = cxt5045_mixers; |
| 970 | codec->patch_ops.init = cxt5045_init; |
| 971 | break; |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 972 | default: |
| 973 | case CXT5045_LAPTOP_HPMICSENSE: |
| 974 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; |
| 975 | spec->input_mux = &cxt5045_capture_source; |
| 976 | spec->num_init_verbs = 3; |
| 977 | spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; |
| 978 | spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; |
| 979 | spec->mixers[0] = cxt5045_mixers; |
| 980 | codec->patch_ops.init = cxt5045_init; |
| 981 | break; |
Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 982 | case CXT5045_BENQ: |
| 983 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; |
| 984 | spec->input_mux = &cxt5045_capture_source_benq; |
| 985 | spec->num_init_verbs = 1; |
| 986 | spec->init_verbs[0] = cxt5045_benq_init_verbs; |
| 987 | spec->mixers[0] = cxt5045_mixers; |
| 988 | spec->mixers[1] = cxt5045_benq_mixers; |
| 989 | spec->num_mixers = 2; |
| 990 | codec->patch_ops.init = cxt5045_init; |
| 991 | break; |
Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 992 | case CXT5045_LAPTOP_HP530: |
| 993 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; |
| 994 | spec->input_mux = &cxt5045_capture_source_hp530; |
| 995 | spec->num_init_verbs = 2; |
| 996 | spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; |
| 997 | spec->mixers[0] = cxt5045_mixers_hp530; |
| 998 | codec->patch_ops.init = cxt5045_init; |
| 999 | break; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1000 | #ifdef CONFIG_SND_DEBUG |
| 1001 | case CXT5045_TEST: |
| 1002 | spec->input_mux = &cxt5045_test_capture_source; |
| 1003 | spec->mixers[0] = cxt5045_test_mixer; |
| 1004 | spec->init_verbs[0] = cxt5045_test_init_verbs; |
Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1005 | break; |
| 1006 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1007 | #endif |
| 1008 | } |
Takashi Iwai | 48ecb7e | 2007-12-17 14:32:49 +0100 | [diff] [blame] | 1009 | |
| 1010 | /* |
| 1011 | * Fix max PCM level to 0 dB |
| 1012 | * (originall it has 0x2b steps with 0dB offset 0x14) |
| 1013 | */ |
| 1014 | snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, |
| 1015 | (0x14 << AC_AMPCAP_OFFSET_SHIFT) | |
| 1016 | (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 1017 | (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 1018 | (1 << AC_AMPCAP_MUTE_SHIFT)); |
| 1019 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1020 | return 0; |
| 1021 | } |
| 1022 | |
| 1023 | |
| 1024 | /* Conexant 5047 specific */ |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1025 | #define CXT5047_SPDIF_OUT 0x11 |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1026 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1027 | static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c }; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1028 | static hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; |
| 1029 | static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1030 | |
Tobin Davis | 5cd5752 | 2006-11-20 17:42:09 +0100 | [diff] [blame] | 1031 | static struct hda_channel_mode cxt5047_modes[1] = { |
| 1032 | { 2, NULL }, |
| 1033 | }; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1034 | |
| 1035 | static struct hda_input_mux cxt5047_capture_source = { |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1036 | .num_items = 1, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1037 | .items = { |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1038 | { "Mic", 0x2 }, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1039 | } |
| 1040 | }; |
| 1041 | |
| 1042 | static struct hda_input_mux cxt5047_hp_capture_source = { |
| 1043 | .num_items = 1, |
| 1044 | .items = { |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1045 | { "ExtMic", 0x2 }, |
| 1046 | } |
| 1047 | }; |
| 1048 | |
| 1049 | static struct hda_input_mux cxt5047_toshiba_capture_source = { |
| 1050 | .num_items = 2, |
| 1051 | .items = { |
| 1052 | { "ExtMic", 0x2 }, |
| 1053 | { "Line-In", 0x1 }, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1054 | } |
| 1055 | }; |
| 1056 | |
| 1057 | /* turn on/off EAPD (+ mute HP) as a master switch */ |
| 1058 | static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, |
| 1059 | struct snd_ctl_elem_value *ucontrol) |
| 1060 | { |
| 1061 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1062 | struct conexant_spec *spec = codec->spec; |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1063 | unsigned int bits; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1064 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1065 | if (!cxt_eapd_put(kcontrol, ucontrol)) |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1066 | return 0; |
| 1067 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1068 | /* toggle internal speakers mute depending of presence of |
| 1069 | * the headphone jack |
| 1070 | */ |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1071 | bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; |
| 1072 | snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, |
| 1073 | HDA_AMP_MUTE, bits); |
| 1074 | bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; |
| 1075 | snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, |
| 1076 | HDA_AMP_MUTE, bits); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1077 | return 1; |
| 1078 | } |
| 1079 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1080 | /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */ |
Takashi Iwai | cca3b37 | 2007-08-10 17:12:15 +0200 | [diff] [blame] | 1081 | static struct hda_bind_ctls cxt5047_bind_master_vol = { |
| 1082 | .ops = &snd_hda_bind_vol, |
| 1083 | .values = { |
| 1084 | HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT), |
| 1085 | HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT), |
| 1086 | 0 |
| 1087 | }, |
| 1088 | }; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1089 | |
| 1090 | /* mute internal speaker if HP is plugged */ |
| 1091 | static void cxt5047_hp_automute(struct hda_codec *codec) |
| 1092 | { |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1093 | struct conexant_spec *spec = codec->spec; |
Tobin Davis | dd87da1 | 2007-02-26 16:07:42 +0100 | [diff] [blame] | 1094 | unsigned int bits; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1095 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1096 | spec->hp_present = snd_hda_codec_read(codec, 0x13, 0, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1097 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
Tobin Davis | dd87da1 | 2007-02-26 16:07:42 +0100 | [diff] [blame] | 1098 | |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1099 | bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; |
| 1100 | snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, |
| 1101 | HDA_AMP_MUTE, bits); |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1102 | /* Mute/Unmute PCM 2 for good measure - some systems need this */ |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1103 | snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0, |
| 1104 | HDA_AMP_MUTE, bits); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1105 | } |
| 1106 | |
Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 1107 | /* mute internal speaker if HP is plugged */ |
| 1108 | static void cxt5047_hp2_automute(struct hda_codec *codec) |
| 1109 | { |
| 1110 | struct conexant_spec *spec = codec->spec; |
| 1111 | unsigned int bits; |
| 1112 | |
| 1113 | spec->hp_present = snd_hda_codec_read(codec, 0x13, 0, |
| 1114 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
| 1115 | |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1116 | bits = spec->hp_present ? HDA_AMP_MUTE : 0; |
| 1117 | snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, |
| 1118 | HDA_AMP_MUTE, bits); |
Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 1119 | /* Mute/Unmute PCM 2 for good measure - some systems need this */ |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1120 | snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0, |
| 1121 | HDA_AMP_MUTE, bits); |
Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 1122 | } |
| 1123 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1124 | /* toggle input of built-in and mic jack appropriately */ |
| 1125 | static void cxt5047_hp_automic(struct hda_codec *codec) |
| 1126 | { |
| 1127 | static struct hda_verb mic_jack_on[] = { |
Marc Boucher | 9f113e0 | 2008-01-22 15:18:08 +0100 | [diff] [blame] | 1128 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, |
| 1129 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1130 | {} |
| 1131 | }; |
| 1132 | static struct hda_verb mic_jack_off[] = { |
Marc Boucher | 9f113e0 | 2008-01-22 15:18:08 +0100 | [diff] [blame] | 1133 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, |
| 1134 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1135 | {} |
| 1136 | }; |
| 1137 | unsigned int present; |
| 1138 | |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1139 | present = snd_hda_codec_read(codec, 0x15, 0, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1140 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
| 1141 | if (present) |
| 1142 | snd_hda_sequence_write(codec, mic_jack_on); |
| 1143 | else |
| 1144 | snd_hda_sequence_write(codec, mic_jack_off); |
| 1145 | } |
| 1146 | |
| 1147 | /* unsolicited event for HP jack sensing */ |
| 1148 | static void cxt5047_hp_unsol_event(struct hda_codec *codec, |
| 1149 | unsigned int res) |
| 1150 | { |
Marc Boucher | 9f113e0 | 2008-01-22 15:18:08 +0100 | [diff] [blame] | 1151 | switch (res >> 26) { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1152 | case CONEXANT_HP_EVENT: |
| 1153 | cxt5047_hp_automute(codec); |
| 1154 | break; |
| 1155 | case CONEXANT_MIC_EVENT: |
| 1156 | cxt5047_hp_automic(codec); |
| 1157 | break; |
| 1158 | } |
| 1159 | } |
| 1160 | |
Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 1161 | /* unsolicited event for HP jack sensing - non-EAPD systems */ |
| 1162 | static void cxt5047_hp2_unsol_event(struct hda_codec *codec, |
| 1163 | unsigned int res) |
| 1164 | { |
| 1165 | res >>= 26; |
| 1166 | switch (res) { |
| 1167 | case CONEXANT_HP_EVENT: |
| 1168 | cxt5047_hp2_automute(codec); |
| 1169 | break; |
| 1170 | case CONEXANT_MIC_EVENT: |
| 1171 | cxt5047_hp_automic(codec); |
| 1172 | break; |
| 1173 | } |
| 1174 | } |
| 1175 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1176 | static struct snd_kcontrol_new cxt5047_mixers[] = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1177 | HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), |
| 1178 | HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT), |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1179 | HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT), |
| 1180 | HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1181 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), |
| 1182 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), |
| 1183 | HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), |
| 1184 | HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1185 | HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT), |
| 1186 | HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT), |
Tobin Davis | b7589ce | 2007-04-24 17:56:55 +0200 | [diff] [blame] | 1187 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT), |
| 1188 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT), |
| 1189 | HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), |
| 1190 | HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT), |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1191 | |
| 1192 | {} |
| 1193 | }; |
| 1194 | |
| 1195 | static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = { |
| 1196 | { |
| 1197 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1198 | .name = "Capture Source", |
| 1199 | .info = conexant_mux_enum_info, |
| 1200 | .get = conexant_mux_enum_get, |
| 1201 | .put = conexant_mux_enum_put |
| 1202 | }, |
| 1203 | HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), |
| 1204 | HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT), |
| 1205 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), |
| 1206 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), |
| 1207 | HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), |
| 1208 | HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), |
Takashi Iwai | cca3b37 | 2007-08-10 17:12:15 +0200 | [diff] [blame] | 1209 | HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol), |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1210 | { |
| 1211 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1212 | .name = "Master Playback Switch", |
| 1213 | .info = cxt_eapd_info, |
| 1214 | .get = cxt_eapd_get, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1215 | .put = cxt5047_hp_master_sw_put, |
| 1216 | .private_value = 0x13, |
| 1217 | }, |
| 1218 | |
| 1219 | {} |
| 1220 | }; |
| 1221 | |
| 1222 | static struct snd_kcontrol_new cxt5047_hp_mixers[] = { |
| 1223 | { |
| 1224 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1225 | .name = "Capture Source", |
| 1226 | .info = conexant_mux_enum_info, |
| 1227 | .get = conexant_mux_enum_get, |
| 1228 | .put = conexant_mux_enum_put |
| 1229 | }, |
| 1230 | HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), |
| 1231 | HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT), |
| 1232 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), |
| 1233 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), |
| 1234 | HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), |
| 1235 | HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), |
| 1236 | HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), |
| 1237 | { |
| 1238 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1239 | .name = "Master Playback Switch", |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1240 | .info = cxt_eapd_info, |
| 1241 | .get = cxt_eapd_get, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1242 | .put = cxt5047_hp_master_sw_put, |
| 1243 | .private_value = 0x13, |
| 1244 | }, |
| 1245 | { } /* end */ |
| 1246 | }; |
| 1247 | |
| 1248 | static struct hda_verb cxt5047_init_verbs[] = { |
| 1249 | /* Line in, Mic, Built-in Mic */ |
| 1250 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, |
| 1251 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, |
| 1252 | {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] | 1253 | /* HP, Speaker */ |
Tobin Davis | b7589ce | 2007-04-24 17:56:55 +0200 | [diff] [blame] | 1254 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
| 1255 | {0x13, AC_VERB_SET_CONNECT_SEL,0x1}, |
Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1256 | {0x1d, AC_VERB_SET_CONNECT_SEL,0x0}, |
| 1257 | /* Record selector: Mic */ |
| 1258 | {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, |
| 1259 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, |
| 1260 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, |
| 1261 | {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1262 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, |
| 1263 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, |
| 1264 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, |
| 1265 | 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] | 1266 | /* SPDIF route: PCM */ |
| 1267 | { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1268 | /* Enable unsolicited events */ |
| 1269 | {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, |
| 1270 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1271 | { } /* end */ |
| 1272 | }; |
| 1273 | |
| 1274 | /* configuration for Toshiba Laptops */ |
| 1275 | static struct hda_verb cxt5047_toshiba_init_verbs[] = { |
| 1276 | {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */ |
| 1277 | /* pin sensing on HP and Mic jacks */ |
| 1278 | {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, |
| 1279 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1280 | /* Speaker routing */ |
| 1281 | {0x1d, AC_VERB_SET_CONNECT_SEL,0x1}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1282 | {} |
| 1283 | }; |
| 1284 | |
| 1285 | /* configuration for HP Laptops */ |
| 1286 | static struct hda_verb cxt5047_hp_init_verbs[] = { |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1287 | /* pin sensing on HP jack */ |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1288 | {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, |
Takashi Iwai | b84f08d | 2008-02-18 12:36:11 +0100 | [diff] [blame] | 1289 | /* 0x13 is actually shared by both HP and speaker; |
| 1290 | * setting the connection to 0 (=0x19) makes the master volume control |
| 1291 | * working mysteriouslly... |
| 1292 | */ |
| 1293 | {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1294 | /* Record selector: Ext Mic */ |
| 1295 | {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1296 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, |
| 1297 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, |
| 1298 | /* Speaker routing */ |
| 1299 | {0x1d, AC_VERB_SET_CONNECT_SEL,0x1}, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1300 | {} |
| 1301 | }; |
| 1302 | |
| 1303 | /* Test configuration for debugging, modelled after the ALC260 test |
| 1304 | * configuration. |
| 1305 | */ |
| 1306 | #ifdef CONFIG_SND_DEBUG |
| 1307 | static struct hda_input_mux cxt5047_test_capture_source = { |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1308 | .num_items = 4, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1309 | .items = { |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1310 | { "LINE1 pin", 0x0 }, |
| 1311 | { "MIC1 pin", 0x1 }, |
| 1312 | { "MIC2 pin", 0x2 }, |
| 1313 | { "CD pin", 0x3 }, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1314 | }, |
| 1315 | }; |
| 1316 | |
| 1317 | static struct snd_kcontrol_new cxt5047_test_mixer[] = { |
| 1318 | |
| 1319 | /* Output only controls */ |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1320 | HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), |
| 1321 | HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), |
| 1322 | HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), |
| 1323 | HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1324 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), |
| 1325 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), |
| 1326 | HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), |
| 1327 | HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1328 | HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), |
| 1329 | HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), |
| 1330 | HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), |
| 1331 | HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1332 | |
| 1333 | /* Modes for retasking pin widgets */ |
| 1334 | CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), |
| 1335 | CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), |
| 1336 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1337 | /* EAPD Switch Control */ |
| 1338 | CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), |
| 1339 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1340 | /* Loopback mixer controls */ |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1341 | HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), |
| 1342 | HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), |
| 1343 | HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), |
| 1344 | HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), |
| 1345 | HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), |
| 1346 | HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), |
| 1347 | HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), |
| 1348 | HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1349 | |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1350 | HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), |
| 1351 | HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), |
| 1352 | HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), |
| 1353 | HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), |
| 1354 | HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), |
| 1355 | HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), |
| 1356 | HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), |
| 1357 | HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1358 | { |
| 1359 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1360 | .name = "Input Source", |
| 1361 | .info = conexant_mux_enum_info, |
| 1362 | .get = conexant_mux_enum_get, |
| 1363 | .put = conexant_mux_enum_put, |
| 1364 | }, |
Marc Boucher | 9f113e0 | 2008-01-22 15:18:08 +0100 | [diff] [blame] | 1365 | HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), |
| 1366 | HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), |
| 1367 | HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), |
| 1368 | HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), |
| 1369 | HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), |
| 1370 | HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), |
| 1371 | HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), |
| 1372 | HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), |
| 1373 | HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), |
| 1374 | HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), |
| 1375 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1376 | { } /* end */ |
| 1377 | }; |
| 1378 | |
| 1379 | static struct hda_verb cxt5047_test_init_verbs[] = { |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1380 | /* Enable retasking pins as output, initially without power amp */ |
| 1381 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 1382 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 1383 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 1384 | |
| 1385 | /* Disable digital (SPDIF) pins initially, but users can enable |
| 1386 | * them via a mixer switch. In the case of SPDIF-out, this initverb |
| 1387 | * payload also sets the generation to 0, output to be in "consumer" |
| 1388 | * PCM format, copyright asserted, no pre-emphasis and no validity |
| 1389 | * control. |
| 1390 | */ |
| 1391 | {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, |
| 1392 | |
| 1393 | /* Ensure mic1, mic2, line1 pin widgets take input from the |
| 1394 | * OUT1 sum bus when acting as an output. |
| 1395 | */ |
| 1396 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, |
| 1397 | {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, |
| 1398 | |
| 1399 | /* Start with output sum widgets muted and their output gains at min */ |
| 1400 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 1401 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 1402 | |
| 1403 | /* Unmute retasking pin widget output buffers since the default |
| 1404 | * state appears to be output. As the pin mode is changed by the |
| 1405 | * user the pin mode control will take care of enabling the pin's |
| 1406 | * input/output buffers as needed. |
| 1407 | */ |
| 1408 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 1409 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 1410 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 1411 | |
| 1412 | /* Mute capture amp left and right */ |
| 1413 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 1414 | |
| 1415 | /* Set ADC connection select to match default mixer setting (mic1 |
| 1416 | * pin) |
| 1417 | */ |
| 1418 | {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, |
| 1419 | |
| 1420 | /* Mute all inputs to mixer widget (even unconnected ones) */ |
| 1421 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ |
| 1422 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ |
| 1423 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ |
| 1424 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ |
| 1425 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ |
| 1426 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ |
| 1427 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ |
| 1428 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ |
| 1429 | |
| 1430 | { } |
| 1431 | }; |
| 1432 | #endif |
| 1433 | |
| 1434 | |
| 1435 | /* initialize jack-sensing, too */ |
| 1436 | static int cxt5047_hp_init(struct hda_codec *codec) |
| 1437 | { |
| 1438 | conexant_init(codec); |
| 1439 | cxt5047_hp_automute(codec); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1440 | return 0; |
| 1441 | } |
| 1442 | |
| 1443 | |
| 1444 | enum { |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1445 | CXT5047_LAPTOP, /* Laptops w/o EAPD support */ |
| 1446 | CXT5047_LAPTOP_HP, /* Some HP laptops */ |
| 1447 | CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1448 | #ifdef CONFIG_SND_DEBUG |
| 1449 | CXT5047_TEST, |
| 1450 | #endif |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1451 | CXT5047_MODELS |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1452 | }; |
| 1453 | |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1454 | static const char *cxt5047_models[CXT5047_MODELS] = { |
| 1455 | [CXT5047_LAPTOP] = "laptop", |
| 1456 | [CXT5047_LAPTOP_HP] = "laptop-hp", |
| 1457 | [CXT5047_LAPTOP_EAPD] = "laptop-eapd", |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1458 | #ifdef CONFIG_SND_DEBUG |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1459 | [CXT5047_TEST] = "test", |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1460 | #endif |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1461 | }; |
| 1462 | |
| 1463 | static struct snd_pci_quirk cxt5047_cfg_tbl[] = { |
| 1464 | SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP), |
Takashi Iwai | ac3e374 | 2007-12-17 17:14:18 +0100 | [diff] [blame] | 1465 | SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1466 | SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP), |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1467 | SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP), |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1468 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1469 | {} |
| 1470 | }; |
| 1471 | |
| 1472 | static int patch_cxt5047(struct hda_codec *codec) |
| 1473 | { |
| 1474 | struct conexant_spec *spec; |
| 1475 | int board_config; |
| 1476 | |
| 1477 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 1478 | if (!spec) |
| 1479 | return -ENOMEM; |
| 1480 | mutex_init(&spec->amp_mutex); |
| 1481 | codec->spec = spec; |
| 1482 | |
| 1483 | spec->multiout.max_channels = 2; |
| 1484 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); |
| 1485 | spec->multiout.dac_nids = cxt5047_dac_nids; |
| 1486 | spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; |
| 1487 | spec->num_adc_nids = 1; |
| 1488 | spec->adc_nids = cxt5047_adc_nids; |
| 1489 | spec->capsrc_nids = cxt5047_capsrc_nids; |
| 1490 | spec->input_mux = &cxt5047_capture_source; |
| 1491 | spec->num_mixers = 1; |
| 1492 | spec->mixers[0] = cxt5047_mixers; |
| 1493 | spec->num_init_verbs = 1; |
| 1494 | spec->init_verbs[0] = cxt5047_init_verbs; |
| 1495 | spec->spdif_route = 0; |
Tobin Davis | 5cd5752 | 2006-11-20 17:42:09 +0100 | [diff] [blame] | 1496 | spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), |
| 1497 | spec->channel_mode = cxt5047_modes, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1498 | |
| 1499 | codec->patch_ops = conexant_patch_ops; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1500 | |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1501 | board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, |
| 1502 | cxt5047_models, |
| 1503 | cxt5047_cfg_tbl); |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1504 | switch (board_config) { |
| 1505 | case CXT5047_LAPTOP: |
Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 1506 | codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1507 | break; |
| 1508 | case CXT5047_LAPTOP_HP: |
| 1509 | spec->input_mux = &cxt5047_hp_capture_source; |
| 1510 | spec->num_init_verbs = 2; |
| 1511 | spec->init_verbs[1] = cxt5047_hp_init_verbs; |
| 1512 | spec->mixers[0] = cxt5047_hp_mixers; |
Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 1513 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1514 | codec->patch_ops.init = cxt5047_hp_init; |
| 1515 | break; |
| 1516 | case CXT5047_LAPTOP_EAPD: |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1517 | spec->input_mux = &cxt5047_toshiba_capture_source; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1518 | spec->num_init_verbs = 2; |
| 1519 | spec->init_verbs[1] = cxt5047_toshiba_init_verbs; |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1520 | spec->mixers[0] = cxt5047_toshiba_mixers; |
Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 1521 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1522 | break; |
| 1523 | #ifdef CONFIG_SND_DEBUG |
| 1524 | case CXT5047_TEST: |
| 1525 | spec->input_mux = &cxt5047_test_capture_source; |
| 1526 | spec->mixers[0] = cxt5047_test_mixer; |
| 1527 | spec->init_verbs[0] = cxt5047_test_init_verbs; |
Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 1528 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1529 | #endif |
| 1530 | } |
| 1531 | return 0; |
| 1532 | } |
| 1533 | |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1534 | /* Conexant 5051 specific */ |
| 1535 | static hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; |
| 1536 | static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; |
| 1537 | #define CXT5051_SPDIF_OUT 0x1C |
| 1538 | #define CXT5051_PORTB_EVENT 0x38 |
| 1539 | #define CXT5051_PORTC_EVENT 0x39 |
| 1540 | |
| 1541 | static struct hda_channel_mode cxt5051_modes[1] = { |
| 1542 | { 2, NULL }, |
| 1543 | }; |
| 1544 | |
| 1545 | static void cxt5051_update_speaker(struct hda_codec *codec) |
| 1546 | { |
| 1547 | struct conexant_spec *spec = codec->spec; |
| 1548 | unsigned int pinctl; |
| 1549 | pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; |
| 1550 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1551 | pinctl); |
| 1552 | } |
| 1553 | |
| 1554 | /* turn on/off EAPD (+ mute HP) as a master switch */ |
| 1555 | static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, |
| 1556 | struct snd_ctl_elem_value *ucontrol) |
| 1557 | { |
| 1558 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1559 | |
| 1560 | if (!cxt_eapd_put(kcontrol, ucontrol)) |
| 1561 | return 0; |
| 1562 | cxt5051_update_speaker(codec); |
| 1563 | return 1; |
| 1564 | } |
| 1565 | |
| 1566 | /* toggle input of built-in and mic jack appropriately */ |
| 1567 | static void cxt5051_portb_automic(struct hda_codec *codec) |
| 1568 | { |
| 1569 | unsigned int present; |
| 1570 | |
| 1571 | present = snd_hda_codec_read(codec, 0x17, 0, |
| 1572 | AC_VERB_GET_PIN_SENSE, 0) & |
| 1573 | AC_PINSENSE_PRESENCE; |
| 1574 | snd_hda_codec_write(codec, 0x14, 0, |
| 1575 | AC_VERB_SET_CONNECT_SEL, |
| 1576 | present ? 0x01 : 0x00); |
| 1577 | } |
| 1578 | |
| 1579 | /* switch the current ADC according to the jack state */ |
| 1580 | static void cxt5051_portc_automic(struct hda_codec *codec) |
| 1581 | { |
| 1582 | struct conexant_spec *spec = codec->spec; |
| 1583 | unsigned int present; |
| 1584 | hda_nid_t new_adc; |
| 1585 | |
| 1586 | present = snd_hda_codec_read(codec, 0x18, 0, |
| 1587 | AC_VERB_GET_PIN_SENSE, 0) & |
| 1588 | AC_PINSENSE_PRESENCE; |
| 1589 | if (present) |
| 1590 | spec->cur_adc_idx = 1; |
| 1591 | else |
| 1592 | spec->cur_adc_idx = 0; |
| 1593 | new_adc = spec->adc_nids[spec->cur_adc_idx]; |
| 1594 | if (spec->cur_adc && spec->cur_adc != new_adc) { |
| 1595 | /* stream is running, let's swap the current ADC */ |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame^] | 1596 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1597 | spec->cur_adc = new_adc; |
| 1598 | snd_hda_codec_setup_stream(codec, new_adc, |
| 1599 | spec->cur_adc_stream_tag, 0, |
| 1600 | spec->cur_adc_format); |
| 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | /* mute internal speaker if HP is plugged */ |
| 1605 | static void cxt5051_hp_automute(struct hda_codec *codec) |
| 1606 | { |
| 1607 | struct conexant_spec *spec = codec->spec; |
| 1608 | |
| 1609 | spec->hp_present = snd_hda_codec_read(codec, 0x16, 0, |
| 1610 | AC_VERB_GET_PIN_SENSE, 0) & |
| 1611 | AC_PINSENSE_PRESENCE; |
| 1612 | cxt5051_update_speaker(codec); |
| 1613 | } |
| 1614 | |
| 1615 | /* unsolicited event for HP jack sensing */ |
| 1616 | static void cxt5051_hp_unsol_event(struct hda_codec *codec, |
| 1617 | unsigned int res) |
| 1618 | { |
| 1619 | switch (res >> 26) { |
| 1620 | case CONEXANT_HP_EVENT: |
| 1621 | cxt5051_hp_automute(codec); |
| 1622 | break; |
| 1623 | case CXT5051_PORTB_EVENT: |
| 1624 | cxt5051_portb_automic(codec); |
| 1625 | break; |
| 1626 | case CXT5051_PORTC_EVENT: |
| 1627 | cxt5051_portc_automic(codec); |
| 1628 | break; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | static struct snd_kcontrol_new cxt5051_mixers[] = { |
| 1633 | HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), |
| 1634 | HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), |
| 1635 | HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT), |
| 1636 | HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT), |
| 1637 | HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), |
| 1638 | HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), |
| 1639 | HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), |
| 1640 | { |
| 1641 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1642 | .name = "Master Playback Switch", |
| 1643 | .info = cxt_eapd_info, |
| 1644 | .get = cxt_eapd_get, |
| 1645 | .put = cxt5051_hp_master_sw_put, |
| 1646 | .private_value = 0x1a, |
| 1647 | }, |
| 1648 | |
| 1649 | {} |
| 1650 | }; |
| 1651 | |
| 1652 | static struct snd_kcontrol_new cxt5051_hp_mixers[] = { |
| 1653 | HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), |
| 1654 | HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), |
| 1655 | HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT), |
| 1656 | HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT), |
| 1657 | HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), |
| 1658 | { |
| 1659 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1660 | .name = "Master Playback Switch", |
| 1661 | .info = cxt_eapd_info, |
| 1662 | .get = cxt_eapd_get, |
| 1663 | .put = cxt5051_hp_master_sw_put, |
| 1664 | .private_value = 0x1a, |
| 1665 | }, |
| 1666 | |
| 1667 | {} |
| 1668 | }; |
| 1669 | |
| 1670 | static struct hda_verb cxt5051_init_verbs[] = { |
| 1671 | /* Line in, Mic */ |
| 1672 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, |
| 1673 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, |
| 1674 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, |
| 1675 | {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, |
| 1676 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, |
| 1677 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, |
| 1678 | /* SPK */ |
| 1679 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
| 1680 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, |
| 1681 | /* HP, Amp */ |
| 1682 | {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, |
| 1683 | {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, |
| 1684 | /* DAC1 */ |
| 1685 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 1686 | /* Record selector: Int mic */ |
| 1687 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, |
| 1688 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, |
| 1689 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, |
| 1690 | /* SPDIF route: PCM */ |
| 1691 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 1692 | /* EAPD */ |
| 1693 | {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ |
| 1694 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, |
| 1695 | {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT}, |
| 1696 | {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT}, |
| 1697 | { } /* end */ |
| 1698 | }; |
| 1699 | |
| 1700 | /* initialize jack-sensing, too */ |
| 1701 | static int cxt5051_init(struct hda_codec *codec) |
| 1702 | { |
| 1703 | conexant_init(codec); |
| 1704 | if (codec->patch_ops.unsol_event) { |
| 1705 | cxt5051_hp_automute(codec); |
| 1706 | cxt5051_portb_automic(codec); |
| 1707 | cxt5051_portc_automic(codec); |
| 1708 | } |
| 1709 | return 0; |
| 1710 | } |
| 1711 | |
| 1712 | |
| 1713 | enum { |
| 1714 | CXT5051_LAPTOP, /* Laptops w/ EAPD support */ |
| 1715 | CXT5051_HP, /* no docking */ |
| 1716 | CXT5051_MODELS |
| 1717 | }; |
| 1718 | |
| 1719 | static const char *cxt5051_models[CXT5051_MODELS] = { |
| 1720 | [CXT5051_LAPTOP] = "laptop", |
| 1721 | [CXT5051_HP] = "hp", |
| 1722 | }; |
| 1723 | |
| 1724 | static struct snd_pci_quirk cxt5051_cfg_tbl[] = { |
| 1725 | SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", |
| 1726 | CXT5051_LAPTOP), |
| 1727 | SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), |
| 1728 | {} |
| 1729 | }; |
| 1730 | |
| 1731 | static int patch_cxt5051(struct hda_codec *codec) |
| 1732 | { |
| 1733 | struct conexant_spec *spec; |
| 1734 | int board_config; |
| 1735 | |
| 1736 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 1737 | if (!spec) |
| 1738 | return -ENOMEM; |
| 1739 | mutex_init(&spec->amp_mutex); |
| 1740 | codec->spec = spec; |
| 1741 | |
| 1742 | codec->patch_ops = conexant_patch_ops; |
| 1743 | codec->patch_ops.init = cxt5051_init; |
| 1744 | |
| 1745 | spec->multiout.max_channels = 2; |
| 1746 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); |
| 1747 | spec->multiout.dac_nids = cxt5051_dac_nids; |
| 1748 | spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; |
| 1749 | spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ |
| 1750 | spec->adc_nids = cxt5051_adc_nids; |
| 1751 | spec->num_mixers = 1; |
| 1752 | spec->mixers[0] = cxt5051_mixers; |
| 1753 | spec->num_init_verbs = 1; |
| 1754 | spec->init_verbs[0] = cxt5051_init_verbs; |
| 1755 | spec->spdif_route = 0; |
| 1756 | spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); |
| 1757 | spec->channel_mode = cxt5051_modes; |
| 1758 | spec->cur_adc = 0; |
| 1759 | spec->cur_adc_idx = 0; |
| 1760 | |
| 1761 | board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, |
| 1762 | cxt5051_models, |
| 1763 | cxt5051_cfg_tbl); |
| 1764 | switch (board_config) { |
| 1765 | case CXT5051_HP: |
| 1766 | codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; |
| 1767 | spec->mixers[0] = cxt5051_hp_mixers; |
| 1768 | break; |
| 1769 | default: |
| 1770 | case CXT5051_LAPTOP: |
| 1771 | codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; |
| 1772 | break; |
| 1773 | } |
| 1774 | |
| 1775 | return 0; |
| 1776 | } |
| 1777 | |
| 1778 | |
| 1779 | /* |
| 1780 | */ |
| 1781 | |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1782 | struct hda_codec_preset snd_hda_preset_conexant[] = { |
Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1783 | { .id = 0x14f15045, .name = "CX20549 (Venice)", |
| 1784 | .patch = patch_cxt5045 }, |
| 1785 | { .id = 0x14f15047, .name = "CX20551 (Waikiki)", |
| 1786 | .patch = patch_cxt5047 }, |
Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1787 | { .id = 0x14f15051, .name = "CX20561 (Hermosa)", |
| 1788 | .patch = patch_cxt5051 }, |
Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1789 | {} /* terminator */ |
| 1790 | }; |