]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - sound/pci/hda/patch_conexant.c
ALSA: hda - Fix HP dv6736 mic input
[linux-2.6-omap-h63xx.git] / sound / pci / hda / patch_conexant.c
1 /*
2  * HD audio interface patch for Conexant HDA audio codec
3  *
4  * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5  *                    Takashi Iwai <tiwai@suse.de>
6  *                    Tobin Davis  <tdavis@dsl-only.net>
7  *
8  *  This driver is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This driver is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  */
22
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/slab.h>
26 #include <linux/pci.h>
27 #include <sound/core.h>
28 #include <sound/jack.h>
29
30 #include "hda_codec.h"
31 #include "hda_local.h"
32
33 #define CXT_PIN_DIR_IN              0x00
34 #define CXT_PIN_DIR_OUT             0x01
35 #define CXT_PIN_DIR_INOUT           0x02
36 #define CXT_PIN_DIR_IN_NOMICBIAS    0x03
37 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
38
39 #define CONEXANT_HP_EVENT       0x37
40 #define CONEXANT_MIC_EVENT      0x38
41
42 /* Conexant 5051 specific */
43
44 #define CXT5051_SPDIF_OUT       0x1C
45 #define CXT5051_PORTB_EVENT     0x38
46 #define CXT5051_PORTC_EVENT     0x39
47
48
49 struct conexant_jack {
50
51         hda_nid_t nid;
52         int type;
53         struct snd_jack *jack;
54
55 };
56
57 struct conexant_spec {
58
59         struct snd_kcontrol_new *mixers[5];
60         int num_mixers;
61
62         const struct hda_verb *init_verbs[5];   /* initialization verbs
63                                                  * don't forget NULL
64                                                  * termination!
65                                                  */
66         unsigned int num_init_verbs;
67
68         /* playback */
69         struct hda_multi_out multiout;  /* playback set-up
70                                          * max_channels, dacs must be set
71                                          * dig_out_nid and hp_nid are optional
72                                          */
73         unsigned int cur_eapd;
74         unsigned int hp_present;
75         unsigned int no_auto_mic;
76         unsigned int need_dac_fix;
77
78         /* capture */
79         unsigned int num_adc_nids;
80         hda_nid_t *adc_nids;
81         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
82
83         unsigned int cur_adc_idx;
84         hda_nid_t cur_adc;
85         unsigned int cur_adc_stream_tag;
86         unsigned int cur_adc_format;
87
88         /* capture source */
89         const struct hda_input_mux *input_mux;
90         hda_nid_t *capsrc_nids;
91         unsigned int cur_mux[3];
92
93         /* channel model */
94         const struct hda_channel_mode *channel_mode;
95         int num_channel_mode;
96
97         /* PCM information */
98         struct hda_pcm pcm_rec[2];      /* used in build_pcms() */
99
100         unsigned int spdif_route;
101
102         /* jack detection */
103         struct snd_array jacks;
104
105         /* dynamic controls, init_verbs and input_mux */
106         struct auto_pin_cfg autocfg;
107         struct hda_input_mux private_imux;
108         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
109
110 };
111
112 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
113                                       struct hda_codec *codec,
114                                       struct snd_pcm_substream *substream)
115 {
116         struct conexant_spec *spec = codec->spec;
117         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
118                                              hinfo);
119 }
120
121 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
122                                          struct hda_codec *codec,
123                                          unsigned int stream_tag,
124                                          unsigned int format,
125                                          struct snd_pcm_substream *substream)
126 {
127         struct conexant_spec *spec = codec->spec;
128         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
129                                                 stream_tag,
130                                                 format, substream);
131 }
132
133 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
134                                          struct hda_codec *codec,
135                                          struct snd_pcm_substream *substream)
136 {
137         struct conexant_spec *spec = codec->spec;
138         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
139 }
140
141 /*
142  * Digital out
143  */
144 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
145                                           struct hda_codec *codec,
146                                           struct snd_pcm_substream *substream)
147 {
148         struct conexant_spec *spec = codec->spec;
149         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
150 }
151
152 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
153                                          struct hda_codec *codec,
154                                          struct snd_pcm_substream *substream)
155 {
156         struct conexant_spec *spec = codec->spec;
157         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
158 }
159
160 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
161                                          struct hda_codec *codec,
162                                          unsigned int stream_tag,
163                                          unsigned int format,
164                                          struct snd_pcm_substream *substream)
165 {
166         struct conexant_spec *spec = codec->spec;
167         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
168                                              stream_tag,
169                                              format, substream);
170 }
171
172 /*
173  * Analog capture
174  */
175 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
176                                       struct hda_codec *codec,
177                                       unsigned int stream_tag,
178                                       unsigned int format,
179                                       struct snd_pcm_substream *substream)
180 {
181         struct conexant_spec *spec = codec->spec;
182         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
183                                    stream_tag, 0, format);
184         return 0;
185 }
186
187 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
188                                       struct hda_codec *codec,
189                                       struct snd_pcm_substream *substream)
190 {
191         struct conexant_spec *spec = codec->spec;
192         snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
193         return 0;
194 }
195
196
197
198 static struct hda_pcm_stream conexant_pcm_analog_playback = {
199         .substreams = 1,
200         .channels_min = 2,
201         .channels_max = 2,
202         .nid = 0, /* fill later */
203         .ops = {
204                 .open = conexant_playback_pcm_open,
205                 .prepare = conexant_playback_pcm_prepare,
206                 .cleanup = conexant_playback_pcm_cleanup
207         },
208 };
209
210 static struct hda_pcm_stream conexant_pcm_analog_capture = {
211         .substreams = 1,
212         .channels_min = 2,
213         .channels_max = 2,
214         .nid = 0, /* fill later */
215         .ops = {
216                 .prepare = conexant_capture_pcm_prepare,
217                 .cleanup = conexant_capture_pcm_cleanup
218         },
219 };
220
221
222 static struct hda_pcm_stream conexant_pcm_digital_playback = {
223         .substreams = 1,
224         .channels_min = 2,
225         .channels_max = 2,
226         .nid = 0, /* fill later */
227         .ops = {
228                 .open = conexant_dig_playback_pcm_open,
229                 .close = conexant_dig_playback_pcm_close,
230                 .prepare = conexant_dig_playback_pcm_prepare
231         },
232 };
233
234 static struct hda_pcm_stream conexant_pcm_digital_capture = {
235         .substreams = 1,
236         .channels_min = 2,
237         .channels_max = 2,
238         /* NID is set in alc_build_pcms */
239 };
240
241 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
242                                       struct hda_codec *codec,
243                                       unsigned int stream_tag,
244                                       unsigned int format,
245                                       struct snd_pcm_substream *substream)
246 {
247         struct conexant_spec *spec = codec->spec;
248         spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
249         spec->cur_adc_stream_tag = stream_tag;
250         spec->cur_adc_format = format;
251         snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
252         return 0;
253 }
254
255 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
256                                       struct hda_codec *codec,
257                                       struct snd_pcm_substream *substream)
258 {
259         struct conexant_spec *spec = codec->spec;
260         snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
261         spec->cur_adc = 0;
262         return 0;
263 }
264
265 static struct hda_pcm_stream cx5051_pcm_analog_capture = {
266         .substreams = 1,
267         .channels_min = 2,
268         .channels_max = 2,
269         .nid = 0, /* fill later */
270         .ops = {
271                 .prepare = cx5051_capture_pcm_prepare,
272                 .cleanup = cx5051_capture_pcm_cleanup
273         },
274 };
275
276 static int conexant_build_pcms(struct hda_codec *codec)
277 {
278         struct conexant_spec *spec = codec->spec;
279         struct hda_pcm *info = spec->pcm_rec;
280
281         codec->num_pcms = 1;
282         codec->pcm_info = info;
283
284         info->name = "CONEXANT Analog";
285         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
286         info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
287                 spec->multiout.max_channels;
288         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
289                 spec->multiout.dac_nids[0];
290         if (codec->vendor_id == 0x14f15051)
291                 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
292                         cx5051_pcm_analog_capture;
293         else
294                 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
295                         conexant_pcm_analog_capture;
296         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
297         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
298
299         if (spec->multiout.dig_out_nid) {
300                 info++;
301                 codec->num_pcms++;
302                 info->name = "Conexant Digital";
303                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
304                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
305                         conexant_pcm_digital_playback;
306                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
307                         spec->multiout.dig_out_nid;
308                 if (spec->dig_in_nid) {
309                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
310                                 conexant_pcm_digital_capture;
311                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
312                                 spec->dig_in_nid;
313                 }
314         }
315
316         return 0;
317 }
318
319 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
320                                   struct snd_ctl_elem_info *uinfo)
321 {
322         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
323         struct conexant_spec *spec = codec->spec;
324
325         return snd_hda_input_mux_info(spec->input_mux, uinfo);
326 }
327
328 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
329                                  struct snd_ctl_elem_value *ucontrol)
330 {
331         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
332         struct conexant_spec *spec = codec->spec;
333         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
334
335         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
336         return 0;
337 }
338
339 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
340                                  struct snd_ctl_elem_value *ucontrol)
341 {
342         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
343         struct conexant_spec *spec = codec->spec;
344         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
345
346         return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
347                                      spec->capsrc_nids[adc_idx],
348                                      &spec->cur_mux[adc_idx]);
349 }
350
351 #ifdef CONFIG_SND_JACK
352 static int conexant_add_jack(struct hda_codec *codec,
353                 hda_nid_t nid, int type)
354 {
355         struct conexant_spec *spec;
356         struct conexant_jack *jack;
357         const char *name;
358
359         spec = codec->spec;
360         snd_array_init(&spec->jacks, sizeof(*jack), 32);
361         jack = snd_array_new(&spec->jacks);
362         name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
363
364         if (!jack)
365                 return -ENOMEM;
366
367         jack->nid = nid;
368         jack->type = type;
369
370         return snd_jack_new(codec->bus->card, name, type, &jack->jack);
371 }
372
373 static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
374 {
375         struct conexant_spec *spec = codec->spec;
376         struct conexant_jack *jacks = spec->jacks.list;
377
378         if (jacks) {
379                 int i;
380                 for (i = 0; i < spec->jacks.used; i++) {
381                         if (jacks->nid == nid) {
382                                 unsigned int present;
383                                 present = snd_hda_codec_read(codec, nid, 0,
384                                                 AC_VERB_GET_PIN_SENSE, 0) &
385                                         AC_PINSENSE_PRESENCE;
386
387                                 present = (present) ? jacks->type : 0 ;
388
389                                 snd_jack_report(jacks->jack,
390                                                 present);
391                         }
392                         jacks++;
393                 }
394         }
395 }
396
397 static int conexant_init_jacks(struct hda_codec *codec)
398 {
399         struct conexant_spec *spec = codec->spec;
400         int i;
401
402         for (i = 0; i < spec->num_init_verbs; i++) {
403                 const struct hda_verb *hv;
404
405                 hv = spec->init_verbs[i];
406                 while (hv->nid) {
407                         int err = 0;
408                         switch (hv->param ^ AC_USRSP_EN) {
409                         case CONEXANT_HP_EVENT:
410                                 err = conexant_add_jack(codec, hv->nid,
411                                                 SND_JACK_HEADPHONE);
412                                 conexant_report_jack(codec, hv->nid);
413                                 break;
414                         case CXT5051_PORTC_EVENT:
415                         case CONEXANT_MIC_EVENT:
416                                 err = conexant_add_jack(codec, hv->nid,
417                                                 SND_JACK_MICROPHONE);
418                                 conexant_report_jack(codec, hv->nid);
419                                 break;
420                         }
421                         if (err < 0)
422                                 return err;
423                         ++hv;
424                 }
425         }
426         return 0;
427
428 }
429 #else
430 static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
431 {
432 }
433
434 static inline int conexant_init_jacks(struct hda_codec *codec)
435 {
436         return 0;
437 }
438 #endif
439
440 static int conexant_init(struct hda_codec *codec)
441 {
442         struct conexant_spec *spec = codec->spec;
443         int i;
444
445         for (i = 0; i < spec->num_init_verbs; i++)
446                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
447         return 0;
448 }
449
450 static void conexant_free(struct hda_codec *codec)
451 {
452 #ifdef CONFIG_SND_JACK
453         struct conexant_spec *spec = codec->spec;
454         if (spec->jacks.list) {
455                 struct conexant_jack *jacks = spec->jacks.list;
456                 int i;
457                 for (i = 0; i < spec->jacks.used; i++)
458                         snd_device_free(codec->bus->card, &jacks[i].jack);
459                 snd_array_free(&spec->jacks);
460         }
461 #endif
462         kfree(codec->spec);
463 }
464
465 static int conexant_build_controls(struct hda_codec *codec)
466 {
467         struct conexant_spec *spec = codec->spec;
468         unsigned int i;
469         int err;
470
471         for (i = 0; i < spec->num_mixers; i++) {
472                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
473                 if (err < 0)
474                         return err;
475         }
476         if (spec->multiout.dig_out_nid) {
477                 err = snd_hda_create_spdif_out_ctls(codec,
478                                                     spec->multiout.dig_out_nid);
479                 if (err < 0)
480                         return err;
481                 err = snd_hda_create_spdif_share_sw(codec,
482                                                     &spec->multiout);
483                 if (err < 0)
484                         return err;
485                 spec->multiout.share_spdif = 1;
486         } 
487         if (spec->dig_in_nid) {
488                 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
489                 if (err < 0)
490                         return err;
491         }
492         return 0;
493 }
494
495 static struct hda_codec_ops conexant_patch_ops = {
496         .build_controls = conexant_build_controls,
497         .build_pcms = conexant_build_pcms,
498         .init = conexant_init,
499         .free = conexant_free,
500 };
501
502 /*
503  * EAPD control
504  * the private value = nid | (invert << 8)
505  */
506
507 #define cxt_eapd_info           snd_ctl_boolean_mono_info
508
509 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
510                              struct snd_ctl_elem_value *ucontrol)
511 {
512         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
513         struct conexant_spec *spec = codec->spec;
514         int invert = (kcontrol->private_value >> 8) & 1;
515         if (invert)
516                 ucontrol->value.integer.value[0] = !spec->cur_eapd;
517         else
518                 ucontrol->value.integer.value[0] = spec->cur_eapd;
519         return 0;
520
521 }
522
523 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
524                              struct snd_ctl_elem_value *ucontrol)
525 {
526         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
527         struct conexant_spec *spec = codec->spec;
528         int invert = (kcontrol->private_value >> 8) & 1;
529         hda_nid_t nid = kcontrol->private_value & 0xff;
530         unsigned int eapd;
531
532         eapd = !!ucontrol->value.integer.value[0];
533         if (invert)
534                 eapd = !eapd;
535         if (eapd == spec->cur_eapd)
536                 return 0;
537         
538         spec->cur_eapd = eapd;
539         snd_hda_codec_write_cache(codec, nid,
540                                   0, AC_VERB_SET_EAPD_BTLENABLE,
541                                   eapd ? 0x02 : 0x00);
542         return 1;
543 }
544
545 /* controls for test mode */
546 #ifdef CONFIG_SND_DEBUG
547
548 #define CXT_EAPD_SWITCH(xname, nid, mask) \
549         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
550           .info = cxt_eapd_info, \
551           .get = cxt_eapd_get, \
552           .put = cxt_eapd_put, \
553           .private_value = nid | (mask<<16) }
554
555
556
557 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
558                                  struct snd_ctl_elem_info *uinfo)
559 {
560         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
561         struct conexant_spec *spec = codec->spec;
562         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
563                                     spec->num_channel_mode);
564 }
565
566 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
567                                 struct snd_ctl_elem_value *ucontrol)
568 {
569         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
570         struct conexant_spec *spec = codec->spec;
571         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
572                                    spec->num_channel_mode,
573                                    spec->multiout.max_channels);
574 }
575
576 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
577                                 struct snd_ctl_elem_value *ucontrol)
578 {
579         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
580         struct conexant_spec *spec = codec->spec;
581         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
582                                       spec->num_channel_mode,
583                                       &spec->multiout.max_channels);
584         if (err >= 0 && spec->need_dac_fix)
585                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
586         return err;
587 }
588
589 #define CXT_PIN_MODE(xname, nid, dir) \
590         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
591           .info = conexant_ch_mode_info, \
592           .get = conexant_ch_mode_get, \
593           .put = conexant_ch_mode_put, \
594           .private_value = nid | (dir<<16) }
595
596 #endif /* CONFIG_SND_DEBUG */
597
598 /* Conexant 5045 specific */
599
600 static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
601 static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
602 static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
603 #define CXT5045_SPDIF_OUT       0x18
604
605 static struct hda_channel_mode cxt5045_modes[1] = {
606         { 2, NULL },
607 };
608
609 static struct hda_input_mux cxt5045_capture_source = {
610         .num_items = 2,
611         .items = {
612                 { "IntMic", 0x1 },
613                 { "ExtMic", 0x2 },
614         }
615 };
616
617 static struct hda_input_mux cxt5045_capture_source_benq = {
618         .num_items = 3,
619         .items = {
620                 { "IntMic", 0x1 },
621                 { "ExtMic", 0x2 },
622                 { "LineIn", 0x3 },
623         }
624 };
625
626 static struct hda_input_mux cxt5045_capture_source_hp530 = {
627         .num_items = 2,
628         .items = {
629                 { "ExtMic", 0x1 },
630                 { "IntMic", 0x2 },
631         }
632 };
633
634 /* turn on/off EAPD (+ mute HP) as a master switch */
635 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
636                                     struct snd_ctl_elem_value *ucontrol)
637 {
638         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639         struct conexant_spec *spec = codec->spec;
640         unsigned int bits;
641
642         if (!cxt_eapd_put(kcontrol, ucontrol))
643                 return 0;
644
645         /* toggle internal speakers mute depending of presence of
646          * the headphone jack
647          */
648         bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
649         snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
650                                  HDA_AMP_MUTE, bits);
651
652         bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
653         snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
654                                  HDA_AMP_MUTE, bits);
655         return 1;
656 }
657
658 /* bind volumes of both NID 0x10 and 0x11 */
659 static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
660         .ops = &snd_hda_bind_vol,
661         .values = {
662                 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
663                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
664                 0
665         },
666 };
667
668 /* toggle input of built-in and mic jack appropriately */
669 static void cxt5045_hp_automic(struct hda_codec *codec)
670 {
671         static struct hda_verb mic_jack_on[] = {
672                 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
673                 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
674                 {}
675         };
676         static struct hda_verb mic_jack_off[] = {
677                 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
678                 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
679                 {}
680         };
681         unsigned int present;
682
683         present = snd_hda_codec_read(codec, 0x12, 0,
684                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
685         if (present)
686                 snd_hda_sequence_write(codec, mic_jack_on);
687         else
688                 snd_hda_sequence_write(codec, mic_jack_off);
689 }
690
691
692 /* mute internal speaker if HP is plugged */
693 static void cxt5045_hp_automute(struct hda_codec *codec)
694 {
695         struct conexant_spec *spec = codec->spec;
696         unsigned int bits;
697
698         spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
699                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
700
701         bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 
702         snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
703                                  HDA_AMP_MUTE, bits);
704 }
705
706 /* unsolicited event for HP jack sensing */
707 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
708                                    unsigned int res)
709 {
710         res >>= 26;
711         switch (res) {
712         case CONEXANT_HP_EVENT:
713                 cxt5045_hp_automute(codec);
714                 break;
715         case CONEXANT_MIC_EVENT:
716                 cxt5045_hp_automic(codec);
717                 break;
718
719         }
720 }
721
722 static struct snd_kcontrol_new cxt5045_mixers[] = {
723         {
724                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
725                 .name = "Capture Source",
726                 .info = conexant_mux_enum_info,
727                 .get = conexant_mux_enum_get,
728                 .put = conexant_mux_enum_put
729         },
730         HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
731         HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
732         HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
733         HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
734         HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
735         HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
736         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
737         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
738         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
739         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
740         HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
741         {
742                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
743                 .name = "Master Playback Switch",
744                 .info = cxt_eapd_info,
745                 .get = cxt_eapd_get,
746                 .put = cxt5045_hp_master_sw_put,
747                 .private_value = 0x10,
748         },
749
750         {}
751 };
752
753 static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
754         HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
755         HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
756         HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
757         HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
758
759         {}
760 };
761
762 static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
763         {
764                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
765                 .name = "Capture Source",
766                 .info = conexant_mux_enum_info,
767                 .get = conexant_mux_enum_get,
768                 .put = conexant_mux_enum_put
769         },
770         HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
771         HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
772         HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
773         HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
774         HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
775         HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
776         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
777         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
778         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
779         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
780         HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
781         {
782                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
783                 .name = "Master Playback Switch",
784                 .info = cxt_eapd_info,
785                 .get = cxt_eapd_get,
786                 .put = cxt5045_hp_master_sw_put,
787                 .private_value = 0x10,
788         },
789
790         {}
791 };
792
793 static struct hda_verb cxt5045_init_verbs[] = {
794         /* Line in, Mic */
795         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
796         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
797         /* HP, Amp  */
798         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
799         {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
800         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
801         {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
802         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
803         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
804         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
805         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
806         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
807         /* Record selector: Int mic */
808         {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
809         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
810          AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
811         /* SPDIF route: PCM */
812         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
813         { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
814         /* EAPD */
815         {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 
816         { } /* end */
817 };
818
819 static struct hda_verb cxt5045_benq_init_verbs[] = {
820         /* Int Mic, Mic */
821         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
822         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
823         /* Line In,HP, Amp  */
824         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
825         {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
826         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
827         {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
828         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
829         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
830         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
831         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
832         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
833         /* Record selector: Int mic */
834         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
835         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
836          AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
837         /* SPDIF route: PCM */
838         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
839         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
840         /* EAPD */
841         {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
842         { } /* end */
843 };
844
845 static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
846         /* pin sensing on HP jack */
847         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
848         { } /* end */
849 };
850
851 static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
852         /* pin sensing on HP jack */
853         {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
854         { } /* end */
855 };
856
857 #ifdef CONFIG_SND_DEBUG
858 /* Test configuration for debugging, modelled after the ALC260 test
859  * configuration.
860  */
861 static struct hda_input_mux cxt5045_test_capture_source = {
862         .num_items = 5,
863         .items = {
864                 { "MIXER", 0x0 },
865                 { "MIC1 pin", 0x1 },
866                 { "LINE1 pin", 0x2 },
867                 { "HP-OUT pin", 0x3 },
868                 { "CD pin", 0x4 },
869         },
870 };
871
872 static struct snd_kcontrol_new cxt5045_test_mixer[] = {
873
874         /* Output controls */
875         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
876         HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
877         HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
878         HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
879         HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
880         HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
881         
882         /* Modes for retasking pin widgets */
883         CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
884         CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
885
886         /* EAPD Switch Control */
887         CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
888
889         /* Loopback mixer controls */
890
891         HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
892         HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
893         HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
894         HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
895         HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
896         HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
897         HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
898         HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
899         HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
900         HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
901         {
902                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
903                 .name = "Input Source",
904                 .info = conexant_mux_enum_info,
905                 .get = conexant_mux_enum_get,
906                 .put = conexant_mux_enum_put,
907         },
908         /* Audio input controls */
909         HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
910         HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
911         HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
912         HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
913         HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
914         HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
915         HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
916         HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
917         HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
918         HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
919         { } /* end */
920 };
921
922 static struct hda_verb cxt5045_test_init_verbs[] = {
923         /* Set connections */
924         { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
925         { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
926         { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
927         /* Enable retasking pins as output, initially without power amp */
928         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
929         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
930
931         /* Disable digital (SPDIF) pins initially, but users can enable
932          * them via a mixer switch.  In the case of SPDIF-out, this initverb
933          * payload also sets the generation to 0, output to be in "consumer"
934          * PCM format, copyright asserted, no pre-emphasis and no validity
935          * control.
936          */
937         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
938         {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
939
940         /* Start with output sum widgets muted and their output gains at min */
941         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
942         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
943
944         /* Unmute retasking pin widget output buffers since the default
945          * state appears to be output.  As the pin mode is changed by the
946          * user the pin mode control will take care of enabling the pin's
947          * input/output buffers as needed.
948          */
949         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
950         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
951
952         /* Mute capture amp left and right */
953         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
954
955         /* Set ADC connection select to match default mixer setting (mic1
956          * pin)
957          */
958         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
959         {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
960
961         /* Mute all inputs to mixer widget (even unconnected ones) */
962         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
963         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
964         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
965         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
966         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
967
968         { }
969 };
970 #endif
971
972
973 /* initialize jack-sensing, too */
974 static int cxt5045_init(struct hda_codec *codec)
975 {
976         conexant_init(codec);
977         cxt5045_hp_automute(codec);
978         return 0;
979 }
980
981
982 enum {
983         CXT5045_LAPTOP_HPSENSE,
984         CXT5045_LAPTOP_MICSENSE,
985         CXT5045_LAPTOP_HPMICSENSE,
986         CXT5045_BENQ,
987         CXT5045_LAPTOP_HP530,
988 #ifdef CONFIG_SND_DEBUG
989         CXT5045_TEST,
990 #endif
991         CXT5045_MODELS
992 };
993
994 static const char *cxt5045_models[CXT5045_MODELS] = {
995         [CXT5045_LAPTOP_HPSENSE]        = "laptop-hpsense",
996         [CXT5045_LAPTOP_MICSENSE]       = "laptop-micsense",
997         [CXT5045_LAPTOP_HPMICSENSE]     = "laptop-hpmicsense",
998         [CXT5045_BENQ]                  = "benq",
999         [CXT5045_LAPTOP_HP530]          = "laptop-hp530",
1000 #ifdef CONFIG_SND_DEBUG
1001         [CXT5045_TEST]          = "test",
1002 #endif
1003 };
1004
1005 static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1006         SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1007         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1008                            CXT5045_LAPTOP_HPSENSE),
1009         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1010         SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1011         SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1012         SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1013         SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1014                       CXT5045_LAPTOP_HPMICSENSE),
1015         SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1016         SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1017         SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1018         SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1019                            CXT5045_LAPTOP_HPMICSENSE),
1020         SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1021         {}
1022 };
1023
1024 static int patch_cxt5045(struct hda_codec *codec)
1025 {
1026         struct conexant_spec *spec;
1027         int board_config;
1028
1029         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1030         if (!spec)
1031                 return -ENOMEM;
1032         codec->spec = spec;
1033
1034         spec->multiout.max_channels = 2;
1035         spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1036         spec->multiout.dac_nids = cxt5045_dac_nids;
1037         spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1038         spec->num_adc_nids = 1;
1039         spec->adc_nids = cxt5045_adc_nids;
1040         spec->capsrc_nids = cxt5045_capsrc_nids;
1041         spec->input_mux = &cxt5045_capture_source;
1042         spec->num_mixers = 1;
1043         spec->mixers[0] = cxt5045_mixers;
1044         spec->num_init_verbs = 1;
1045         spec->init_verbs[0] = cxt5045_init_verbs;
1046         spec->spdif_route = 0;
1047         spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1048         spec->channel_mode = cxt5045_modes,
1049
1050
1051         codec->patch_ops = conexant_patch_ops;
1052
1053         board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1054                                                   cxt5045_models,
1055                                                   cxt5045_cfg_tbl);
1056         switch (board_config) {
1057         case CXT5045_LAPTOP_HPSENSE:
1058                 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1059                 spec->input_mux = &cxt5045_capture_source;
1060                 spec->num_init_verbs = 2;
1061                 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1062                 spec->mixers[0] = cxt5045_mixers;
1063                 codec->patch_ops.init = cxt5045_init;
1064                 break;
1065         case CXT5045_LAPTOP_MICSENSE:
1066                 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1067                 spec->input_mux = &cxt5045_capture_source;
1068                 spec->num_init_verbs = 2;
1069                 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1070                 spec->mixers[0] = cxt5045_mixers;
1071                 codec->patch_ops.init = cxt5045_init;
1072                 break;
1073         default:
1074         case CXT5045_LAPTOP_HPMICSENSE:
1075                 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1076                 spec->input_mux = &cxt5045_capture_source;
1077                 spec->num_init_verbs = 3;
1078                 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1079                 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1080                 spec->mixers[0] = cxt5045_mixers;
1081                 codec->patch_ops.init = cxt5045_init;
1082                 break;
1083         case CXT5045_BENQ:
1084                 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1085                 spec->input_mux = &cxt5045_capture_source_benq;
1086                 spec->num_init_verbs = 1;
1087                 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1088                 spec->mixers[0] = cxt5045_mixers;
1089                 spec->mixers[1] = cxt5045_benq_mixers;
1090                 spec->num_mixers = 2;
1091                 codec->patch_ops.init = cxt5045_init;
1092                 break;
1093         case CXT5045_LAPTOP_HP530:
1094                 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1095                 spec->input_mux = &cxt5045_capture_source_hp530;
1096                 spec->num_init_verbs = 2;
1097                 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1098                 spec->mixers[0] = cxt5045_mixers_hp530;
1099                 codec->patch_ops.init = cxt5045_init;
1100                 break;
1101 #ifdef CONFIG_SND_DEBUG
1102         case CXT5045_TEST:
1103                 spec->input_mux = &cxt5045_test_capture_source;
1104                 spec->mixers[0] = cxt5045_test_mixer;
1105                 spec->init_verbs[0] = cxt5045_test_init_verbs;
1106                 break;
1107                 
1108 #endif  
1109         }
1110
1111         switch (codec->subsystem_id >> 16) {
1112         case 0x103c:
1113                 /* HP laptop has a really bad sound over 0dB on NID 0x17.
1114                  * Fix max PCM level to 0 dB
1115                  * (originall it has 0x2b steps with 0dB offset 0x14)
1116                  */
1117                 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1118                                           (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1119                                           (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1120                                           (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1121                                           (1 << AC_AMPCAP_MUTE_SHIFT));
1122                 break;
1123         }
1124
1125         return 0;
1126 }
1127
1128
1129 /* Conexant 5047 specific */
1130 #define CXT5047_SPDIF_OUT       0x11
1131
1132 static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
1133 static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1134 static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1135
1136 static struct hda_channel_mode cxt5047_modes[1] = {
1137         { 2, NULL },
1138 };
1139
1140 static struct hda_input_mux cxt5047_capture_source = {
1141         .num_items = 1,
1142         .items = {
1143                 { "Mic", 0x2 },
1144         }
1145 };
1146
1147 static struct hda_input_mux cxt5047_hp_capture_source = {
1148         .num_items = 1,
1149         .items = {
1150                 { "ExtMic", 0x2 },
1151         }
1152 };
1153
1154 static struct hda_input_mux cxt5047_toshiba_capture_source = {
1155         .num_items = 2,
1156         .items = {
1157                 { "ExtMic", 0x2 },
1158                 { "Line-In", 0x1 },
1159         }
1160 };
1161
1162 /* turn on/off EAPD (+ mute HP) as a master switch */
1163 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1164                                     struct snd_ctl_elem_value *ucontrol)
1165 {
1166         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1167         struct conexant_spec *spec = codec->spec;
1168         unsigned int bits;
1169
1170         if (!cxt_eapd_put(kcontrol, ucontrol))
1171                 return 0;
1172
1173         /* toggle internal speakers mute depending of presence of
1174          * the headphone jack
1175          */
1176         bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1177         snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1178                                  HDA_AMP_MUTE, bits);
1179         bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1180         snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1181                                  HDA_AMP_MUTE, bits);
1182         return 1;
1183 }
1184
1185 /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
1186 static struct hda_bind_ctls cxt5047_bind_master_vol = {
1187         .ops = &snd_hda_bind_vol,
1188         .values = {
1189                 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1190                 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1191                 0
1192         },
1193 };
1194
1195 /* mute internal speaker if HP is plugged */
1196 static void cxt5047_hp_automute(struct hda_codec *codec)
1197 {
1198         struct conexant_spec *spec = codec->spec;
1199         unsigned int bits;
1200
1201         spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1202                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1203
1204         bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1205         snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1206                                  HDA_AMP_MUTE, bits);
1207         /* Mute/Unmute PCM 2 for good measure - some systems need this */
1208         snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1209                                  HDA_AMP_MUTE, bits);
1210 }
1211
1212 /* mute internal speaker if HP is plugged */
1213 static void cxt5047_hp2_automute(struct hda_codec *codec)
1214 {
1215         struct conexant_spec *spec = codec->spec;
1216         unsigned int bits;
1217
1218         spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1219                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1220
1221         bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1222         snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1223                                  HDA_AMP_MUTE, bits);
1224         /* Mute/Unmute PCM 2 for good measure - some systems need this */
1225         snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1226                                  HDA_AMP_MUTE, bits);
1227 }
1228
1229 /* toggle input of built-in and mic jack appropriately */
1230 static void cxt5047_hp_automic(struct hda_codec *codec)
1231 {
1232         static struct hda_verb mic_jack_on[] = {
1233                 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1234                 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1235                 {}
1236         };
1237         static struct hda_verb mic_jack_off[] = {
1238                 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1239                 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1240                 {}
1241         };
1242         unsigned int present;
1243
1244         present = snd_hda_codec_read(codec, 0x15, 0,
1245                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1246         if (present)
1247                 snd_hda_sequence_write(codec, mic_jack_on);
1248         else
1249                 snd_hda_sequence_write(codec, mic_jack_off);
1250 }
1251
1252 /* unsolicited event for HP jack sensing */
1253 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1254                                   unsigned int res)
1255 {
1256         switch (res >> 26) {
1257         case CONEXANT_HP_EVENT:
1258                 cxt5047_hp_automute(codec);
1259                 break;
1260         case CONEXANT_MIC_EVENT:
1261                 cxt5047_hp_automic(codec);
1262                 break;
1263         }
1264 }
1265
1266 /* unsolicited event for HP jack sensing - non-EAPD systems */
1267 static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1268                                   unsigned int res)
1269 {
1270         res >>= 26;
1271         switch (res) {
1272         case CONEXANT_HP_EVENT:
1273                 cxt5047_hp2_automute(codec);
1274                 break;
1275         case CONEXANT_MIC_EVENT:
1276                 cxt5047_hp_automic(codec);
1277                 break;
1278         }
1279 }
1280
1281 static struct snd_kcontrol_new cxt5047_mixers[] = {
1282         HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1283         HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1284         HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1285         HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
1286         HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1287         HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1288         HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1289         HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1290         HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1291         HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
1292         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1293         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1294         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1295         HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
1296
1297         {}
1298 };
1299
1300 static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1301         {
1302                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1303                 .name = "Capture Source",
1304                 .info = conexant_mux_enum_info,
1305                 .get = conexant_mux_enum_get,
1306                 .put = conexant_mux_enum_put
1307         },
1308         HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1309         HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1310         HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1311         HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1312         HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1313         HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1314         HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
1315         {
1316                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1317                 .name = "Master Playback Switch",
1318                 .info = cxt_eapd_info,
1319                 .get = cxt_eapd_get,
1320                 .put = cxt5047_hp_master_sw_put,
1321                 .private_value = 0x13,
1322         },
1323
1324         {}
1325 };
1326
1327 static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1328         {
1329                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1330                 .name = "Capture Source",
1331                 .info = conexant_mux_enum_info,
1332                 .get = conexant_mux_enum_get,
1333                 .put = conexant_mux_enum_put
1334         },
1335         HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1336         HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1337         HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1338         HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1339         HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1340         HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1341         HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1342         {
1343                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1344                 .name = "Master Playback Switch",
1345                 .info = cxt_eapd_info,
1346                 .get = cxt_eapd_get,
1347                 .put = cxt5047_hp_master_sw_put,
1348                 .private_value = 0x13,
1349         },
1350         { } /* end */
1351 };
1352
1353 static struct hda_verb cxt5047_init_verbs[] = {
1354         /* Line in, Mic, Built-in Mic */
1355         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1356         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1357         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1358         /* HP, Speaker  */
1359         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1360         {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
1361         {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1362         /* Record selector: Mic */
1363         {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1364         {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1365          AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1366         {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1367         {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1368          AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1369         {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1370          AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1371         /* SPDIF route: PCM */
1372         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1373         /* Enable unsolicited events */
1374         {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1375         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1376         { } /* end */
1377 };
1378
1379 /* configuration for Toshiba Laptops */
1380 static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1381         {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1382         /* pin sensing on HP and Mic jacks */
1383         {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1384         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1385         /* Speaker routing */
1386         {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1387         {}
1388 };
1389
1390 /* configuration for HP Laptops */
1391 static struct hda_verb cxt5047_hp_init_verbs[] = {
1392         /* pin sensing on HP jack */
1393         {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1394         /* 0x13 is actually shared by both HP and speaker;
1395          * setting the connection to 0 (=0x19) makes the master volume control
1396          * working mysteriouslly...
1397          */
1398         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1399         /* Record selector: Ext Mic */
1400         {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1401         {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1402          AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1403         /* Speaker routing */
1404         {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1405         {}
1406 };
1407
1408 /* Test configuration for debugging, modelled after the ALC260 test
1409  * configuration.
1410  */
1411 #ifdef CONFIG_SND_DEBUG
1412 static struct hda_input_mux cxt5047_test_capture_source = {
1413         .num_items = 4,
1414         .items = {
1415                 { "LINE1 pin", 0x0 },
1416                 { "MIC1 pin", 0x1 },
1417                 { "MIC2 pin", 0x2 },
1418                 { "CD pin", 0x3 },
1419         },
1420 };
1421
1422 static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1423
1424         /* Output only controls */
1425         HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1426         HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1427         HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1428         HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1429         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1430         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1431         HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1432         HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1433         HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1434         HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1435         HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1436         HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1437
1438         /* Modes for retasking pin widgets */
1439         CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1440         CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1441
1442         /* EAPD Switch Control */
1443         CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1444
1445         /* Loopback mixer controls */
1446         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1447         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1448         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1449         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1450         HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1451         HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1452         HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1453         HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1454
1455         HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1456         HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1457         HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1458         HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1459         HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1460         HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1461         HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1462         HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1463         {
1464                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1465                 .name = "Input Source",
1466                 .info = conexant_mux_enum_info,
1467                 .get = conexant_mux_enum_get,
1468                 .put = conexant_mux_enum_put,
1469         },
1470         HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1471         HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1472         HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1473         HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1474         HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1475         HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1476         HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1477         HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1478         HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1479         HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1480
1481         { } /* end */
1482 };
1483
1484 static struct hda_verb cxt5047_test_init_verbs[] = {
1485         /* Enable retasking pins as output, initially without power amp */
1486         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1487         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1488         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1489
1490         /* Disable digital (SPDIF) pins initially, but users can enable
1491          * them via a mixer switch.  In the case of SPDIF-out, this initverb
1492          * payload also sets the generation to 0, output to be in "consumer"
1493          * PCM format, copyright asserted, no pre-emphasis and no validity
1494          * control.
1495          */
1496         {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1497
1498         /* Ensure mic1, mic2, line1 pin widgets take input from the 
1499          * OUT1 sum bus when acting as an output.
1500          */
1501         {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1502         {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1503
1504         /* Start with output sum widgets muted and their output gains at min */
1505         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1506         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1507
1508         /* Unmute retasking pin widget output buffers since the default
1509          * state appears to be output.  As the pin mode is changed by the
1510          * user the pin mode control will take care of enabling the pin's
1511          * input/output buffers as needed.
1512          */
1513         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1514         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1515         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1516
1517         /* Mute capture amp left and right */
1518         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1519
1520         /* Set ADC connection select to match default mixer setting (mic1
1521          * pin)
1522          */
1523         {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1524
1525         /* Mute all inputs to mixer widget (even unconnected ones) */
1526         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1527         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1528         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1529         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1530         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1531         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1532         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1533         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1534
1535         { }
1536 };
1537 #endif
1538
1539
1540 /* initialize jack-sensing, too */
1541 static int cxt5047_hp_init(struct hda_codec *codec)
1542 {
1543         conexant_init(codec);
1544         cxt5047_hp_automute(codec);
1545         return 0;
1546 }
1547
1548
1549 enum {
1550         CXT5047_LAPTOP,         /* Laptops w/o EAPD support */
1551         CXT5047_LAPTOP_HP,      /* Some HP laptops */
1552         CXT5047_LAPTOP_EAPD,    /* Laptops with EAPD support */
1553 #ifdef CONFIG_SND_DEBUG
1554         CXT5047_TEST,
1555 #endif
1556         CXT5047_MODELS
1557 };
1558
1559 static const char *cxt5047_models[CXT5047_MODELS] = {
1560         [CXT5047_LAPTOP]        = "laptop",
1561         [CXT5047_LAPTOP_HP]     = "laptop-hp",
1562         [CXT5047_LAPTOP_EAPD]   = "laptop-eapd",
1563 #ifdef CONFIG_SND_DEBUG
1564         [CXT5047_TEST]          = "test",
1565 #endif
1566 };
1567
1568 static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1569         SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1570         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1571                            CXT5047_LAPTOP),
1572         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1573         {}
1574 };
1575
1576 static int patch_cxt5047(struct hda_codec *codec)
1577 {
1578         struct conexant_spec *spec;
1579         int board_config;
1580
1581         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1582         if (!spec)
1583                 return -ENOMEM;
1584         codec->spec = spec;
1585
1586         spec->multiout.max_channels = 2;
1587         spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1588         spec->multiout.dac_nids = cxt5047_dac_nids;
1589         spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1590         spec->num_adc_nids = 1;
1591         spec->adc_nids = cxt5047_adc_nids;
1592         spec->capsrc_nids = cxt5047_capsrc_nids;
1593         spec->input_mux = &cxt5047_capture_source;
1594         spec->num_mixers = 1;
1595         spec->mixers[0] = cxt5047_mixers;
1596         spec->num_init_verbs = 1;
1597         spec->init_verbs[0] = cxt5047_init_verbs;
1598         spec->spdif_route = 0;
1599         spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1600         spec->channel_mode = cxt5047_modes,
1601
1602         codec->patch_ops = conexant_patch_ops;
1603
1604         board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1605                                                   cxt5047_models,
1606                                                   cxt5047_cfg_tbl);
1607         switch (board_config) {
1608         case CXT5047_LAPTOP:
1609                 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
1610                 break;
1611         case CXT5047_LAPTOP_HP:
1612                 spec->input_mux = &cxt5047_hp_capture_source;
1613                 spec->num_init_verbs = 2;
1614                 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1615                 spec->mixers[0] = cxt5047_hp_mixers;
1616                 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1617                 codec->patch_ops.init = cxt5047_hp_init;
1618                 break;
1619         case CXT5047_LAPTOP_EAPD:
1620                 spec->input_mux = &cxt5047_toshiba_capture_source;
1621                 spec->num_init_verbs = 2;
1622                 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1623                 spec->mixers[0] = cxt5047_toshiba_mixers;
1624                 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1625                 break;
1626 #ifdef CONFIG_SND_DEBUG
1627         case CXT5047_TEST:
1628                 spec->input_mux = &cxt5047_test_capture_source;
1629                 spec->mixers[0] = cxt5047_test_mixer;
1630                 spec->init_verbs[0] = cxt5047_test_init_verbs;
1631                 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1632 #endif  
1633         }
1634         return 0;
1635 }
1636
1637 /* Conexant 5051 specific */
1638 static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1639 static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1640
1641 static struct hda_channel_mode cxt5051_modes[1] = {
1642         { 2, NULL },
1643 };
1644
1645 static void cxt5051_update_speaker(struct hda_codec *codec)
1646 {
1647         struct conexant_spec *spec = codec->spec;
1648         unsigned int pinctl;
1649         pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1650         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1651                             pinctl);
1652 }
1653
1654 /* turn on/off EAPD (+ mute HP) as a master switch */
1655 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1656                                     struct snd_ctl_elem_value *ucontrol)
1657 {
1658         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1659
1660         if (!cxt_eapd_put(kcontrol, ucontrol))
1661                 return 0;
1662         cxt5051_update_speaker(codec);
1663         return 1;
1664 }
1665
1666 /* toggle input of built-in and mic jack appropriately */
1667 static void cxt5051_portb_automic(struct hda_codec *codec)
1668 {
1669         struct conexant_spec *spec = codec->spec;
1670         unsigned int present;
1671
1672         if (spec->no_auto_mic)
1673                 return;
1674         present = snd_hda_codec_read(codec, 0x17, 0,
1675                                      AC_VERB_GET_PIN_SENSE, 0) &
1676                 AC_PINSENSE_PRESENCE;
1677         snd_hda_codec_write(codec, 0x14, 0,
1678                             AC_VERB_SET_CONNECT_SEL,
1679                             present ? 0x01 : 0x00);
1680 }
1681
1682 /* switch the current ADC according to the jack state */
1683 static void cxt5051_portc_automic(struct hda_codec *codec)
1684 {
1685         struct conexant_spec *spec = codec->spec;
1686         unsigned int present;
1687         hda_nid_t new_adc;
1688
1689         if (spec->no_auto_mic)
1690                 return;
1691         present = snd_hda_codec_read(codec, 0x18, 0,
1692                                      AC_VERB_GET_PIN_SENSE, 0) &
1693                 AC_PINSENSE_PRESENCE;
1694         if (present)
1695                 spec->cur_adc_idx = 1;
1696         else
1697                 spec->cur_adc_idx = 0;
1698         new_adc = spec->adc_nids[spec->cur_adc_idx];
1699         if (spec->cur_adc && spec->cur_adc != new_adc) {
1700                 /* stream is running, let's swap the current ADC */
1701                 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1702                 spec->cur_adc = new_adc;
1703                 snd_hda_codec_setup_stream(codec, new_adc,
1704                                            spec->cur_adc_stream_tag, 0,
1705                                            spec->cur_adc_format);
1706         }
1707 }
1708
1709 /* mute internal speaker if HP is plugged */
1710 static void cxt5051_hp_automute(struct hda_codec *codec)
1711 {
1712         struct conexant_spec *spec = codec->spec;
1713
1714         spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1715                                      AC_VERB_GET_PIN_SENSE, 0) &
1716                 AC_PINSENSE_PRESENCE;
1717         cxt5051_update_speaker(codec);
1718 }
1719
1720 /* unsolicited event for HP jack sensing */
1721 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1722                                    unsigned int res)
1723 {
1724         int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1725         switch (res >> 26) {
1726         case CONEXANT_HP_EVENT:
1727                 cxt5051_hp_automute(codec);
1728                 break;
1729         case CXT5051_PORTB_EVENT:
1730                 cxt5051_portb_automic(codec);
1731                 break;
1732         case CXT5051_PORTC_EVENT:
1733                 cxt5051_portc_automic(codec);
1734                 break;
1735         }
1736         conexant_report_jack(codec, nid);
1737 }
1738
1739 static struct snd_kcontrol_new cxt5051_mixers[] = {
1740         HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1741         HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1742         HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1743         HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1744         HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1745         HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1746         HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1747         {
1748                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1749                 .name = "Master Playback Switch",
1750                 .info = cxt_eapd_info,
1751                 .get = cxt_eapd_get,
1752                 .put = cxt5051_hp_master_sw_put,
1753                 .private_value = 0x1a,
1754         },
1755
1756         {}
1757 };
1758
1759 static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1760         HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1761         HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1762         HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1763         HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1764         HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1765         {
1766                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1767                 .name = "Master Playback Switch",
1768                 .info = cxt_eapd_info,
1769                 .get = cxt_eapd_get,
1770                 .put = cxt5051_hp_master_sw_put,
1771                 .private_value = 0x1a,
1772         },
1773
1774         {}
1775 };
1776
1777 static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1778         HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
1779         HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
1780         HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1781         {
1782                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1783                 .name = "Master Playback Switch",
1784                 .info = cxt_eapd_info,
1785                 .get = cxt_eapd_get,
1786                 .put = cxt5051_hp_master_sw_put,
1787                 .private_value = 0x1a,
1788         },
1789
1790         {}
1791 };
1792
1793 static struct hda_verb cxt5051_init_verbs[] = {
1794         /* Line in, Mic */
1795         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1796         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1797         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1798         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1799         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1800         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1801         /* SPK  */
1802         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1803         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1804         /* HP, Amp  */
1805         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1806         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1807         /* DAC1 */      
1808         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1809         /* Record selector: Int mic */
1810         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1811         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1812         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1813         /* SPDIF route: PCM */
1814         {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1815         /* EAPD */
1816         {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 
1817         {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1818         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1819         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1820         { } /* end */
1821 };
1822
1823 static struct hda_verb cxt5051_hp_dv6736_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_PIN_WIDGET_CONTROL, 0x0},
1828         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1829         /* SPK  */
1830         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1831         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1832         /* HP, Amp  */
1833         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1834         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1835         /* DAC1 */
1836         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1837         /* Record selector: Int mic */
1838         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1839         {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1840         /* SPDIF route: PCM */
1841         {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1842         /* EAPD */
1843         {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1844         {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1845         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1846         { } /* end */
1847 };
1848
1849 static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1850         /* Line in, Mic */
1851         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1852         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1853         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1854         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1855         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1856         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1857         /* SPK  */
1858         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1859         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1860         /* HP, Amp  */
1861         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1862         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1863         /* Docking HP */
1864         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1865         {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1866         /* DAC1 */
1867         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1868         /* Record selector: Int mic */
1869         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1870         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1871         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1872         /* SPDIF route: PCM */
1873         {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1874         /* EAPD */
1875         {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1876         {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1877         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1878         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1879         {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1880         { } /* end */
1881 };
1882
1883 /* initialize jack-sensing, too */
1884 static int cxt5051_init(struct hda_codec *codec)
1885 {
1886         conexant_init(codec);
1887         conexant_init_jacks(codec);
1888         if (codec->patch_ops.unsol_event) {
1889                 cxt5051_hp_automute(codec);
1890                 cxt5051_portb_automic(codec);
1891                 cxt5051_portc_automic(codec);
1892         }
1893         return 0;
1894 }
1895
1896
1897 enum {
1898         CXT5051_LAPTOP,  /* Laptops w/ EAPD support */
1899         CXT5051_HP,     /* no docking */
1900         CXT5051_HP_DV6736,      /* HP without mic switch */
1901         CXT5051_LENOVO_X200,    /* Lenovo X200 laptop */
1902         CXT5051_MODELS
1903 };
1904
1905 static const char *cxt5051_models[CXT5051_MODELS] = {
1906         [CXT5051_LAPTOP]        = "laptop",
1907         [CXT5051_HP]            = "hp",
1908         [CXT5051_HP_DV6736]     = "hp-dv6736",
1909         [CXT5051_LENOVO_X200]   = "lenovo-x200",
1910 };
1911
1912 static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1913         SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1914         SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1915                       CXT5051_LAPTOP),
1916         SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1917         SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1918         {}
1919 };
1920
1921 static int patch_cxt5051(struct hda_codec *codec)
1922 {
1923         struct conexant_spec *spec;
1924         int board_config;
1925
1926         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1927         if (!spec)
1928                 return -ENOMEM;
1929         codec->spec = spec;
1930
1931         codec->patch_ops = conexant_patch_ops;
1932         codec->patch_ops.init = cxt5051_init;
1933
1934         spec->multiout.max_channels = 2;
1935         spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1936         spec->multiout.dac_nids = cxt5051_dac_nids;
1937         spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1938         spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1939         spec->adc_nids = cxt5051_adc_nids;
1940         spec->num_mixers = 1;
1941         spec->mixers[0] = cxt5051_mixers;
1942         spec->num_init_verbs = 1;
1943         spec->init_verbs[0] = cxt5051_init_verbs;
1944         spec->spdif_route = 0;
1945         spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1946         spec->channel_mode = cxt5051_modes;
1947         spec->cur_adc = 0;
1948         spec->cur_adc_idx = 0;
1949
1950         codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1951
1952         board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1953                                                   cxt5051_models,
1954                                                   cxt5051_cfg_tbl);
1955         switch (board_config) {
1956         case CXT5051_HP:
1957                 spec->mixers[0] = cxt5051_hp_mixers;
1958                 break;
1959         case CXT5051_HP_DV6736:
1960                 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1961                 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1962                 spec->no_auto_mic = 1;
1963                 break;
1964         case CXT5051_LENOVO_X200:
1965                 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
1966                 break;
1967         }
1968
1969         return 0;
1970 }
1971
1972
1973 /*
1974  */
1975
1976 static struct hda_codec_preset snd_hda_preset_conexant[] = {
1977         { .id = 0x14f15045, .name = "CX20549 (Venice)",
1978           .patch = patch_cxt5045 },
1979         { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1980           .patch = patch_cxt5047 },
1981         { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1982           .patch = patch_cxt5051 },
1983         {} /* terminator */
1984 };
1985
1986 MODULE_ALIAS("snd-hda-codec-id:14f15045");
1987 MODULE_ALIAS("snd-hda-codec-id:14f15047");
1988 MODULE_ALIAS("snd-hda-codec-id:14f15051");
1989
1990 MODULE_LICENSE("GPL");
1991 MODULE_DESCRIPTION("Conexant HD-audio codec");
1992
1993 static struct hda_codec_preset_list conexant_list = {
1994         .preset = snd_hda_preset_conexant,
1995         .owner = THIS_MODULE,
1996 };
1997
1998 static int __init patch_conexant_init(void)
1999 {
2000         return snd_hda_add_codec_preset(&conexant_list);
2001 }
2002
2003 static void __exit patch_conexant_exit(void)
2004 {
2005         snd_hda_delete_codec_preset(&conexant_list);
2006 }
2007
2008 module_init(patch_conexant_init)
2009 module_exit(patch_conexant_exit)