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