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