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