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