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