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