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