]> git.karo-electronics.de Git - karo-tx-linux.git/blob - sound/pci/hda/patch_conexant.c
ALSA: hda - Add inv_eapd flag to struct hda_codec
[karo-tx-linux.git] / sound / pci / hda / patch_conexant.c
1 /*
2  * HD audio interface patch for Conexant HDA audio codec
3  *
4  * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5  *                    Takashi Iwai <tiwai@suse.de>
6  *                    Tobin Davis  <tdavis@dsl-only.net>
7  *
8  *  This driver is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This driver is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  */
22
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/slab.h>
26 #include <linux/pci.h>
27 #include <linux/module.h>
28 #include <sound/core.h>
29 #include <sound/jack.h>
30
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_auto_parser.h"
34 #include "hda_beep.h"
35 #include "hda_jack.h"
36
37 #define CXT_PIN_DIR_IN              0x00
38 #define CXT_PIN_DIR_OUT             0x01
39 #define CXT_PIN_DIR_INOUT           0x02
40 #define CXT_PIN_DIR_IN_NOMICBIAS    0x03
41 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
42
43 #define CONEXANT_HP_EVENT       0x37
44 #define CONEXANT_MIC_EVENT      0x38
45 #define CONEXANT_LINE_EVENT     0x39
46
47 /* Conexant 5051 specific */
48
49 #define CXT5051_SPDIF_OUT       0x12
50 #define CXT5051_PORTB_EVENT     0x38
51 #define CXT5051_PORTC_EVENT     0x39
52
53 #define AUTO_MIC_PORTB          (1 << 1)
54 #define AUTO_MIC_PORTC          (1 << 2)
55
56 struct pin_dac_pair {
57         hda_nid_t pin;
58         hda_nid_t dac;
59         int type;
60 };
61
62 struct imux_info {
63         hda_nid_t pin;          /* input pin NID */
64         hda_nid_t adc;          /* connected ADC NID */ 
65         hda_nid_t boost;        /* optional boost volume NID */
66         int index;              /* corresponding to autocfg.input */
67 };
68
69 struct conexant_spec {
70         const struct snd_kcontrol_new *mixers[5];
71         int num_mixers;
72         hda_nid_t vmaster_nid;
73         struct hda_vmaster_mute_hook vmaster_mute;
74         bool vmaster_mute_led;
75
76         const struct hda_verb *init_verbs[5];   /* initialization verbs
77                                                  * don't forget NULL
78                                                  * termination!
79                                                  */
80         unsigned int num_init_verbs;
81
82         /* playback */
83         struct hda_multi_out multiout;  /* playback set-up
84                                          * max_channels, dacs must be set
85                                          * dig_out_nid and hp_nid are optional
86                                          */
87         unsigned int cur_eapd;
88         unsigned int hp_present;
89         unsigned int line_present;
90         unsigned int auto_mic;
91         int auto_mic_ext;               /* imux_pins[] index for ext mic */
92         int auto_mic_dock;              /* imux_pins[] index for dock mic */
93         int auto_mic_int;               /* imux_pins[] index for int mic */
94         unsigned int need_dac_fix;
95         hda_nid_t slave_dig_outs[2];
96
97         /* capture */
98         unsigned int num_adc_nids;
99         const hda_nid_t *adc_nids;
100         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
101
102         unsigned int cur_adc_idx;
103         hda_nid_t cur_adc;
104         unsigned int cur_adc_stream_tag;
105         unsigned int cur_adc_format;
106
107         const struct hda_pcm_stream *capture_stream;
108
109         /* capture source */
110         const struct hda_input_mux *input_mux;
111         const hda_nid_t *capsrc_nids;
112         unsigned int cur_mux[3];
113
114         /* channel model */
115         const struct hda_channel_mode *channel_mode;
116         int num_channel_mode;
117
118         /* PCM information */
119         struct hda_pcm pcm_rec[2];      /* used in build_pcms() */
120
121         unsigned int spdif_route;
122
123         /* dynamic controls, init_verbs and input_mux */
124         struct auto_pin_cfg autocfg;
125         struct hda_input_mux private_imux;
126         struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
127         hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
128         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
129         struct pin_dac_pair dac_info[8];
130         int dac_info_filled;
131
132         unsigned int port_d_mode;
133         unsigned int auto_mute:1;       /* used in auto-parser */
134         unsigned int detect_line:1;     /* Line-out detection enabled */
135         unsigned int automute_lines:1;  /* automute line-out as well */
136         unsigned int automute_hp_lo:1;  /* both HP and LO available */
137         unsigned int dell_automute:1;
138         unsigned int dell_vostro:1;
139         unsigned int ideapad:1;
140         unsigned int thinkpad:1;
141         unsigned int hp_laptop:1;
142         unsigned int asus:1;
143         unsigned int pin_eapd_ctrls:1;
144         unsigned int fixup_stereo_dmic:1;
145
146         unsigned int adc_switching:1;
147
148         unsigned int ext_mic_present;
149         unsigned int recording;
150         void (*capture_prepare)(struct hda_codec *codec);
151         void (*capture_cleanup)(struct hda_codec *codec);
152
153         /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
154          * through the microphone jack.
155          * When the user enables this through a mixer switch, both internal and
156          * external microphones are disabled. Gain is fixed at 0dB. In this mode,
157          * we also allow the bias to be configured through a separate mixer
158          * control. */
159         unsigned int dc_enable;
160         unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
161         unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
162
163         unsigned int beep_amp;
164
165         /* extra EAPD pins */
166         unsigned int num_eapds;
167         hda_nid_t eapds[4];
168 };
169
170 static int conexant_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_analog_open(codec, &spec->multiout, substream,
176                                              hinfo);
177 }
178
179 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
180                                          struct hda_codec *codec,
181                                          unsigned int stream_tag,
182                                          unsigned int format,
183                                          struct snd_pcm_substream *substream)
184 {
185         struct conexant_spec *spec = codec->spec;
186         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
187                                                 stream_tag,
188                                                 format, substream);
189 }
190
191 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
192                                          struct hda_codec *codec,
193                                          struct snd_pcm_substream *substream)
194 {
195         struct conexant_spec *spec = codec->spec;
196         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
197 }
198
199 /*
200  * Digital out
201  */
202 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
203                                           struct hda_codec *codec,
204                                           struct snd_pcm_substream *substream)
205 {
206         struct conexant_spec *spec = codec->spec;
207         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
208 }
209
210 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
211                                          struct hda_codec *codec,
212                                          struct snd_pcm_substream *substream)
213 {
214         struct conexant_spec *spec = codec->spec;
215         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
216 }
217
218 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
219                                          struct hda_codec *codec,
220                                          unsigned int stream_tag,
221                                          unsigned int format,
222                                          struct snd_pcm_substream *substream)
223 {
224         struct conexant_spec *spec = codec->spec;
225         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
226                                              stream_tag,
227                                              format, substream);
228 }
229
230 /*
231  * Analog capture
232  */
233 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
234                                       struct hda_codec *codec,
235                                       unsigned int stream_tag,
236                                       unsigned int format,
237                                       struct snd_pcm_substream *substream)
238 {
239         struct conexant_spec *spec = codec->spec;
240         if (spec->capture_prepare)
241                 spec->capture_prepare(codec);
242         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
243                                    stream_tag, 0, format);
244         return 0;
245 }
246
247 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
248                                       struct hda_codec *codec,
249                                       struct snd_pcm_substream *substream)
250 {
251         struct conexant_spec *spec = codec->spec;
252         snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
253         if (spec->capture_cleanup)
254                 spec->capture_cleanup(codec);
255         return 0;
256 }
257
258
259
260 static const struct hda_pcm_stream conexant_pcm_analog_playback = {
261         .substreams = 1,
262         .channels_min = 2,
263         .channels_max = 2,
264         .nid = 0, /* fill later */
265         .ops = {
266                 .open = conexant_playback_pcm_open,
267                 .prepare = conexant_playback_pcm_prepare,
268                 .cleanup = conexant_playback_pcm_cleanup
269         },
270 };
271
272 static const struct hda_pcm_stream conexant_pcm_analog_capture = {
273         .substreams = 1,
274         .channels_min = 2,
275         .channels_max = 2,
276         .nid = 0, /* fill later */
277         .ops = {
278                 .prepare = conexant_capture_pcm_prepare,
279                 .cleanup = conexant_capture_pcm_cleanup
280         },
281 };
282
283
284 static const struct hda_pcm_stream conexant_pcm_digital_playback = {
285         .substreams = 1,
286         .channels_min = 2,
287         .channels_max = 2,
288         .nid = 0, /* fill later */
289         .ops = {
290                 .open = conexant_dig_playback_pcm_open,
291                 .close = conexant_dig_playback_pcm_close,
292                 .prepare = conexant_dig_playback_pcm_prepare
293         },
294 };
295
296 static const struct hda_pcm_stream conexant_pcm_digital_capture = {
297         .substreams = 1,
298         .channels_min = 2,
299         .channels_max = 2,
300         /* NID is set in alc_build_pcms */
301 };
302
303 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
304                                       struct hda_codec *codec,
305                                       unsigned int stream_tag,
306                                       unsigned int format,
307                                       struct snd_pcm_substream *substream)
308 {
309         struct conexant_spec *spec = codec->spec;
310         spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
311         spec->cur_adc_stream_tag = stream_tag;
312         spec->cur_adc_format = format;
313         snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
314         return 0;
315 }
316
317 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
318                                       struct hda_codec *codec,
319                                       struct snd_pcm_substream *substream)
320 {
321         struct conexant_spec *spec = codec->spec;
322         snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
323         spec->cur_adc = 0;
324         return 0;
325 }
326
327 static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
328         .substreams = 1,
329         .channels_min = 2,
330         .channels_max = 2,
331         .nid = 0, /* fill later */
332         .ops = {
333                 .prepare = cx5051_capture_pcm_prepare,
334                 .cleanup = cx5051_capture_pcm_cleanup
335         },
336 };
337
338 static bool is_2_1_speaker(struct conexant_spec *spec);
339
340 static int conexant_build_pcms(struct hda_codec *codec)
341 {
342         struct conexant_spec *spec = codec->spec;
343         struct hda_pcm *info = spec->pcm_rec;
344
345         codec->num_pcms = 1;
346         codec->pcm_info = info;
347
348         info->name = "CONEXANT Analog";
349         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
350         info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
351                 spec->multiout.max_channels;
352         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
353                 spec->multiout.dac_nids[0];
354         if (is_2_1_speaker(spec))
355                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
356                         snd_pcm_2_1_chmaps;
357         if (spec->capture_stream)
358                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
359         else {
360                 if (codec->vendor_id == 0x14f15051)
361                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
362                                 cx5051_pcm_analog_capture;
363                 else {
364                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
365                                 conexant_pcm_analog_capture;
366                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
367                                 spec->num_adc_nids;
368                 }
369         }
370         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
371
372         if (spec->multiout.dig_out_nid) {
373                 info++;
374                 codec->num_pcms++;
375                 info->name = "Conexant Digital";
376                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
377                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
378                         conexant_pcm_digital_playback;
379                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
380                         spec->multiout.dig_out_nid;
381                 if (spec->dig_in_nid) {
382                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
383                                 conexant_pcm_digital_capture;
384                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
385                                 spec->dig_in_nid;
386                 }
387                 if (spec->slave_dig_outs[0])
388                         codec->slave_dig_outs = spec->slave_dig_outs;
389         }
390
391         return 0;
392 }
393
394 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
395                                   struct snd_ctl_elem_info *uinfo)
396 {
397         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
398         struct conexant_spec *spec = codec->spec;
399
400         return snd_hda_input_mux_info(spec->input_mux, uinfo);
401 }
402
403 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
404                                  struct snd_ctl_elem_value *ucontrol)
405 {
406         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
407         struct conexant_spec *spec = codec->spec;
408         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
409
410         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
411         return 0;
412 }
413
414 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
415                                  struct snd_ctl_elem_value *ucontrol)
416 {
417         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
418         struct conexant_spec *spec = codec->spec;
419         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
420
421         return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
422                                      spec->capsrc_nids[adc_idx],
423                                      &spec->cur_mux[adc_idx]);
424 }
425
426 static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
427                                unsigned int power_state)
428 {
429         if (power_state == AC_PWRST_D3)
430                 msleep(100);
431         snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
432                             power_state);
433         /* partial workaround for "azx_get_response timeout" */
434         if (power_state == AC_PWRST_D0)
435                 msleep(10);
436         snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
437 }
438
439 static int conexant_init(struct hda_codec *codec)
440 {
441         struct conexant_spec *spec = codec->spec;
442         int i;
443
444         for (i = 0; i < spec->num_init_verbs; i++)
445                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
446         return 0;
447 }
448
449 static void conexant_free(struct hda_codec *codec)
450 {
451         struct conexant_spec *spec = codec->spec;
452         snd_hda_detach_beep_device(codec);
453         kfree(spec);
454 }
455
456 static const struct snd_kcontrol_new cxt_capture_mixers[] = {
457         {
458                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
459                 .name = "Capture Source",
460                 .info = conexant_mux_enum_info,
461                 .get = conexant_mux_enum_get,
462                 .put = conexant_mux_enum_put
463         },
464         {}
465 };
466
467 #ifdef CONFIG_SND_HDA_INPUT_BEEP
468 /* additional beep mixers; the actual parameters are overwritten at build */
469 static const struct snd_kcontrol_new cxt_beep_mixer[] = {
470         HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
471         HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
472         { } /* end */
473 };
474 #endif
475
476 static const char * const slave_pfxs[] = {
477         "Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
478         NULL
479 };
480
481 static int conexant_build_controls(struct hda_codec *codec)
482 {
483         struct conexant_spec *spec = codec->spec;
484         unsigned int i;
485         int err;
486
487         for (i = 0; i < spec->num_mixers; i++) {
488                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
489                 if (err < 0)
490                         return err;
491         }
492         if (spec->multiout.dig_out_nid) {
493                 err = snd_hda_create_spdif_out_ctls(codec,
494                                                     spec->multiout.dig_out_nid,
495                                                     spec->multiout.dig_out_nid);
496                 if (err < 0)
497                         return err;
498                 err = snd_hda_create_spdif_share_sw(codec,
499                                                     &spec->multiout);
500                 if (err < 0)
501                         return err;
502                 spec->multiout.share_spdif = 1;
503         } 
504         if (spec->dig_in_nid) {
505                 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
506                 if (err < 0)
507                         return err;
508         }
509
510         /* if we have no master control, let's create it */
511         if (spec->vmaster_nid &&
512             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
513                 unsigned int vmaster_tlv[4];
514                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
515                                         HDA_OUTPUT, vmaster_tlv);
516                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
517                                           vmaster_tlv, slave_pfxs,
518                                           "Playback Volume");
519                 if (err < 0)
520                         return err;
521         }
522         if (spec->vmaster_nid &&
523             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
524                 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
525                                             NULL, slave_pfxs,
526                                             "Playback Switch", true,
527                                             &spec->vmaster_mute.sw_kctl);
528                 if (err < 0)
529                         return err;
530         }
531
532         if (spec->input_mux) {
533                 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
534                 if (err < 0)
535                         return err;
536         }
537
538 #ifdef CONFIG_SND_HDA_INPUT_BEEP
539         /* create beep controls if needed */
540         if (spec->beep_amp) {
541                 const struct snd_kcontrol_new *knew;
542                 for (knew = cxt_beep_mixer; knew->name; knew++) {
543                         struct snd_kcontrol *kctl;
544                         kctl = snd_ctl_new1(knew, codec);
545                         if (!kctl)
546                                 return -ENOMEM;
547                         kctl->private_value = spec->beep_amp;
548                         err = snd_hda_ctl_add(codec, 0, kctl);
549                         if (err < 0)
550                                 return err;
551                 }
552         }
553 #endif
554
555         return 0;
556 }
557
558 static const struct hda_codec_ops conexant_patch_ops = {
559         .build_controls = conexant_build_controls,
560         .build_pcms = conexant_build_pcms,
561         .init = conexant_init,
562         .free = conexant_free,
563         .set_power_state = conexant_set_power,
564 };
565
566 #ifdef CONFIG_SND_HDA_INPUT_BEEP
567 #define set_beep_amp(spec, nid, idx, dir) \
568         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
569 #else
570 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
571 #endif
572
573 static int patch_conexant_auto(struct hda_codec *codec);
574 /*
575  * EAPD control
576  * the private value = nid | (invert << 8)
577  */
578
579 #define cxt_eapd_info           snd_ctl_boolean_mono_info
580
581 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
582                              struct snd_ctl_elem_value *ucontrol)
583 {
584         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
585         struct conexant_spec *spec = codec->spec;
586         int invert = (kcontrol->private_value >> 8) & 1;
587         if (invert)
588                 ucontrol->value.integer.value[0] = !spec->cur_eapd;
589         else
590                 ucontrol->value.integer.value[0] = spec->cur_eapd;
591         return 0;
592
593 }
594
595 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
596                              struct snd_ctl_elem_value *ucontrol)
597 {
598         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
599         struct conexant_spec *spec = codec->spec;
600         int invert = (kcontrol->private_value >> 8) & 1;
601         hda_nid_t nid = kcontrol->private_value & 0xff;
602         unsigned int eapd;
603
604         eapd = !!ucontrol->value.integer.value[0];
605         if (invert)
606                 eapd = !eapd;
607         if (eapd == spec->cur_eapd)
608                 return 0;
609         
610         spec->cur_eapd = eapd;
611         snd_hda_codec_write_cache(codec, nid,
612                                   0, AC_VERB_SET_EAPD_BTLENABLE,
613                                   eapd ? 0x02 : 0x00);
614         return 1;
615 }
616
617 /* controls for test mode */
618 #ifdef CONFIG_SND_DEBUG
619
620 #define CXT_EAPD_SWITCH(xname, nid, mask) \
621         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
622           .info = cxt_eapd_info, \
623           .get = cxt_eapd_get, \
624           .put = cxt_eapd_put, \
625           .private_value = nid | (mask<<16) }
626
627
628
629 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
630                                  struct snd_ctl_elem_info *uinfo)
631 {
632         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
633         struct conexant_spec *spec = codec->spec;
634         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
635                                     spec->num_channel_mode);
636 }
637
638 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
639                                 struct snd_ctl_elem_value *ucontrol)
640 {
641         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
642         struct conexant_spec *spec = codec->spec;
643         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
644                                    spec->num_channel_mode,
645                                    spec->multiout.max_channels);
646 }
647
648 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
649                                 struct snd_ctl_elem_value *ucontrol)
650 {
651         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652         struct conexant_spec *spec = codec->spec;
653         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
654                                       spec->num_channel_mode,
655                                       &spec->multiout.max_channels);
656         if (err >= 0 && spec->need_dac_fix)
657                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
658         return err;
659 }
660
661 #define CXT_PIN_MODE(xname, nid, dir) \
662         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
663           .info = conexant_ch_mode_info, \
664           .get = conexant_ch_mode_get, \
665           .put = conexant_ch_mode_put, \
666           .private_value = nid | (dir<<16) }
667
668 #endif /* CONFIG_SND_DEBUG */
669
670 /* Conexant 5045 specific */
671
672 static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
673 static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
674 static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
675 #define CXT5045_SPDIF_OUT       0x18
676
677 static const struct hda_channel_mode cxt5045_modes[1] = {
678         { 2, NULL },
679 };
680
681 static const struct hda_input_mux cxt5045_capture_source = {
682         .num_items = 2,
683         .items = {
684                 { "Internal Mic", 0x1 },
685                 { "Mic",          0x2 },
686         }
687 };
688
689 static const struct hda_input_mux cxt5045_capture_source_benq = {
690         .num_items = 4,
691         .items = {
692                 { "Internal Mic", 0x1 },
693                 { "Mic",          0x2 },
694                 { "Line",         0x3 },
695                 { "Mixer",        0x0 },
696         }
697 };
698
699 static const struct hda_input_mux cxt5045_capture_source_hp530 = {
700         .num_items = 2,
701         .items = {
702                 { "Mic",          0x1 },
703                 { "Internal Mic", 0x2 },
704         }
705 };
706
707 /* turn on/off EAPD (+ mute HP) as a master switch */
708 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
709                                     struct snd_ctl_elem_value *ucontrol)
710 {
711         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
712         struct conexant_spec *spec = codec->spec;
713         unsigned int bits;
714
715         if (!cxt_eapd_put(kcontrol, ucontrol))
716                 return 0;
717
718         /* toggle internal speakers mute depending of presence of
719          * the headphone jack
720          */
721         bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
722         snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
723                                  HDA_AMP_MUTE, bits);
724
725         bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
726         snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
727                                  HDA_AMP_MUTE, bits);
728         return 1;
729 }
730
731 /* bind volumes of both NID 0x10 and 0x11 */
732 static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
733         .ops = &snd_hda_bind_vol,
734         .values = {
735                 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
736                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
737                 0
738         },
739 };
740
741 /* toggle input of built-in and mic jack appropriately */
742 static void cxt5045_hp_automic(struct hda_codec *codec)
743 {
744         static const struct hda_verb mic_jack_on[] = {
745                 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
746                 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
747                 {}
748         };
749         static const struct hda_verb mic_jack_off[] = {
750                 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
751                 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
752                 {}
753         };
754         unsigned int present;
755
756         present = snd_hda_jack_detect(codec, 0x12);
757         if (present)
758                 snd_hda_sequence_write(codec, mic_jack_on);
759         else
760                 snd_hda_sequence_write(codec, mic_jack_off);
761 }
762
763
764 /* mute internal speaker if HP is plugged */
765 static void cxt5045_hp_automute(struct hda_codec *codec)
766 {
767         struct conexant_spec *spec = codec->spec;
768         unsigned int bits;
769
770         spec->hp_present = snd_hda_jack_detect(codec, 0x11);
771
772         bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 
773         snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
774                                  HDA_AMP_MUTE, bits);
775 }
776
777 /* unsolicited event for HP jack sensing */
778 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
779                                    unsigned int res)
780 {
781         res >>= 26;
782         switch (res) {
783         case CONEXANT_HP_EVENT:
784                 cxt5045_hp_automute(codec);
785                 break;
786         case CONEXANT_MIC_EVENT:
787                 cxt5045_hp_automic(codec);
788                 break;
789
790         }
791 }
792
793 static const struct snd_kcontrol_new cxt5045_mixers[] = {
794         HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
795         HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
796         HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
797         HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
798         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
799         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
800         HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
801         HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
802         HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
803         {
804                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
805                 .name = "Master Playback Switch",
806                 .info = cxt_eapd_info,
807                 .get = cxt_eapd_get,
808                 .put = cxt5045_hp_master_sw_put,
809                 .private_value = 0x10,
810         },
811
812         {}
813 };
814
815 static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
816         HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
817         HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
818
819         {}
820 };
821
822 static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
823         HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
824         HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
825         HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
826         HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
827         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
828         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
829         HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
830         HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
831         HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
832         {
833                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
834                 .name = "Master Playback Switch",
835                 .info = cxt_eapd_info,
836                 .get = cxt_eapd_get,
837                 .put = cxt5045_hp_master_sw_put,
838                 .private_value = 0x10,
839         },
840
841         {}
842 };
843
844 static const struct hda_verb cxt5045_init_verbs[] = {
845         /* Line in, Mic */
846         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
847         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
848         /* HP, Amp  */
849         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
850         {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
851         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
852         {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
853         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
854         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
855         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
856         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
857         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
858         /* Record selector: Internal mic */
859         {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
860         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
861          AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
862         /* SPDIF route: PCM */
863         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
864         { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
865         /* EAPD */
866         {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 
867         { } /* end */
868 };
869
870 static const struct hda_verb cxt5045_benq_init_verbs[] = {
871         /* Internal Mic, Mic */
872         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
873         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
874         /* Line In,HP, Amp  */
875         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
876         {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
877         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
878         {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
879         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
880         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
881         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
882         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
883         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
884         /* Record selector: Internal mic */
885         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
886         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
887          AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
888         /* SPDIF route: PCM */
889         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
890         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
891         /* EAPD */
892         {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
893         { } /* end */
894 };
895
896 static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
897         /* pin sensing on HP jack */
898         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
899         { } /* end */
900 };
901
902 static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
903         /* pin sensing on HP jack */
904         {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
905         { } /* end */
906 };
907
908 #ifdef CONFIG_SND_DEBUG
909 /* Test configuration for debugging, modelled after the ALC260 test
910  * configuration.
911  */
912 static const struct hda_input_mux cxt5045_test_capture_source = {
913         .num_items = 5,
914         .items = {
915                 { "MIXER", 0x0 },
916                 { "MIC1 pin", 0x1 },
917                 { "LINE1 pin", 0x2 },
918                 { "HP-OUT pin", 0x3 },
919                 { "CD pin", 0x4 },
920         },
921 };
922
923 static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
924
925         /* Output controls */
926         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
927         HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
928         HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
929         HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
930         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
931         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
932         
933         /* Modes for retasking pin widgets */
934         CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
935         CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
936
937         /* EAPD Switch Control */
938         CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
939
940         /* Loopback mixer controls */
941
942         HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
943         HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
944         HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
945         HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
946         HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
947         HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
948         HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
949         HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
950         HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
951         HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
952         {
953                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
954                 .name = "Input Source",
955                 .info = conexant_mux_enum_info,
956                 .get = conexant_mux_enum_get,
957                 .put = conexant_mux_enum_put,
958         },
959         /* Audio input controls */
960         HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
961         HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
962         { } /* end */
963 };
964
965 static const struct hda_verb cxt5045_test_init_verbs[] = {
966         /* Set connections */
967         { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
968         { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
969         { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
970         /* Enable retasking pins as output, initially without power amp */
971         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
972         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
973
974         /* Disable digital (SPDIF) pins initially, but users can enable
975          * them via a mixer switch.  In the case of SPDIF-out, this initverb
976          * payload also sets the generation to 0, output to be in "consumer"
977          * PCM format, copyright asserted, no pre-emphasis and no validity
978          * control.
979          */
980         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
981         {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
982
983         /* Unmute retasking pin widget output buffers since the default
984          * state appears to be output.  As the pin mode is changed by the
985          * user the pin mode control will take care of enabling the pin's
986          * input/output buffers as needed.
987          */
988         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
989         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
990
991         /* Mute capture amp left and right */
992         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
993
994         /* Set ADC connection select to match default mixer setting (mic1
995          * pin)
996          */
997         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
998         {0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
999
1000         /* Mute all inputs to mixer widget (even unconnected ones) */
1001         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
1002         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1003         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1004         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1005         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1006
1007         { }
1008 };
1009 #endif
1010
1011
1012 /* initialize jack-sensing, too */
1013 static int cxt5045_init(struct hda_codec *codec)
1014 {
1015         conexant_init(codec);
1016         cxt5045_hp_automute(codec);
1017         return 0;
1018 }
1019
1020
1021 enum {
1022         CXT5045_LAPTOP_HPSENSE,
1023         CXT5045_LAPTOP_MICSENSE,
1024         CXT5045_LAPTOP_HPMICSENSE,
1025         CXT5045_BENQ,
1026         CXT5045_LAPTOP_HP530,
1027 #ifdef CONFIG_SND_DEBUG
1028         CXT5045_TEST,
1029 #endif
1030         CXT5045_AUTO,
1031         CXT5045_MODELS
1032 };
1033
1034 static const char * const cxt5045_models[CXT5045_MODELS] = {
1035         [CXT5045_LAPTOP_HPSENSE]        = "laptop-hpsense",
1036         [CXT5045_LAPTOP_MICSENSE]       = "laptop-micsense",
1037         [CXT5045_LAPTOP_HPMICSENSE]     = "laptop-hpmicsense",
1038         [CXT5045_BENQ]                  = "benq",
1039         [CXT5045_LAPTOP_HP530]          = "laptop-hp530",
1040 #ifdef CONFIG_SND_DEBUG
1041         [CXT5045_TEST]          = "test",
1042 #endif
1043         [CXT5045_AUTO]                  = "auto",
1044 };
1045
1046 static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1047         SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1048         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1049         SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1050         SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1051         SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1052         SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1053                       CXT5045_LAPTOP_HPMICSENSE),
1054         SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1055         SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1056         SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1057         SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1058                            CXT5045_LAPTOP_HPMICSENSE),
1059         SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1060         {}
1061 };
1062
1063 static int patch_cxt5045(struct hda_codec *codec)
1064 {
1065         struct conexant_spec *spec;
1066         int board_config;
1067
1068         board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1069                                                   cxt5045_models,
1070                                                   cxt5045_cfg_tbl);
1071         if (board_config < 0)
1072                 board_config = CXT5045_AUTO; /* model=auto as default */
1073         if (board_config == CXT5045_AUTO)
1074                 return patch_conexant_auto(codec);
1075
1076         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1077         if (!spec)
1078                 return -ENOMEM;
1079         codec->spec = spec;
1080         codec->single_adc_amp = 1;
1081
1082         spec->multiout.max_channels = 2;
1083         spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1084         spec->multiout.dac_nids = cxt5045_dac_nids;
1085         spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1086         spec->num_adc_nids = 1;
1087         spec->adc_nids = cxt5045_adc_nids;
1088         spec->capsrc_nids = cxt5045_capsrc_nids;
1089         spec->input_mux = &cxt5045_capture_source;
1090         spec->num_mixers = 1;
1091         spec->mixers[0] = cxt5045_mixers;
1092         spec->num_init_verbs = 1;
1093         spec->init_verbs[0] = cxt5045_init_verbs;
1094         spec->spdif_route = 0;
1095         spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1096         spec->channel_mode = cxt5045_modes;
1097
1098         set_beep_amp(spec, 0x16, 0, 1);
1099
1100         codec->patch_ops = conexant_patch_ops;
1101
1102         switch (board_config) {
1103         case CXT5045_LAPTOP_HPSENSE:
1104                 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1105                 spec->input_mux = &cxt5045_capture_source;
1106                 spec->num_init_verbs = 2;
1107                 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1108                 spec->mixers[0] = cxt5045_mixers;
1109                 codec->patch_ops.init = cxt5045_init;
1110                 break;
1111         case CXT5045_LAPTOP_MICSENSE:
1112                 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1113                 spec->input_mux = &cxt5045_capture_source;
1114                 spec->num_init_verbs = 2;
1115                 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1116                 spec->mixers[0] = cxt5045_mixers;
1117                 codec->patch_ops.init = cxt5045_init;
1118                 break;
1119         default:
1120         case CXT5045_LAPTOP_HPMICSENSE:
1121                 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1122                 spec->input_mux = &cxt5045_capture_source;
1123                 spec->num_init_verbs = 3;
1124                 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1125                 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1126                 spec->mixers[0] = cxt5045_mixers;
1127                 codec->patch_ops.init = cxt5045_init;
1128                 break;
1129         case CXT5045_BENQ:
1130                 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1131                 spec->input_mux = &cxt5045_capture_source_benq;
1132                 spec->num_init_verbs = 1;
1133                 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1134                 spec->mixers[0] = cxt5045_mixers;
1135                 spec->mixers[1] = cxt5045_benq_mixers;
1136                 spec->num_mixers = 2;
1137                 codec->patch_ops.init = cxt5045_init;
1138                 break;
1139         case CXT5045_LAPTOP_HP530:
1140                 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1141                 spec->input_mux = &cxt5045_capture_source_hp530;
1142                 spec->num_init_verbs = 2;
1143                 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1144                 spec->mixers[0] = cxt5045_mixers_hp530;
1145                 codec->patch_ops.init = cxt5045_init;
1146                 break;
1147 #ifdef CONFIG_SND_DEBUG
1148         case CXT5045_TEST:
1149                 spec->input_mux = &cxt5045_test_capture_source;
1150                 spec->mixers[0] = cxt5045_test_mixer;
1151                 spec->init_verbs[0] = cxt5045_test_init_verbs;
1152                 break;
1153                 
1154 #endif  
1155         }
1156
1157         switch (codec->subsystem_id >> 16) {
1158         case 0x103c:
1159         case 0x1631:
1160         case 0x1734:
1161         case 0x17aa:
1162                 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1163                  * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1164                  * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1165                  */
1166                 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1167                                           (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1168                                           (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1169                                           (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1170                                           (1 << AC_AMPCAP_MUTE_SHIFT));
1171                 break;
1172         }
1173
1174         if (spec->beep_amp)
1175                 snd_hda_attach_beep_device(codec, spec->beep_amp);
1176
1177         return 0;
1178 }
1179
1180
1181 /* Conexant 5047 specific */
1182 #define CXT5047_SPDIF_OUT       0x11
1183
1184 static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1185 static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1186 static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1187
1188 static const struct hda_channel_mode cxt5047_modes[1] = {
1189         { 2, NULL },
1190 };
1191
1192 static const struct hda_input_mux cxt5047_toshiba_capture_source = {
1193         .num_items = 2,
1194         .items = {
1195                 { "ExtMic", 0x2 },
1196                 { "Line-In", 0x1 },
1197         }
1198 };
1199
1200 /* turn on/off EAPD (+ mute HP) as a master switch */
1201 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1202                                     struct snd_ctl_elem_value *ucontrol)
1203 {
1204         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1205         struct conexant_spec *spec = codec->spec;
1206         unsigned int bits;
1207
1208         if (!cxt_eapd_put(kcontrol, ucontrol))
1209                 return 0;
1210
1211         /* toggle internal speakers mute depending of presence of
1212          * the headphone jack
1213          */
1214         bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1215         /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1216          * pin widgets unlike other codecs.  In this case, we need to
1217          * set index 0x01 for the volume from the mixer amp 0x19.
1218          */
1219         snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1220                                  HDA_AMP_MUTE, bits);
1221         bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1222         snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1223                                  HDA_AMP_MUTE, bits);
1224         return 1;
1225 }
1226
1227 /* mute internal speaker if HP is plugged */
1228 static void cxt5047_hp_automute(struct hda_codec *codec)
1229 {
1230         struct conexant_spec *spec = codec->spec;
1231         unsigned int bits;
1232
1233         spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1234
1235         bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1236         /* See the note in cxt5047_hp_master_sw_put */
1237         snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1238                                  HDA_AMP_MUTE, bits);
1239 }
1240
1241 /* toggle input of built-in and mic jack appropriately */
1242 static void cxt5047_hp_automic(struct hda_codec *codec)
1243 {
1244         static const struct hda_verb mic_jack_on[] = {
1245                 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1246                 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1247                 {}
1248         };
1249         static const struct hda_verb mic_jack_off[] = {
1250                 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1251                 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1252                 {}
1253         };
1254         unsigned int present;
1255
1256         present = snd_hda_jack_detect(codec, 0x15);
1257         if (present)
1258                 snd_hda_sequence_write(codec, mic_jack_on);
1259         else
1260                 snd_hda_sequence_write(codec, mic_jack_off);
1261 }
1262
1263 /* unsolicited event for HP jack sensing */
1264 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1265                                   unsigned int res)
1266 {
1267         switch (res >> 26) {
1268         case CONEXANT_HP_EVENT:
1269                 cxt5047_hp_automute(codec);
1270                 break;
1271         case CONEXANT_MIC_EVENT:
1272                 cxt5047_hp_automic(codec);
1273                 break;
1274         }
1275 }
1276
1277 static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1278         HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1279         HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1280         HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1281         HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1282         HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1283         HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1284         HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1285         {
1286                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1287                 .name = "Master Playback Switch",
1288                 .info = cxt_eapd_info,
1289                 .get = cxt_eapd_get,
1290                 .put = cxt5047_hp_master_sw_put,
1291                 .private_value = 0x13,
1292         },
1293
1294         {}
1295 };
1296
1297 static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1298         /* See the note in cxt5047_hp_master_sw_put */
1299         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1300         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1301         {}
1302 };
1303
1304 static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1305         HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1306         { } /* end */
1307 };
1308
1309 static const struct hda_verb cxt5047_init_verbs[] = {
1310         /* Line in, Mic, Built-in Mic */
1311         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1312         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1313         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1314         /* HP, Speaker  */
1315         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1316         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1317         {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1318         /* Record selector: Mic */
1319         {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1320         {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1321          AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1322         {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1323         {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1324          AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1325         {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1326          AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1327         /* SPDIF route: PCM */
1328         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1329         /* Enable unsolicited events */
1330         {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1331         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1332         { } /* end */
1333 };
1334
1335 /* configuration for Toshiba Laptops */
1336 static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
1337         {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1338         {}
1339 };
1340
1341 /* Test configuration for debugging, modelled after the ALC260 test
1342  * configuration.
1343  */
1344 #ifdef CONFIG_SND_DEBUG
1345 static const struct hda_input_mux cxt5047_test_capture_source = {
1346         .num_items = 4,
1347         .items = {
1348                 { "LINE1 pin", 0x0 },
1349                 { "MIC1 pin", 0x1 },
1350                 { "MIC2 pin", 0x2 },
1351                 { "CD pin", 0x3 },
1352         },
1353 };
1354
1355 static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1356
1357         /* Output only controls */
1358         HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1359         HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1360         HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1361         HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1362         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1363         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1364         HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1365         HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1366         HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1367         HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1368         HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1369         HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1370
1371         /* Modes for retasking pin widgets */
1372         CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1373         CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1374
1375         /* EAPD Switch Control */
1376         CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1377
1378         /* Loopback mixer controls */
1379         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1380         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1381         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1382         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1383         HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1384         HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1385         HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1386         HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1387
1388         HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1389         HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1390         HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1391         HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1392         HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1393         HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1394         HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1395         HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1396         {
1397                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1398                 .name = "Input Source",
1399                 .info = conexant_mux_enum_info,
1400                 .get = conexant_mux_enum_get,
1401                 .put = conexant_mux_enum_put,
1402         },
1403         HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1404
1405         { } /* end */
1406 };
1407
1408 static const struct hda_verb cxt5047_test_init_verbs[] = {
1409         /* Enable retasking pins as output, initially without power amp */
1410         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1411         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1412         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1413
1414         /* Disable digital (SPDIF) pins initially, but users can enable
1415          * them via a mixer switch.  In the case of SPDIF-out, this initverb
1416          * payload also sets the generation to 0, output to be in "consumer"
1417          * PCM format, copyright asserted, no pre-emphasis and no validity
1418          * control.
1419          */
1420         {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1421
1422         /* Ensure mic1, mic2, line1 pin widgets take input from the 
1423          * OUT1 sum bus when acting as an output.
1424          */
1425         {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1426         {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1427
1428         /* Start with output sum widgets muted and their output gains at min */
1429         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1430         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1431
1432         /* Unmute retasking pin widget output buffers since the default
1433          * state appears to be output.  As the pin mode is changed by the
1434          * user the pin mode control will take care of enabling the pin's
1435          * input/output buffers as needed.
1436          */
1437         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1438         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1439         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1440
1441         /* Mute capture amp left and right */
1442         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1443
1444         /* Set ADC connection select to match default mixer setting (mic1
1445          * pin)
1446          */
1447         {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1448
1449         /* Mute all inputs to mixer widget (even unconnected ones) */
1450         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1451         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1452         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1453         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1454         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1455         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1456         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1457         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1458
1459         { }
1460 };
1461 #endif
1462
1463
1464 /* initialize jack-sensing, too */
1465 static int cxt5047_hp_init(struct hda_codec *codec)
1466 {
1467         conexant_init(codec);
1468         cxt5047_hp_automute(codec);
1469         return 0;
1470 }
1471
1472
1473 enum {
1474         CXT5047_LAPTOP,         /* Laptops w/o EAPD support */
1475         CXT5047_LAPTOP_HP,      /* Some HP laptops */
1476         CXT5047_LAPTOP_EAPD,    /* Laptops with EAPD support */
1477 #ifdef CONFIG_SND_DEBUG
1478         CXT5047_TEST,
1479 #endif
1480         CXT5047_AUTO,
1481         CXT5047_MODELS
1482 };
1483
1484 static const char * const cxt5047_models[CXT5047_MODELS] = {
1485         [CXT5047_LAPTOP]        = "laptop",
1486         [CXT5047_LAPTOP_HP]     = "laptop-hp",
1487         [CXT5047_LAPTOP_EAPD]   = "laptop-eapd",
1488 #ifdef CONFIG_SND_DEBUG
1489         [CXT5047_TEST]          = "test",
1490 #endif
1491         [CXT5047_AUTO]          = "auto",
1492 };
1493
1494 static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1495         SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1496         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1497                            CXT5047_LAPTOP),
1498         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1499         {}
1500 };
1501
1502 static int patch_cxt5047(struct hda_codec *codec)
1503 {
1504         struct conexant_spec *spec;
1505         int board_config;
1506
1507         board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1508                                                   cxt5047_models,
1509                                                   cxt5047_cfg_tbl);
1510         if (board_config < 0)
1511                 board_config = CXT5047_AUTO; /* model=auto as default */
1512         if (board_config == CXT5047_AUTO)
1513                 return patch_conexant_auto(codec);
1514
1515         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1516         if (!spec)
1517                 return -ENOMEM;
1518         codec->spec = spec;
1519         codec->pin_amp_workaround = 1;
1520
1521         spec->multiout.max_channels = 2;
1522         spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1523         spec->multiout.dac_nids = cxt5047_dac_nids;
1524         spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1525         spec->num_adc_nids = 1;
1526         spec->adc_nids = cxt5047_adc_nids;
1527         spec->capsrc_nids = cxt5047_capsrc_nids;
1528         spec->num_mixers = 1;
1529         spec->mixers[0] = cxt5047_base_mixers;
1530         spec->num_init_verbs = 1;
1531         spec->init_verbs[0] = cxt5047_init_verbs;
1532         spec->spdif_route = 0;
1533         spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1534         spec->channel_mode = cxt5047_modes,
1535
1536         codec->patch_ops = conexant_patch_ops;
1537
1538         switch (board_config) {
1539         case CXT5047_LAPTOP:
1540                 spec->num_mixers = 2;
1541                 spec->mixers[1] = cxt5047_hp_spk_mixers;
1542                 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1543                 break;
1544         case CXT5047_LAPTOP_HP:
1545                 spec->num_mixers = 2;
1546                 spec->mixers[1] = cxt5047_hp_only_mixers;
1547                 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1548                 codec->patch_ops.init = cxt5047_hp_init;
1549                 break;
1550         case CXT5047_LAPTOP_EAPD:
1551                 spec->input_mux = &cxt5047_toshiba_capture_source;
1552                 spec->num_mixers = 2;
1553                 spec->mixers[1] = cxt5047_hp_spk_mixers;
1554                 spec->num_init_verbs = 2;
1555                 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1556                 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1557                 break;
1558 #ifdef CONFIG_SND_DEBUG
1559         case CXT5047_TEST:
1560                 spec->input_mux = &cxt5047_test_capture_source;
1561                 spec->mixers[0] = cxt5047_test_mixer;
1562                 spec->init_verbs[0] = cxt5047_test_init_verbs;
1563                 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1564 #endif  
1565         }
1566         spec->vmaster_nid = 0x13;
1567
1568         switch (codec->subsystem_id >> 16) {
1569         case 0x103c:
1570                 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1571                  * Fix max PCM level to 0 dB (originally it has 0x1e steps
1572                  * with 0 dB offset 0x17)
1573                  */
1574                 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1575                                           (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1576                                           (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1577                                           (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1578                                           (1 << AC_AMPCAP_MUTE_SHIFT));
1579                 break;
1580         }
1581
1582         return 0;
1583 }
1584
1585 /* Conexant 5051 specific */
1586 static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1587 static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1588
1589 static const struct hda_channel_mode cxt5051_modes[1] = {
1590         { 2, NULL },
1591 };
1592
1593 static void cxt5051_update_speaker(struct hda_codec *codec)
1594 {
1595         struct conexant_spec *spec = codec->spec;
1596         unsigned int pinctl;
1597         /* headphone pin */
1598         pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1599         snd_hda_set_pin_ctl(codec, 0x16, pinctl);
1600         /* speaker pin */
1601         pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1602         snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
1603         /* on ideapad there is an additional speaker (subwoofer) to mute */
1604         if (spec->ideapad)
1605                 snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
1606 }
1607
1608 /* turn on/off EAPD (+ mute HP) as a master switch */
1609 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1610                                     struct snd_ctl_elem_value *ucontrol)
1611 {
1612         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1613
1614         if (!cxt_eapd_put(kcontrol, ucontrol))
1615                 return 0;
1616         cxt5051_update_speaker(codec);
1617         return 1;
1618 }
1619
1620 /* toggle input of built-in and mic jack appropriately */
1621 static void cxt5051_portb_automic(struct hda_codec *codec)
1622 {
1623         struct conexant_spec *spec = codec->spec;
1624         unsigned int present;
1625
1626         if (!(spec->auto_mic & AUTO_MIC_PORTB))
1627                 return;
1628         present = snd_hda_jack_detect(codec, 0x17);
1629         snd_hda_codec_write(codec, 0x14, 0,
1630                             AC_VERB_SET_CONNECT_SEL,
1631                             present ? 0x01 : 0x00);
1632 }
1633
1634 /* switch the current ADC according to the jack state */
1635 static void cxt5051_portc_automic(struct hda_codec *codec)
1636 {
1637         struct conexant_spec *spec = codec->spec;
1638         unsigned int present;
1639         hda_nid_t new_adc;
1640
1641         if (!(spec->auto_mic & AUTO_MIC_PORTC))
1642                 return;
1643         present = snd_hda_jack_detect(codec, 0x18);
1644         if (present)
1645                 spec->cur_adc_idx = 1;
1646         else
1647                 spec->cur_adc_idx = 0;
1648         new_adc = spec->adc_nids[spec->cur_adc_idx];
1649         if (spec->cur_adc && spec->cur_adc != new_adc) {
1650                 /* stream is running, let's swap the current ADC */
1651                 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1652                 spec->cur_adc = new_adc;
1653                 snd_hda_codec_setup_stream(codec, new_adc,
1654                                            spec->cur_adc_stream_tag, 0,
1655                                            spec->cur_adc_format);
1656         }
1657 }
1658
1659 /* mute internal speaker if HP is plugged */
1660 static void cxt5051_hp_automute(struct hda_codec *codec)
1661 {
1662         struct conexant_spec *spec = codec->spec;
1663
1664         spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1665         cxt5051_update_speaker(codec);
1666 }
1667
1668 /* unsolicited event for HP jack sensing */
1669 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1670                                    unsigned int res)
1671 {
1672         switch (res >> 26) {
1673         case CONEXANT_HP_EVENT:
1674                 cxt5051_hp_automute(codec);
1675                 break;
1676         case CXT5051_PORTB_EVENT:
1677                 cxt5051_portb_automic(codec);
1678                 break;
1679         case CXT5051_PORTC_EVENT:
1680                 cxt5051_portc_automic(codec);
1681                 break;
1682         }
1683 }
1684
1685 static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1686         HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1687         {
1688                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1689                 .name = "Master Playback Switch",
1690                 .info = cxt_eapd_info,
1691                 .get = cxt_eapd_get,
1692                 .put = cxt5051_hp_master_sw_put,
1693                 .private_value = 0x1a,
1694         },
1695         {}
1696 };
1697
1698 static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1699         HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1700         HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1701         HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1702         HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1703         HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
1704         HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
1705         {}
1706 };
1707
1708 static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1709         HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1710         HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1711         HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1712         HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1713         {}
1714 };
1715
1716 static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1717         HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1718         HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
1719         {}
1720 };
1721
1722 static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
1723         HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1724         HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1725         {}
1726 };
1727
1728 static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1729         HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1730         HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1731         HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1732         HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1733         {}
1734 };
1735
1736 static const struct hda_verb cxt5051_init_verbs[] = {
1737         /* Line in, Mic */
1738         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1739         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1740         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1741         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1742         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1743         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1744         /* SPK  */
1745         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1746         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1747         /* HP, Amp  */
1748         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1749         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1750         /* DAC1 */      
1751         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1752         /* Record selector: Internal mic */
1753         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1754         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1755         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1756         /* SPDIF route: PCM */
1757         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1758         {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1759         /* EAPD */
1760         {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 
1761         {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1762         { } /* end */
1763 };
1764
1765 static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1766         /* Line in, Mic */
1767         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1768         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1769         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1770         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1771         /* SPK  */
1772         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1773         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1774         /* HP, Amp  */
1775         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1776         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1777         /* DAC1 */
1778         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1779         /* Record selector: Internal mic */
1780         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1781         {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1782         /* SPDIF route: PCM */
1783         {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1784         /* EAPD */
1785         {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1786         {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1787         { } /* end */
1788 };
1789
1790 static const struct hda_verb cxt5051_f700_init_verbs[] = {
1791         /* Line in, Mic */
1792         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1793         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1794         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1795         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1796         /* SPK  */
1797         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1798         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1799         /* HP, Amp  */
1800         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1801         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1802         /* DAC1 */
1803         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1804         /* Record selector: Internal mic */
1805         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1806         {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1807         /* SPDIF route: PCM */
1808         {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1809         /* EAPD */
1810         {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1811         {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1812         { } /* end */
1813 };
1814
1815 static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1816                                  unsigned int event)
1817 {
1818         snd_hda_codec_write(codec, nid, 0,
1819                             AC_VERB_SET_UNSOLICITED_ENABLE,
1820                             AC_USRSP_EN | event);
1821 }
1822
1823 static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1824         /* Subwoofer */
1825         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1826         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1827         { } /* end */
1828 };
1829
1830 /* initialize jack-sensing, too */
1831 static int cxt5051_init(struct hda_codec *codec)
1832 {
1833         struct conexant_spec *spec = codec->spec;
1834
1835         conexant_init(codec);
1836
1837         if (spec->auto_mic & AUTO_MIC_PORTB)
1838                 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1839         if (spec->auto_mic & AUTO_MIC_PORTC)
1840                 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1841
1842         if (codec->patch_ops.unsol_event) {
1843                 cxt5051_hp_automute(codec);
1844                 cxt5051_portb_automic(codec);
1845                 cxt5051_portc_automic(codec);
1846         }
1847         return 0;
1848 }
1849
1850
1851 enum {
1852         CXT5051_LAPTOP,  /* Laptops w/ EAPD support */
1853         CXT5051_HP,     /* no docking */
1854         CXT5051_HP_DV6736,      /* HP without mic switch */
1855         CXT5051_F700,       /* HP Compaq Presario F700 */
1856         CXT5051_TOSHIBA,        /* Toshiba M300 & co */
1857         CXT5051_IDEAPAD,        /* Lenovo IdeaPad Y430 */
1858         CXT5051_AUTO,           /* auto-parser */
1859         CXT5051_MODELS
1860 };
1861
1862 static const char *const cxt5051_models[CXT5051_MODELS] = {
1863         [CXT5051_LAPTOP]        = "laptop",
1864         [CXT5051_HP]            = "hp",
1865         [CXT5051_HP_DV6736]     = "hp-dv6736",
1866         [CXT5051_F700]          = "hp-700",
1867         [CXT5051_TOSHIBA]       = "toshiba",
1868         [CXT5051_IDEAPAD]       = "ideapad",
1869         [CXT5051_AUTO]          = "auto",
1870 };
1871
1872 static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1873         SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1874         SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1875         SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1876         SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1877         SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1878                       CXT5051_LAPTOP),
1879         SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1880         SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1881         {}
1882 };
1883
1884 static int patch_cxt5051(struct hda_codec *codec)
1885 {
1886         struct conexant_spec *spec;
1887         int board_config;
1888
1889         board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1890                                                   cxt5051_models,
1891                                                   cxt5051_cfg_tbl);
1892         if (board_config < 0)
1893                 board_config = CXT5051_AUTO; /* model=auto as default */
1894         if (board_config == CXT5051_AUTO)
1895                 return patch_conexant_auto(codec);
1896
1897         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1898         if (!spec)
1899                 return -ENOMEM;
1900         codec->spec = spec;
1901         codec->pin_amp_workaround = 1;
1902
1903         codec->patch_ops = conexant_patch_ops;
1904         codec->patch_ops.init = cxt5051_init;
1905
1906         spec->multiout.max_channels = 2;
1907         spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1908         spec->multiout.dac_nids = cxt5051_dac_nids;
1909         spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1910         spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1911         spec->adc_nids = cxt5051_adc_nids;
1912         spec->num_mixers = 2;
1913         spec->mixers[0] = cxt5051_capture_mixers;
1914         spec->mixers[1] = cxt5051_playback_mixers;
1915         spec->num_init_verbs = 1;
1916         spec->init_verbs[0] = cxt5051_init_verbs;
1917         spec->spdif_route = 0;
1918         spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1919         spec->channel_mode = cxt5051_modes;
1920         spec->cur_adc = 0;
1921         spec->cur_adc_idx = 0;
1922
1923         set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1924
1925         codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1926
1927         spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
1928         switch (board_config) {
1929         case CXT5051_HP:
1930                 spec->mixers[0] = cxt5051_hp_mixers;
1931                 break;
1932         case CXT5051_HP_DV6736:
1933                 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1934                 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1935                 spec->auto_mic = 0;
1936                 break;
1937         case CXT5051_F700:
1938                 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1939                 spec->mixers[0] = cxt5051_f700_mixers;
1940                 spec->auto_mic = 0;
1941                 break;
1942         case CXT5051_TOSHIBA:
1943                 spec->mixers[0] = cxt5051_toshiba_mixers;
1944                 spec->auto_mic = AUTO_MIC_PORTB;
1945                 break;
1946         case CXT5051_IDEAPAD:
1947                 spec->init_verbs[spec->num_init_verbs++] =
1948                         cxt5051_ideapad_init_verbs;
1949                 spec->ideapad = 1;
1950                 break;
1951         }
1952
1953         if (spec->beep_amp)
1954                 snd_hda_attach_beep_device(codec, spec->beep_amp);
1955
1956         return 0;
1957 }
1958
1959 /* Conexant 5066 specific */
1960
1961 static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1962 static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1963 static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1964 static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
1965
1966 /* OLPC's microphone port is DC coupled for use with external sensors,
1967  * therefore we use a 50% mic bias in order to center the input signal with
1968  * the DC input range of the codec. */
1969 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1970
1971 static const struct hda_channel_mode cxt5066_modes[1] = {
1972         { 2, NULL },
1973 };
1974
1975 #define HP_PRESENT_PORT_A       (1 << 0)
1976 #define HP_PRESENT_PORT_D       (1 << 1)
1977 #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
1978 #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
1979
1980 static void cxt5066_update_speaker(struct hda_codec *codec)
1981 {
1982         struct conexant_spec *spec = codec->spec;
1983         unsigned int pinctl;
1984
1985         snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
1986                     spec->hp_present, spec->cur_eapd);
1987
1988         /* Port A (HP) */
1989         pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
1990         snd_hda_set_pin_ctl(codec, 0x19, pinctl);
1991
1992         /* Port D (HP/LO) */
1993         pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
1994         if (spec->dell_automute || spec->thinkpad) {
1995                 /* Mute if Port A is connected */
1996                 if (hp_port_a_present(spec))
1997                         pinctl = 0;
1998         } else {
1999                 /* Thinkpad/Dell doesn't give pin-D status */
2000                 if (!hp_port_d_present(spec))
2001                         pinctl = 0;
2002         }
2003         snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
2004
2005         /* CLASS_D AMP */
2006         pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2007         snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
2008 }
2009
2010 /* turn on/off EAPD (+ mute HP) as a master switch */
2011 static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2012                                     struct snd_ctl_elem_value *ucontrol)
2013 {
2014         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2015
2016         if (!cxt_eapd_put(kcontrol, ucontrol))
2017                 return 0;
2018
2019         cxt5066_update_speaker(codec);
2020         return 1;
2021 }
2022
2023 static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2024         .num_items = 3,
2025         .items = {
2026                 { "Off", PIN_IN },
2027                 { "50%", PIN_VREF50 },
2028                 { "80%", PIN_VREF80 },
2029         },
2030 };
2031
2032 static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2033 {
2034         struct conexant_spec *spec = codec->spec;
2035         /* Even though port F is the DC input, the bias is controlled on port B.
2036          * we also leave that port as an active input (but unselected) in DC mode
2037          * just in case that is necessary to make the bias setting take effect. */
2038         return snd_hda_set_pin_ctl_cache(codec, 0x1a,
2039                 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2040 }
2041
2042 /* OLPC defers mic widget control until when capture is started because the
2043  * microphone LED comes on as soon as these settings are put in place. if we
2044  * did this before recording, it would give the false indication that recording
2045  * is happening when it is not. */
2046 static void cxt5066_olpc_select_mic(struct hda_codec *codec)
2047 {
2048         struct conexant_spec *spec = codec->spec;
2049         if (!spec->recording)
2050                 return;
2051
2052         if (spec->dc_enable) {
2053                 /* in DC mode we ignore presence detection and just use the jack
2054                  * through our special DC port */
2055                 const struct hda_verb enable_dc_mode[] = {
2056                         /* disble internal mic, port C */
2057                         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2058
2059                         /* enable DC capture, port F */
2060                         {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2061                         {},
2062                 };
2063
2064                 snd_hda_sequence_write(codec, enable_dc_mode);
2065                 /* port B input disabled (and bias set) through the following call */
2066                 cxt5066_set_olpc_dc_bias(codec);
2067                 return;
2068         }
2069
2070         /* disable DC (port F) */
2071         snd_hda_set_pin_ctl(codec, 0x1e, 0);
2072
2073         /* external mic, port B */
2074         snd_hda_set_pin_ctl(codec, 0x1a,
2075                 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
2076
2077         /* internal mic, port C */
2078         snd_hda_set_pin_ctl(codec, 0x1b,
2079                 spec->ext_mic_present ? 0 : PIN_VREF80);
2080 }
2081
2082 /* toggle input of built-in and mic jack appropriately */
2083 static void cxt5066_olpc_automic(struct hda_codec *codec)
2084 {
2085         struct conexant_spec *spec = codec->spec;
2086         unsigned int present;
2087
2088         if (spec->dc_enable) /* don't do presence detection in DC mode */
2089                 return;
2090
2091         present = snd_hda_codec_read(codec, 0x1a, 0,
2092                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2093         if (present)
2094                 snd_printdd("CXT5066: external microphone detected\n");
2095         else
2096                 snd_printdd("CXT5066: external microphone absent\n");
2097
2098         snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2099                 present ? 0 : 1);
2100         spec->ext_mic_present = !!present;
2101
2102         cxt5066_olpc_select_mic(codec);
2103 }
2104
2105 /* toggle input of built-in digital mic and mic jack appropriately */
2106 static void cxt5066_vostro_automic(struct hda_codec *codec)
2107 {
2108         unsigned int present;
2109
2110         struct hda_verb ext_mic_present[] = {
2111                 /* enable external mic, port B */
2112                 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2113
2114                 /* switch to external mic input */
2115                 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2116                 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2117
2118                 /* disable internal digital mic */
2119                 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2120                 {}
2121         };
2122         static const struct hda_verb ext_mic_absent[] = {
2123                 /* enable internal mic, port C */
2124                 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2125
2126                 /* switch to internal mic input */
2127                 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2128
2129                 /* disable external mic, port B */
2130                 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2131                 {}
2132         };
2133
2134         present = snd_hda_jack_detect(codec, 0x1a);
2135         if (present) {
2136                 snd_printdd("CXT5066: external microphone detected\n");
2137                 snd_hda_sequence_write(codec, ext_mic_present);
2138         } else {
2139                 snd_printdd("CXT5066: external microphone absent\n");
2140                 snd_hda_sequence_write(codec, ext_mic_absent);
2141         }
2142 }
2143
2144 /* toggle input of built-in digital mic and mic jack appropriately */
2145 static void cxt5066_ideapad_automic(struct hda_codec *codec)
2146 {
2147         unsigned int present;
2148
2149         struct hda_verb ext_mic_present[] = {
2150                 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2151                 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2152                 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2153                 {}
2154         };
2155         static const struct hda_verb ext_mic_absent[] = {
2156                 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2157                 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2158                 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2159                 {}
2160         };
2161
2162         present = snd_hda_jack_detect(codec, 0x1b);
2163         if (present) {
2164                 snd_printdd("CXT5066: external microphone detected\n");
2165                 snd_hda_sequence_write(codec, ext_mic_present);
2166         } else {
2167                 snd_printdd("CXT5066: external microphone absent\n");
2168                 snd_hda_sequence_write(codec, ext_mic_absent);
2169         }
2170 }
2171
2172
2173 /* toggle input of built-in digital mic and mic jack appropriately */
2174 static void cxt5066_asus_automic(struct hda_codec *codec)
2175 {
2176         unsigned int present;
2177
2178         present = snd_hda_jack_detect(codec, 0x1b);
2179         snd_printdd("CXT5066: external microphone present=%d\n", present);
2180         snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2181                             present ? 1 : 0);
2182 }
2183
2184
2185 /* toggle input of built-in digital mic and mic jack appropriately */
2186 static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2187 {
2188         unsigned int present;
2189
2190         present = snd_hda_jack_detect(codec, 0x1b);
2191         snd_printdd("CXT5066: external microphone present=%d\n", present);
2192         snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2193                             present ? 1 : 3);
2194 }
2195
2196
2197 /* toggle input of built-in digital mic and mic jack appropriately
2198    order is: external mic -> dock mic -> interal mic */
2199 static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2200 {
2201         unsigned int ext_present, dock_present;
2202
2203         static const struct hda_verb ext_mic_present[] = {
2204                 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2205                 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2206                 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2207                 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2208                 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2209                 {}
2210         };
2211         static const struct hda_verb dock_mic_present[] = {
2212                 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2213                 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2214                 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2215                 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2216                 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2217                 {}
2218         };
2219         static const struct hda_verb ext_mic_absent[] = {
2220                 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2221                 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2222                 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2223                 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2224                 {}
2225         };
2226
2227         ext_present = snd_hda_jack_detect(codec, 0x1b);
2228         dock_present = snd_hda_jack_detect(codec, 0x1a);
2229         if (ext_present) {
2230                 snd_printdd("CXT5066: external microphone detected\n");
2231                 snd_hda_sequence_write(codec, ext_mic_present);
2232         } else if (dock_present) {
2233                 snd_printdd("CXT5066: dock microphone detected\n");
2234                 snd_hda_sequence_write(codec, dock_mic_present);
2235         } else {
2236                 snd_printdd("CXT5066: external microphone absent\n");
2237                 snd_hda_sequence_write(codec, ext_mic_absent);
2238         }
2239 }
2240
2241 /* mute internal speaker if HP is plugged */
2242 static void cxt5066_hp_automute(struct hda_codec *codec)
2243 {
2244         struct conexant_spec *spec = codec->spec;
2245         unsigned int portA, portD;
2246
2247         /* Port A */
2248         portA = snd_hda_jack_detect(codec, 0x19);
2249
2250         /* Port D */
2251         portD = snd_hda_jack_detect(codec, 0x1c);
2252
2253         spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2254         spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
2255         snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2256                 portA, portD, spec->hp_present);
2257         cxt5066_update_speaker(codec);
2258 }
2259
2260 /* Dispatch the right mic autoswitch function */
2261 static void cxt5066_automic(struct hda_codec *codec)
2262 {
2263         struct conexant_spec *spec = codec->spec;
2264
2265         if (spec->dell_vostro)
2266                 cxt5066_vostro_automic(codec);
2267         else if (spec->ideapad)
2268                 cxt5066_ideapad_automic(codec);
2269         else if (spec->thinkpad)
2270                 cxt5066_thinkpad_automic(codec);
2271         else if (spec->hp_laptop)
2272                 cxt5066_hp_laptop_automic(codec);
2273         else if (spec->asus)
2274                 cxt5066_asus_automic(codec);
2275 }
2276
2277 /* unsolicited event for jack sensing */
2278 static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
2279 {
2280         struct conexant_spec *spec = codec->spec;
2281         snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2282         switch (res >> 26) {
2283         case CONEXANT_HP_EVENT:
2284                 cxt5066_hp_automute(codec);
2285                 break;
2286         case CONEXANT_MIC_EVENT:
2287                 /* ignore mic events in DC mode; we're always using the jack */
2288                 if (!spec->dc_enable)
2289                         cxt5066_olpc_automic(codec);
2290                 break;
2291         }
2292 }
2293
2294 /* unsolicited event for jack sensing */
2295 static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2296 {
2297         snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2298         switch (res >> 26) {
2299         case CONEXANT_HP_EVENT:
2300                 cxt5066_hp_automute(codec);
2301                 break;
2302         case CONEXANT_MIC_EVENT:
2303                 cxt5066_automic(codec);
2304                 break;
2305         }
2306 }
2307
2308
2309 static const struct hda_input_mux cxt5066_analog_mic_boost = {
2310         .num_items = 5,
2311         .items = {
2312                 { "0dB",  0 },
2313                 { "10dB", 1 },
2314                 { "20dB", 2 },
2315                 { "30dB", 3 },
2316                 { "40dB", 4 },
2317         },
2318 };
2319
2320 static void cxt5066_set_mic_boost(struct hda_codec *codec)
2321 {
2322         struct conexant_spec *spec = codec->spec;
2323         snd_hda_codec_write_cache(codec, 0x17, 0,
2324                 AC_VERB_SET_AMP_GAIN_MUTE,
2325                 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2326                         cxt5066_analog_mic_boost.items[spec->mic_boost].index);
2327         if (spec->ideapad || spec->thinkpad) {
2328                 /* adjust the internal mic as well...it is not through 0x17 */
2329                 snd_hda_codec_write_cache(codec, 0x23, 0,
2330                         AC_VERB_SET_AMP_GAIN_MUTE,
2331                         AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2332                                 cxt5066_analog_mic_boost.
2333                                         items[spec->mic_boost].index);
2334         }
2335 }
2336
2337 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2338                                            struct snd_ctl_elem_info *uinfo)
2339 {
2340         return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2341 }
2342
2343 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2344                                           struct snd_ctl_elem_value *ucontrol)
2345 {
2346         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2347         struct conexant_spec *spec = codec->spec;
2348         ucontrol->value.enumerated.item[0] = spec->mic_boost;
2349         return 0;
2350 }
2351
2352 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2353                                           struct snd_ctl_elem_value *ucontrol)
2354 {
2355         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2356         struct conexant_spec *spec = codec->spec;
2357         const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2358         unsigned int idx;
2359         idx = ucontrol->value.enumerated.item[0];
2360         if (idx >= imux->num_items)
2361                 idx = imux->num_items - 1;
2362
2363         spec->mic_boost = idx;
2364         if (!spec->dc_enable)
2365                 cxt5066_set_mic_boost(codec);
2366         return 1;
2367 }
2368
2369 static void cxt5066_enable_dc(struct hda_codec *codec)
2370 {
2371         const struct hda_verb enable_dc_mode[] = {
2372                 /* disable gain */
2373                 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2374
2375                 /* switch to DC input */
2376                 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2377                 {}
2378         };
2379
2380         /* configure as input source */
2381         snd_hda_sequence_write(codec, enable_dc_mode);
2382         cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2383 }
2384
2385 static void cxt5066_disable_dc(struct hda_codec *codec)
2386 {
2387         /* reconfigure input source */
2388         cxt5066_set_mic_boost(codec);
2389         /* automic also selects the right mic if we're recording */
2390         cxt5066_olpc_automic(codec);
2391 }
2392
2393 static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2394                              struct snd_ctl_elem_value *ucontrol)
2395 {
2396         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2397         struct conexant_spec *spec = codec->spec;
2398         ucontrol->value.integer.value[0] = spec->dc_enable;
2399         return 0;
2400 }
2401
2402 static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2403                              struct snd_ctl_elem_value *ucontrol)
2404 {
2405         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2406         struct conexant_spec *spec = codec->spec;
2407         int dc_enable = !!ucontrol->value.integer.value[0];
2408
2409         if (dc_enable == spec->dc_enable)
2410                 return 0;
2411
2412         spec->dc_enable = dc_enable;
2413         if (dc_enable)
2414                 cxt5066_enable_dc(codec);
2415         else
2416                 cxt5066_disable_dc(codec);
2417
2418         return 1;
2419 }
2420
2421 static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2422                                            struct snd_ctl_elem_info *uinfo)
2423 {
2424         return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2425 }
2426
2427 static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2428                                           struct snd_ctl_elem_value *ucontrol)
2429 {
2430         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2431         struct conexant_spec *spec = codec->spec;
2432         ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2433         return 0;
2434 }
2435
2436 static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2437                                           struct snd_ctl_elem_value *ucontrol)
2438 {
2439         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2440         struct conexant_spec *spec = codec->spec;
2441         const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2442         unsigned int idx;
2443
2444         idx = ucontrol->value.enumerated.item[0];
2445         if (idx >= imux->num_items)
2446                 idx = imux->num_items - 1;
2447
2448         spec->dc_input_bias = idx;
2449         if (spec->dc_enable)
2450                 cxt5066_set_olpc_dc_bias(codec);
2451         return 1;
2452 }
2453
2454 static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2455 {
2456         struct conexant_spec *spec = codec->spec;
2457         /* mark as recording and configure the microphone widget so that the
2458          * recording LED comes on. */
2459         spec->recording = 1;
2460         cxt5066_olpc_select_mic(codec);
2461 }
2462
2463 static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2464 {
2465         struct conexant_spec *spec = codec->spec;
2466         const struct hda_verb disable_mics[] = {
2467                 /* disable external mic, port B */
2468                 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2469
2470                 /* disble internal mic, port C */
2471                 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2472
2473                 /* disable DC capture, port F */
2474                 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2475                 {},
2476         };
2477
2478         snd_hda_sequence_write(codec, disable_mics);
2479         spec->recording = 0;
2480 }
2481
2482 static void conexant_check_dig_outs(struct hda_codec *codec,
2483                                     const hda_nid_t *dig_pins,
2484                                     int num_pins)
2485 {
2486         struct conexant_spec *spec = codec->spec;
2487         hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2488         int i;
2489
2490         for (i = 0; i < num_pins; i++, dig_pins++) {
2491                 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2492                 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2493                         continue;
2494                 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2495                         continue;
2496                 if (spec->slave_dig_outs[0])
2497                         nid_loc++;
2498                 else
2499                         nid_loc = spec->slave_dig_outs;
2500         }
2501 }
2502
2503 static const struct hda_input_mux cxt5066_capture_source = {
2504         .num_items = 4,
2505         .items = {
2506                 { "Mic B", 0 },
2507                 { "Mic C", 1 },
2508                 { "Mic E", 2 },
2509                 { "Mic F", 3 },
2510         },
2511 };
2512
2513 static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2514         .ops = &snd_hda_bind_vol,
2515         .values = {
2516                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2517                 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2518                 0
2519         },
2520 };
2521
2522 static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2523         .ops = &snd_hda_bind_sw,
2524         .values = {
2525                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2526                 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2527                 0
2528         },
2529 };
2530
2531 static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
2532         HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2533         {}
2534 };
2535
2536 static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2537         {
2538                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2539                 .name = "Master Playback Volume",
2540                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2541                                   SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2542                                   SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2543                 .subdevice = HDA_SUBDEV_AMP_FLAG,
2544                 .info = snd_hda_mixer_amp_volume_info,
2545                 .get = snd_hda_mixer_amp_volume_get,
2546                 .put = snd_hda_mixer_amp_volume_put,
2547                 .tlv = { .c = snd_hda_mixer_amp_tlv },
2548                 /* offset by 28 volume steps to limit minimum gain to -46dB */
2549                 .private_value =
2550                         HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2551         },
2552         {}
2553 };
2554
2555 static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2556         {
2557                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2558                 .name = "DC Mode Enable Switch",
2559                 .info = snd_ctl_boolean_mono_info,
2560                 .get = cxt5066_olpc_dc_get,
2561                 .put = cxt5066_olpc_dc_put,
2562         },
2563         {
2564                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2565                 .name = "DC Input Bias Enum",
2566                 .info = cxt5066_olpc_dc_bias_enum_info,
2567                 .get = cxt5066_olpc_dc_bias_enum_get,
2568                 .put = cxt5066_olpc_dc_bias_enum_put,
2569         },
2570         {}
2571 };
2572
2573 static const struct snd_kcontrol_new cxt5066_mixers[] = {
2574         {
2575                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2576                 .name = "Master Playback Switch",
2577                 .info = cxt_eapd_info,
2578                 .get = cxt_eapd_get,
2579                 .put = cxt5066_hp_master_sw_put,
2580                 .private_value = 0x1d,
2581         },
2582
2583         {
2584                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2585                 .name = "Analog Mic Boost Capture Enum",
2586                 .info = cxt5066_mic_boost_mux_enum_info,
2587                 .get = cxt5066_mic_boost_mux_enum_get,
2588                 .put = cxt5066_mic_boost_mux_enum_put,
2589         },
2590
2591         HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2592         HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2593         {}
2594 };
2595
2596 static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2597         {
2598                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2599                 .name = "Internal Mic Boost Capture Enum",
2600                 .info = cxt5066_mic_boost_mux_enum_info,
2601                 .get = cxt5066_mic_boost_mux_enum_get,
2602                 .put = cxt5066_mic_boost_mux_enum_put,
2603                 .private_value = 0x23 | 0x100,
2604         },
2605         {}
2606 };
2607
2608 static const struct hda_verb cxt5066_init_verbs[] = {
2609         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2610         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2611         {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2612         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2613
2614         /* Speakers  */
2615         {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2616         {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2617
2618         /* HP, Amp  */
2619         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2620         {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2621
2622         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2623         {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2624
2625         /* DAC1 */
2626         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2627
2628         /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2629         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2630         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2631         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2632         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2633         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2634
2635         /* no digital microphone support yet */
2636         {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2637
2638         /* Audio input selector */
2639         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2640
2641         /* SPDIF route: PCM */
2642         {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2643         {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2644
2645         {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2646         {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2647
2648         /* EAPD */
2649         {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2650
2651         /* not handling these yet */
2652         {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2653         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2654         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2655         {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2656         {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2657         {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2658         {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2659         {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2660         { } /* end */
2661 };
2662
2663 static const struct hda_verb cxt5066_init_verbs_olpc[] = {
2664         /* Port A: headphones */
2665         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2666         {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2667
2668         /* Port B: external microphone */
2669         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2670
2671         /* Port C: internal microphone */
2672         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2673
2674         /* Port D: unused */
2675         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2676
2677         /* Port E: unused, but has primary EAPD */
2678         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2679         {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2680
2681         /* Port F: external DC input through microphone port */
2682         {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2683
2684         /* Port G: internal speakers */
2685         {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2686         {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2687
2688         /* DAC1 */
2689         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2690
2691         /* DAC2: unused */
2692         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2693
2694         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2695         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2696         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2697         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2698         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2699         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2700         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2701         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2702         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2703         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2704         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2705         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2706
2707         /* Disable digital microphone port */
2708         {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2709
2710         /* Audio input selectors */
2711         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2712         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2713
2714         /* Disable SPDIF */
2715         {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2716         {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2717
2718         /* enable unsolicited events for Port A and B */
2719         {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2720         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2721         { } /* end */
2722 };
2723
2724 static const struct hda_verb cxt5066_init_verbs_vostro[] = {
2725         /* Port A: headphones */
2726         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2727         {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2728
2729         /* Port B: external microphone */
2730         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2731
2732         /* Port C: unused */
2733         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2734
2735         /* Port D: unused */
2736         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2737
2738         /* Port E: unused, but has primary EAPD */
2739         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2740         {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2741
2742         /* Port F: unused */
2743         {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2744
2745         /* Port G: internal speakers */
2746         {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2747         {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2748
2749         /* DAC1 */
2750         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2751
2752         /* DAC2: unused */
2753         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2754
2755         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2756         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2757         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2758         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2759         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2760         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2761         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2762         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2763         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2764         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2765         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2766         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2767
2768         /* Digital microphone port */
2769         {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2770
2771         /* Audio input selectors */
2772         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2773         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2774
2775         /* Disable SPDIF */
2776         {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2777         {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2778
2779         /* enable unsolicited events for Port A and B */
2780         {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2781         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2782         { } /* end */
2783 };
2784
2785 static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2786         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2787         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2788         {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2789         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2790
2791         /* Speakers  */
2792         {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2793         {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2794
2795         /* HP, Amp  */
2796         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2797         {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2798
2799         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2800         {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2801
2802         /* DAC1 */
2803         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2804
2805         /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2806         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2807         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2808         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2809         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2810         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2811         {0x14, AC_VERB_SET_CONNECT_SEL, 2},     /* default to internal mic */
2812
2813         /* Audio input selector */
2814         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2815         {0x17, AC_VERB_SET_CONNECT_SEL, 1},     /* route ext mic */
2816
2817         /* SPDIF route: PCM */
2818         {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2819         {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2820
2821         {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2822         {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2823
2824         /* internal microphone */
2825         {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2826
2827         /* EAPD */
2828         {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2829
2830         {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2831         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2832         { } /* end */
2833 };
2834
2835 static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2836         {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2837         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
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         /* Port A: HP, Amp  */
2844         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2845         {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2846
2847         /* Port B: Mic Dock */
2848         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2849
2850         /* Port C: Mic */
2851         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2852
2853         /* Port D: HP Dock, Amp */
2854         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2855         {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2856
2857         /* DAC1 */
2858         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2859
2860         /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2861         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2862         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2863         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2864         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2865         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2866         {0x14, AC_VERB_SET_CONNECT_SEL, 2},     /* default to internal mic */
2867
2868         /* Audio input selector */
2869         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2870         {0x17, AC_VERB_SET_CONNECT_SEL, 1},     /* route ext mic */
2871
2872         /* SPDIF route: PCM */
2873         {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2874         {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2875
2876         {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2877         {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2878
2879         /* internal microphone */
2880         {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2881
2882         /* EAPD */
2883         {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2884
2885         /* enable unsolicited events for Port A, B, C and D */
2886         {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2887         {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2888         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2889         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2890         { } /* end */
2891 };
2892
2893 static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2894         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2895         { } /* end */
2896 };
2897
2898
2899 static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
2900         {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2901         {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2902         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2903         { } /* end */
2904 };
2905
2906 /* initialize jack-sensing, too */
2907 static int cxt5066_init(struct hda_codec *codec)
2908 {
2909         snd_printdd("CXT5066: init\n");
2910         conexant_init(codec);
2911         if (codec->patch_ops.unsol_event) {
2912                 cxt5066_hp_automute(codec);
2913                 cxt5066_automic(codec);
2914         }
2915         cxt5066_set_mic_boost(codec);
2916         return 0;
2917 }
2918
2919 static int cxt5066_olpc_init(struct hda_codec *codec)
2920 {
2921         struct conexant_spec *spec = codec->spec;
2922         snd_printdd("CXT5066: init\n");
2923         conexant_init(codec);
2924         cxt5066_hp_automute(codec);
2925         if (!spec->dc_enable) {
2926                 cxt5066_set_mic_boost(codec);
2927                 cxt5066_olpc_automic(codec);
2928         } else {
2929                 cxt5066_enable_dc(codec);
2930         }
2931         return 0;
2932 }
2933
2934 enum {
2935         CXT5066_LAPTOP,         /* Laptops w/ EAPD support */
2936         CXT5066_DELL_LAPTOP,    /* Dell Laptop */
2937         CXT5066_OLPC_XO_1_5,    /* OLPC XO 1.5 */
2938         CXT5066_DELL_VOSTRO,    /* Dell Vostro 1015i */
2939         CXT5066_IDEAPAD,        /* Lenovo IdeaPad U150 */
2940         CXT5066_THINKPAD,       /* Lenovo ThinkPad T410s, others? */
2941         CXT5066_ASUS,           /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
2942         CXT5066_HP_LAPTOP,      /* HP Laptop */
2943         CXT5066_AUTO,           /* BIOS auto-parser */
2944         CXT5066_MODELS
2945 };
2946
2947 static const char * const cxt5066_models[CXT5066_MODELS] = {
2948         [CXT5066_LAPTOP]        = "laptop",
2949         [CXT5066_DELL_LAPTOP]   = "dell-laptop",
2950         [CXT5066_OLPC_XO_1_5]   = "olpc-xo-1_5",
2951         [CXT5066_DELL_VOSTRO]   = "dell-vostro",
2952         [CXT5066_IDEAPAD]       = "ideapad",
2953         [CXT5066_THINKPAD]      = "thinkpad",
2954         [CXT5066_ASUS]          = "asus",
2955         [CXT5066_HP_LAPTOP]     = "hp-laptop",
2956         [CXT5066_AUTO]          = "auto",
2957 };
2958
2959 static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2960         SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
2961         SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
2962         SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
2963         SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
2964         SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
2965         SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2966         SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
2967         SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
2968         SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
2969         SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
2970         SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
2971         SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
2972         SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
2973         SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2974                       CXT5066_LAPTOP),
2975         SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
2976         SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
2977         SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
2978         SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
2979         SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
2980         SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
2981         SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
2982         SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
2983         {}
2984 };
2985
2986 static int patch_cxt5066(struct hda_codec *codec)
2987 {
2988         struct conexant_spec *spec;
2989         int board_config;
2990
2991         board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2992                                                   cxt5066_models, cxt5066_cfg_tbl);
2993         if (board_config < 0)
2994                 board_config = CXT5066_AUTO; /* model=auto as default */
2995         if (board_config == CXT5066_AUTO)
2996                 return patch_conexant_auto(codec);
2997
2998         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2999         if (!spec)
3000                 return -ENOMEM;
3001         codec->spec = spec;
3002
3003         codec->patch_ops = conexant_patch_ops;
3004         codec->patch_ops.init = conexant_init;
3005
3006         spec->dell_automute = 0;
3007         spec->multiout.max_channels = 2;
3008         spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3009         spec->multiout.dac_nids = cxt5066_dac_nids;
3010         conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3011             ARRAY_SIZE(cxt5066_digout_pin_nids));
3012         spec->num_adc_nids = 1;
3013         spec->adc_nids = cxt5066_adc_nids;
3014         spec->capsrc_nids = cxt5066_capsrc_nids;
3015         spec->input_mux = &cxt5066_capture_source;
3016
3017         spec->port_d_mode = PIN_HP;
3018
3019         spec->num_init_verbs = 1;
3020         spec->init_verbs[0] = cxt5066_init_verbs;
3021         spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3022         spec->channel_mode = cxt5066_modes;
3023         spec->cur_adc = 0;
3024         spec->cur_adc_idx = 0;
3025
3026         set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3027
3028         switch (board_config) {
3029         default:
3030         case CXT5066_LAPTOP:
3031                 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3032                 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3033                 break;
3034         case CXT5066_DELL_LAPTOP:
3035                 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3036                 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3037
3038                 spec->port_d_mode = PIN_OUT;
3039                 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3040                 spec->num_init_verbs++;
3041                 spec->dell_automute = 1;
3042                 break;
3043         case CXT5066_ASUS:
3044         case CXT5066_HP_LAPTOP:
3045                 codec->patch_ops.init = cxt5066_init;
3046                 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3047                 spec->init_verbs[spec->num_init_verbs] =
3048                         cxt5066_init_verbs_hp_laptop;
3049                 spec->num_init_verbs++;
3050                 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3051                 spec->asus = board_config == CXT5066_ASUS;
3052                 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3053                 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3054                 /* no S/PDIF out */
3055                 if (board_config == CXT5066_HP_LAPTOP)
3056                         spec->multiout.dig_out_nid = 0;
3057                 /* input source automatically selected */
3058                 spec->input_mux = NULL;
3059                 spec->port_d_mode = 0;
3060                 spec->mic_boost = 3; /* default 30dB gain */
3061                 break;
3062
3063         case CXT5066_OLPC_XO_1_5:
3064                 codec->patch_ops.init = cxt5066_olpc_init;
3065                 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
3066                 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3067                 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3068                 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
3069                 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3070                 spec->port_d_mode = 0;
3071                 spec->mic_boost = 3; /* default 30dB gain */
3072
3073                 /* no S/PDIF out */
3074                 spec->multiout.dig_out_nid = 0;
3075
3076                 /* input source automatically selected */
3077                 spec->input_mux = NULL;
3078
3079                 /* our capture hooks which allow us to turn on the microphone LED
3080                  * at the right time */
3081                 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3082                 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
3083                 break;
3084         case CXT5066_DELL_VOSTRO:
3085                 codec->patch_ops.init = cxt5066_init;
3086                 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3087                 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3088                 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3089                 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3090                 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
3091                 spec->port_d_mode = 0;
3092                 spec->dell_vostro = 1;
3093                 spec->mic_boost = 3; /* default 30dB gain */
3094
3095                 /* no S/PDIF out */
3096                 spec->multiout.dig_out_nid = 0;
3097
3098                 /* input source automatically selected */
3099                 spec->input_mux = NULL;
3100                 break;
3101         case CXT5066_IDEAPAD:
3102                 codec->patch_ops.init = cxt5066_init;
3103                 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3104                 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3105                 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3106                 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3107                 spec->port_d_mode = 0;
3108                 spec->ideapad = 1;
3109                 spec->mic_boost = 2;    /* default 20dB gain */
3110
3111                 /* no S/PDIF out */
3112                 spec->multiout.dig_out_nid = 0;
3113
3114                 /* input source automatically selected */
3115                 spec->input_mux = NULL;
3116                 break;
3117         case CXT5066_THINKPAD:
3118                 codec->patch_ops.init = cxt5066_init;
3119                 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3120                 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3121                 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3122                 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3123                 spec->thinkpad = 1;
3124                 spec->port_d_mode = PIN_OUT;
3125                 spec->mic_boost = 2;    /* default 20dB gain */
3126
3127                 /* no S/PDIF out */
3128                 spec->multiout.dig_out_nid = 0;
3129
3130                 /* input source automatically selected */
3131                 spec->input_mux = NULL;
3132                 break;
3133         }
3134
3135         if (spec->beep_amp)
3136                 snd_hda_attach_beep_device(codec, spec->beep_amp);
3137
3138         return 0;
3139 }
3140
3141 /*
3142  * Automatic parser for CX20641 & co
3143  */
3144
3145 static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3146                                        struct hda_codec *codec,
3147                                        unsigned int stream_tag,
3148                                        unsigned int format,
3149                                        struct snd_pcm_substream *substream)
3150 {
3151         struct conexant_spec *spec = codec->spec;
3152         hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
3153         if (spec->adc_switching) {
3154                 spec->cur_adc = adc;
3155                 spec->cur_adc_stream_tag = stream_tag;
3156                 spec->cur_adc_format = format;
3157         }
3158         snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3159         return 0;
3160 }
3161
3162 static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3163                                        struct hda_codec *codec,
3164                                        struct snd_pcm_substream *substream)
3165 {
3166         struct conexant_spec *spec = codec->spec;
3167         snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3168         spec->cur_adc = 0;
3169         return 0;
3170 }
3171
3172 static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3173         .substreams = 1,
3174         .channels_min = 2,
3175         .channels_max = 2,
3176         .nid = 0, /* fill later */
3177         .ops = {
3178                 .prepare = cx_auto_capture_pcm_prepare,
3179                 .cleanup = cx_auto_capture_pcm_cleanup
3180         },
3181 };
3182
3183 static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3184
3185 #define get_connection_index(codec, mux, nid)\
3186         snd_hda_get_conn_index(codec, mux, nid, 0)
3187
3188 /* get an unassigned DAC from the given list.
3189  * Return the nid if found and reduce the DAC list, or return zero if
3190  * not found
3191  */
3192 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3193                                     hda_nid_t *dacs, int *num_dacs)
3194 {
3195         int i, nums = *num_dacs;
3196         hda_nid_t ret = 0;
3197
3198         for (i = 0; i < nums; i++) {
3199                 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3200                         ret = dacs[i];
3201                         break;
3202                 }
3203         }
3204         if (!ret)
3205                 return 0;
3206         if (--nums > 0)
3207                 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3208         *num_dacs = nums;
3209         return ret;
3210 }
3211
3212 #define MAX_AUTO_DACS   5
3213
3214 #define DAC_SLAVE_FLAG  0x8000  /* filled dac is a slave */
3215
3216 /* fill analog DAC list from the widget tree */
3217 static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3218 {
3219         hda_nid_t nid, end_nid;
3220         int nums = 0;
3221
3222         end_nid = codec->start_nid + codec->num_nodes;
3223         for (nid = codec->start_nid; nid < end_nid; nid++) {
3224                 unsigned int wcaps = get_wcaps(codec, nid);
3225                 unsigned int type = get_wcaps_type(wcaps);
3226                 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3227                         dacs[nums++] = nid;
3228                         if (nums >= MAX_AUTO_DACS)
3229                                 break;
3230                 }
3231         }
3232         return nums;
3233 }
3234
3235 /* fill pin_dac_pair list from the pin and dac list */
3236 static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3237                               int num_pins, hda_nid_t *dacs, int *rest,
3238                               struct pin_dac_pair *filled, int nums, 
3239                               int type)
3240 {
3241         int i, start = nums;
3242
3243         for (i = 0; i < num_pins; i++, nums++) {
3244                 filled[nums].pin = pins[i];
3245                 filled[nums].type = type;
3246                 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3247                 if (filled[nums].dac) 
3248                         continue;
3249                 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3250                         filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3251                         continue;
3252                 }
3253                 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
3254                         filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
3255                         continue;
3256                 }
3257                 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
3258         }
3259         return nums;
3260 }
3261
3262 /* parse analog output paths */
3263 static void cx_auto_parse_output(struct hda_codec *codec)
3264 {
3265         struct conexant_spec *spec = codec->spec;
3266         struct auto_pin_cfg *cfg = &spec->autocfg;
3267         hda_nid_t dacs[MAX_AUTO_DACS];
3268         int i, j, nums, rest;
3269
3270         rest = fill_cx_auto_dacs(codec, dacs);
3271         /* parse all analog output pins */
3272         nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3273                           dacs, &rest, spec->dac_info, 0,
3274                           AUTO_PIN_LINE_OUT);
3275         nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3276                           dacs, &rest, spec->dac_info, nums,
3277                           AUTO_PIN_HP_OUT);
3278         nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3279                           dacs, &rest, spec->dac_info, nums,
3280                           AUTO_PIN_SPEAKER_OUT);
3281         spec->dac_info_filled = nums;
3282         /* fill multiout struct */
3283         for (i = 0; i < nums; i++) {
3284                 hda_nid_t dac = spec->dac_info[i].dac;
3285                 if (!dac || (dac & DAC_SLAVE_FLAG))
3286                         continue;
3287                 switch (spec->dac_info[i].type) {
3288                 case AUTO_PIN_LINE_OUT:
3289                         spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3290                         spec->multiout.num_dacs++;
3291                         break;
3292                 case AUTO_PIN_HP_OUT:
3293                 case AUTO_PIN_SPEAKER_OUT:
3294                         if (!spec->multiout.hp_nid) {
3295                                 spec->multiout.hp_nid = dac;
3296                                 break;
3297                         }
3298                         for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3299                                 if (!spec->multiout.extra_out_nid[j]) {
3300                                         spec->multiout.extra_out_nid[j] = dac;
3301                                         break;
3302                                 }
3303                         break;
3304                 }
3305         }
3306         spec->multiout.dac_nids = spec->private_dac_nids;
3307         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3308
3309         for (i = 0; i < cfg->hp_outs; i++) {
3310                 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3311                         spec->auto_mute = 1;
3312                         break;
3313                 }
3314         }
3315         if (spec->auto_mute &&
3316             cfg->line_out_pins[0] &&
3317             cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
3318             cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3319             cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3320                 for (i = 0; i < cfg->line_outs; i++) {
3321                         if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3322                                 spec->detect_line = 1;
3323                                 break;
3324                         }
3325                 }
3326                 spec->automute_lines = spec->detect_line;
3327         }
3328
3329         spec->vmaster_nid = spec->private_dac_nids[0];
3330 }
3331
3332 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3333                               hda_nid_t *pins, bool on);
3334
3335 static void do_automute(struct hda_codec *codec, int num_pins,
3336                         hda_nid_t *pins, bool on)
3337 {
3338         struct conexant_spec *spec = codec->spec;
3339         int i;
3340         for (i = 0; i < num_pins; i++)
3341                 snd_hda_set_pin_ctl(codec, pins[i], on ? PIN_OUT : 0);
3342         if (spec->pin_eapd_ctrls)
3343                 cx_auto_turn_eapd(codec, num_pins, pins, on);
3344 }
3345
3346 static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3347 {
3348         int i, present = 0;
3349
3350         for (i = 0; i < num_pins; i++) {
3351                 hda_nid_t nid = pins[i];
3352                 if (!nid || !is_jack_detectable(codec, nid))
3353                         break;
3354                 present |= snd_hda_jack_detect(codec, nid);
3355         }
3356         return present;
3357 }
3358
3359 /* auto-mute/unmute speaker and line outs according to headphone jack */
3360 static void cx_auto_update_speakers(struct hda_codec *codec)
3361 {
3362         struct conexant_spec *spec = codec->spec;
3363         struct auto_pin_cfg *cfg = &spec->autocfg;
3364         int on = 1;
3365
3366         /* turn on HP EAPD when HP jacks are present */
3367         if (spec->pin_eapd_ctrls) {
3368                 if (spec->auto_mute)
3369                         on = spec->hp_present;
3370                 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3371         }
3372
3373         /* mute speakers in auto-mode if HP or LO jacks are plugged */
3374         if (spec->auto_mute)
3375                 on = !(spec->hp_present ||
3376                        (spec->detect_line && spec->line_present));
3377         do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
3378
3379         /* toggle line-out mutes if needed, too */
3380         /* if LO is a copy of either HP or Speaker, don't need to handle it */
3381         if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3382             cfg->line_out_pins[0] == cfg->speaker_pins[0])
3383                 return;
3384         if (spec->auto_mute) {
3385                 /* mute LO in auto-mode when HP jack is present */
3386                 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3387                     spec->automute_lines)
3388                         on = !spec->hp_present;
3389                 else
3390                         on = 1;
3391         }
3392         do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
3393 }
3394
3395 static void cx_auto_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
3396 {
3397         struct conexant_spec *spec = codec->spec;
3398         struct auto_pin_cfg *cfg = &spec->autocfg;
3399
3400         if (!spec->auto_mute)
3401                 return;
3402         spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3403         cx_auto_update_speakers(codec);
3404 }
3405
3406 static void cx_auto_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
3407 {
3408         struct conexant_spec *spec = codec->spec;
3409         struct auto_pin_cfg *cfg = &spec->autocfg;
3410
3411         if (!spec->auto_mute || !spec->detect_line)
3412                 return;
3413         spec->line_present = detect_jacks(codec, cfg->line_outs,
3414                                           cfg->line_out_pins);
3415         cx_auto_update_speakers(codec);
3416 }
3417
3418 static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3419                                  struct snd_ctl_elem_info *uinfo)
3420 {
3421         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3422         struct conexant_spec *spec = codec->spec;
3423         static const char * const texts3[] = {
3424                 "Disabled", "Speaker Only", "Line Out+Speaker"
3425         };
3426
3427         if (spec->automute_hp_lo)
3428                 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
3429         return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
3430 }
3431
3432 static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3433                                 struct snd_ctl_elem_value *ucontrol)
3434 {
3435         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3436         struct conexant_spec *spec = codec->spec;
3437         unsigned int val;
3438         if (!spec->auto_mute)
3439                 val = 0;
3440         else if (!spec->automute_lines)
3441                 val = 1;
3442         else
3443                 val = 2;
3444         ucontrol->value.enumerated.item[0] = val;
3445         return 0;
3446 }
3447
3448 static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3449                                 struct snd_ctl_elem_value *ucontrol)
3450 {
3451         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3452         struct conexant_spec *spec = codec->spec;
3453
3454         switch (ucontrol->value.enumerated.item[0]) {
3455         case 0:
3456                 if (!spec->auto_mute)
3457                         return 0;
3458                 spec->auto_mute = 0;
3459                 break;
3460         case 1:
3461                 if (spec->auto_mute && !spec->automute_lines)
3462                         return 0;
3463                 spec->auto_mute = 1;
3464                 spec->automute_lines = 0;
3465                 break;
3466         case 2:
3467                 if (!spec->automute_hp_lo)
3468                         return -EINVAL;
3469                 if (spec->auto_mute && spec->automute_lines)
3470                         return 0;
3471                 spec->auto_mute = 1;
3472                 spec->automute_lines = 1;
3473                 break;
3474         default:
3475                 return -EINVAL;
3476         }
3477         cx_auto_update_speakers(codec);
3478         return 1;
3479 }
3480
3481 static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3482         {
3483                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3484                 .name = "Auto-Mute Mode",
3485                 .info = cx_automute_mode_info,
3486                 .get = cx_automute_mode_get,
3487                 .put = cx_automute_mode_put,
3488         },
3489         { }
3490 };
3491
3492 static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3493                                  struct snd_ctl_elem_info *uinfo)
3494 {
3495         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3496         struct conexant_spec *spec = codec->spec;
3497
3498         return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3499 }
3500
3501 static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3502                                 struct snd_ctl_elem_value *ucontrol)
3503 {
3504         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3505         struct conexant_spec *spec = codec->spec;
3506
3507         ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3508         return 0;
3509 }
3510
3511 /* look for the route the given pin from mux and return the index;
3512  * if do_select is set, actually select the route.
3513  */
3514 static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3515                                      hda_nid_t pin, hda_nid_t *srcp,
3516                                      bool do_select, int depth)
3517 {
3518         struct conexant_spec *spec = codec->spec;
3519         hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3520         int startidx, i, nums;
3521
3522         switch (get_wcaps_type(get_wcaps(codec, mux))) {
3523         case AC_WID_AUD_IN:
3524         case AC_WID_AUD_SEL:
3525         case AC_WID_AUD_MIX:
3526                 break;
3527         default:
3528                 return -1;
3529         }
3530
3531         nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3532         for (i = 0; i < nums; i++)
3533                 if (conn[i] == pin) {
3534                         if (do_select)
3535                                 snd_hda_codec_write(codec, mux, 0,
3536                                                     AC_VERB_SET_CONNECT_SEL, i);
3537                         if (srcp)
3538                                 *srcp = mux;
3539                         return i;
3540                 }
3541         depth++;
3542         if (depth == 2)
3543                 return -1;
3544
3545         /* Try to rotate around connections to avoid one boost controlling
3546            another input path as well */
3547         startidx = 0;
3548         for (i = 0; i < spec->private_imux.num_items; i++)
3549                 if (spec->imux_info[i].pin == pin) {
3550                         startidx = i;
3551                         break;
3552                 }
3553
3554         for (i = 0; i < nums; i++) {
3555                 int j = (i + startidx) % nums;
3556                 int ret  = __select_input_connection(codec, conn[j], pin, srcp,
3557                                                      do_select, depth);
3558                 if (ret >= 0) {
3559                         if (do_select)
3560                                 snd_hda_codec_write(codec, mux, 0,
3561                                                     AC_VERB_SET_CONNECT_SEL, j);
3562                         return j;
3563                 }
3564         }
3565         return -1;
3566 }
3567
3568 static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3569                                    hda_nid_t pin)
3570 {
3571         __select_input_connection(codec, mux, pin, NULL, true, 0);
3572 }
3573
3574 static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3575                                 hda_nid_t pin)
3576 {
3577         return __select_input_connection(codec, mux, pin, NULL, false, 0);
3578 }
3579
3580 static int cx_auto_mux_enum_update(struct hda_codec *codec,
3581                                    const struct hda_input_mux *imux,
3582                                    unsigned int idx)
3583 {
3584         struct conexant_spec *spec = codec->spec;
3585         hda_nid_t adc;
3586         int changed = 1;
3587
3588         if (!imux->num_items)
3589                 return 0;
3590         if (idx >= imux->num_items)
3591                 idx = imux->num_items - 1;
3592         if (spec->cur_mux[0] == idx)
3593                 changed = 0;
3594         adc = spec->imux_info[idx].adc;
3595         select_input_connection(codec, spec->imux_info[idx].adc,
3596                                 spec->imux_info[idx].pin);
3597         if (spec->cur_adc && spec->cur_adc != adc) {
3598                 /* stream is running, let's swap the current ADC */
3599                 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3600                 spec->cur_adc = adc;
3601                 snd_hda_codec_setup_stream(codec, adc,
3602                                            spec->cur_adc_stream_tag, 0,
3603                                            spec->cur_adc_format);
3604         }
3605         spec->cur_mux[0] = idx;
3606         return changed;
3607 }
3608
3609 static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3610                                 struct snd_ctl_elem_value *ucontrol)
3611 {
3612         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3613         struct conexant_spec *spec = codec->spec;
3614
3615         return cx_auto_mux_enum_update(codec, &spec->private_imux,
3616                                        ucontrol->value.enumerated.item[0]);
3617 }
3618
3619 static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3620         {
3621                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3622                 .name = "Capture Source",
3623                 .info = cx_auto_mux_enum_info,
3624                 .get = cx_auto_mux_enum_get,
3625                 .put = cx_auto_mux_enum_put
3626         },
3627         {}
3628 };
3629
3630 static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3631 {
3632         struct conexant_spec *spec = codec->spec;
3633         if (idx < 0)
3634                 return false;
3635         if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3636                 return false;
3637         cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3638         return true;
3639 }
3640
3641 /* automatic switch internal and external mic */
3642 static void cx_auto_automic(struct hda_codec *codec, struct hda_jack_tbl *jack)
3643 {
3644         struct conexant_spec *spec = codec->spec;
3645
3646         if (!spec->auto_mic)
3647                 return;
3648         if (!select_automic(codec, spec->auto_mic_ext, true))
3649                 if (!select_automic(codec, spec->auto_mic_dock, true))
3650                         select_automic(codec, spec->auto_mic_int, false);
3651 }
3652
3653 /* check whether the pin config is suitable for auto-mic switching;
3654  * auto-mic is enabled only when one int-mic and one ext- and/or
3655  * one dock-mic exist
3656  */
3657 static void cx_auto_check_auto_mic(struct hda_codec *codec)
3658 {
3659         struct conexant_spec *spec = codec->spec;
3660         int pset[INPUT_PIN_ATTR_NORMAL + 1];
3661         int i;
3662
3663         for (i = 0; i < ARRAY_SIZE(pset); i++)
3664                 pset[i] = -1;
3665         for (i = 0; i < spec->private_imux.num_items; i++) {
3666                 hda_nid_t pin = spec->imux_info[i].pin;
3667                 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3668                 int type, attr;
3669                 attr = snd_hda_get_input_pin_attr(def_conf);
3670                 if (attr == INPUT_PIN_ATTR_UNUSED)
3671                         return; /* invalid entry */
3672                 if (attr > INPUT_PIN_ATTR_NORMAL)
3673                         attr = INPUT_PIN_ATTR_NORMAL;
3674                 if (attr != INPUT_PIN_ATTR_INT &&
3675                     !is_jack_detectable(codec, pin))
3676                         return; /* non-detectable pin */
3677                 type = get_defcfg_device(def_conf);
3678                 if (type != AC_JACK_MIC_IN &&
3679                     (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3680                         return; /* no valid input type */
3681                 if (pset[attr] >= 0)
3682                         return; /* already occupied */
3683                 pset[attr] = i;
3684         }
3685         if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3686             (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3687                 return; /* no input to switch*/
3688         spec->auto_mic = 1;
3689         spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3690         spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3691         spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
3692 }
3693
3694 static void cx_auto_parse_input(struct hda_codec *codec)
3695 {
3696         struct conexant_spec *spec = codec->spec;
3697         struct auto_pin_cfg *cfg = &spec->autocfg;
3698         struct hda_input_mux *imux;
3699         int i, j;
3700
3701         imux = &spec->private_imux;
3702         for (i = 0; i < cfg->num_inputs; i++) {
3703                 for (j = 0; j < spec->num_adc_nids; j++) {
3704                         hda_nid_t adc = spec->adc_nids[j];
3705                         int idx = get_input_connection(codec, adc,
3706                                                        cfg->inputs[i].pin);
3707                         if (idx >= 0) {
3708                                 const char *label;
3709                                 label = hda_get_autocfg_input_label(codec, cfg, i);
3710                                 spec->imux_info[imux->num_items].index = i;
3711                                 spec->imux_info[imux->num_items].boost = 0;
3712                                 spec->imux_info[imux->num_items].adc = adc;
3713                                 spec->imux_info[imux->num_items].pin =
3714                                         cfg->inputs[i].pin;
3715                                 snd_hda_add_imux_item(imux, label, idx, NULL);
3716                                 break;
3717                         }
3718                 }
3719         }
3720         if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
3721                 cx_auto_check_auto_mic(codec);
3722         if (imux->num_items > 1) {
3723                 for (i = 1; i < imux->num_items; i++) {
3724                         if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
3725                                 spec->adc_switching = 1;
3726                                 break;
3727                         }
3728                 }
3729         }
3730 }
3731
3732 /* get digital-input audio widget corresponding to the given pin */
3733 static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3734 {
3735         hda_nid_t nid, end_nid;
3736
3737         end_nid = codec->start_nid + codec->num_nodes;
3738         for (nid = codec->start_nid; nid < end_nid; nid++) {
3739                 unsigned int wcaps = get_wcaps(codec, nid);
3740                 unsigned int type = get_wcaps_type(wcaps);
3741                 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3742                         if (get_connection_index(codec, nid, pin) >= 0)
3743                                 return nid;
3744                 }
3745         }
3746         return 0;
3747 }
3748
3749 static void cx_auto_parse_digital(struct hda_codec *codec)
3750 {
3751         struct conexant_spec *spec = codec->spec;
3752         struct auto_pin_cfg *cfg = &spec->autocfg;
3753         hda_nid_t nid;
3754
3755         if (cfg->dig_outs &&
3756             snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3757                 spec->multiout.dig_out_nid = nid;
3758         if (cfg->dig_in_pin)
3759                 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3760 }
3761
3762 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3763 static void cx_auto_parse_beep(struct hda_codec *codec)
3764 {
3765         struct conexant_spec *spec = codec->spec;
3766         hda_nid_t nid, end_nid;
3767
3768         end_nid = codec->start_nid + codec->num_nodes;
3769         for (nid = codec->start_nid; nid < end_nid; nid++)
3770                 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3771                         set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3772                         break;
3773                 }
3774 }
3775 #else
3776 #define cx_auto_parse_beep(codec)
3777 #endif
3778
3779 /* parse EAPDs */
3780 static void cx_auto_parse_eapd(struct hda_codec *codec)
3781 {
3782         struct conexant_spec *spec = codec->spec;
3783         hda_nid_t nid, end_nid;
3784
3785         end_nid = codec->start_nid + codec->num_nodes;
3786         for (nid = codec->start_nid; nid < end_nid; nid++) {
3787                 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3788                         continue;
3789                 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3790                         continue;
3791                 spec->eapds[spec->num_eapds++] = nid;
3792                 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3793                         break;
3794         }
3795
3796         /* NOTE: below is a wild guess; if we have more than two EAPDs,
3797          * it's a new chip, where EAPDs are supposed to be associated to
3798          * pins, and we can control EAPD per pin.
3799          * OTOH, if only one or two EAPDs are found, it's an old chip,
3800          * thus it might control over all pins.
3801          */
3802         spec->pin_eapd_ctrls = spec->num_eapds > 2;
3803 }
3804
3805 static int cx_auto_parse_auto_config(struct hda_codec *codec)
3806 {
3807         struct conexant_spec *spec = codec->spec;
3808         int err;
3809
3810         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3811         if (err < 0)
3812                 return err;
3813
3814         cx_auto_parse_output(codec);
3815         cx_auto_parse_input(codec);
3816         cx_auto_parse_digital(codec);
3817         cx_auto_parse_beep(codec);
3818         cx_auto_parse_eapd(codec);
3819         return 0;
3820 }
3821
3822 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3823                               hda_nid_t *pins, bool on)
3824 {
3825         int i;
3826         for (i = 0; i < num_pins; i++) {
3827                 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3828                         snd_hda_codec_write(codec, pins[i], 0,
3829                                             AC_VERB_SET_EAPD_BTLENABLE,
3830                                             on ? 0x02 : 0);
3831         }
3832 }
3833
3834 static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3835                               hda_nid_t src)
3836 {
3837         int idx = get_connection_index(codec, pin, src);
3838         if (idx >= 0)
3839                 snd_hda_codec_write(codec, pin, 0,
3840                                     AC_VERB_SET_CONNECT_SEL, idx);
3841 }
3842
3843 static void mute_outputs(struct hda_codec *codec, int num_nids,
3844                          const hda_nid_t *nids)
3845 {
3846         int i, val;
3847
3848         for (i = 0; i < num_nids; i++) {
3849                 hda_nid_t nid = nids[i];
3850                 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3851                         continue;
3852                 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3853                         val = AMP_OUT_MUTE;
3854                 else
3855                         val = AMP_OUT_ZERO;
3856                 snd_hda_codec_write(codec, nid, 0,
3857                                     AC_VERB_SET_AMP_GAIN_MUTE, val);
3858         }
3859 }
3860
3861 static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
3862                               hda_nid_t *pins, unsigned int action,
3863                               hda_jack_callback cb)
3864 {
3865         int i;
3866         for (i = 0; i < num_pins; i++)
3867                 snd_hda_jack_detect_enable_callback(codec, pins[i], action, cb);
3868 }
3869
3870 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
3871 {
3872         int i;
3873         for (i = 0; i < nums; i++)
3874                 if (list[i] == nid)
3875                         return true;
3876         return false;
3877 }
3878
3879 /* is the given NID found in any of autocfg items? */
3880 static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid)
3881 {
3882         int i;
3883
3884         if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3885             found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3886             found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) ||
3887             found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs))
3888                 return true;
3889         for (i = 0; i < cfg->num_inputs; i++)
3890                 if (cfg->inputs[i].pin == nid)
3891                         return true;
3892         if (cfg->dig_in_pin == nid)
3893                 return true;
3894         return false;
3895 }
3896
3897 /* clear unsol-event tags on unused pins; Conexant codecs seem to leave
3898  * invalid unsol tags by some reason
3899  */
3900 static void clear_unsol_on_unused_pins(struct hda_codec *codec)
3901 {
3902         struct conexant_spec *spec = codec->spec;
3903         struct auto_pin_cfg *cfg = &spec->autocfg;
3904         int i;
3905
3906         for (i = 0; i < codec->init_pins.used; i++) {
3907                 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
3908                 if (!found_in_autocfg(cfg, pin->nid))
3909                         snd_hda_codec_write(codec, pin->nid, 0,
3910                                             AC_VERB_SET_UNSOLICITED_ENABLE, 0);
3911         }
3912 }
3913
3914 /* turn on/off EAPD according to Master switch */
3915 static void cx_auto_vmaster_hook(void *private_data, int enabled)
3916 {
3917         struct hda_codec *codec = private_data;
3918         struct conexant_spec *spec = codec->spec;
3919
3920         if (enabled && spec->pin_eapd_ctrls) {
3921                 cx_auto_update_speakers(codec);
3922                 return;
3923         }
3924         cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3925 }
3926
3927 static void cx_auto_init_output(struct hda_codec *codec)
3928 {
3929         struct conexant_spec *spec = codec->spec;
3930         struct auto_pin_cfg *cfg = &spec->autocfg;
3931         hda_nid_t nid;
3932         int i;
3933
3934         mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
3935         for (i = 0; i < cfg->hp_outs; i++) {
3936                 unsigned int val = PIN_OUT;
3937                 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) &
3938                     AC_PINCAP_HP_DRV)
3939                         val |= AC_PINCTL_HP_EN;
3940                 snd_hda_set_pin_ctl(codec, cfg->hp_pins[i], val);
3941         }
3942         mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3943         mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3944         mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
3945         for (i = 0; i < spec->dac_info_filled; i++) {
3946                 nid = spec->dac_info[i].dac;
3947                 if (!nid)
3948                         nid = spec->multiout.dac_nids[0];
3949                 else if (nid & DAC_SLAVE_FLAG)
3950                         nid &= ~DAC_SLAVE_FLAG;
3951                 select_connection(codec, spec->dac_info[i].pin, nid);
3952         }
3953         if (spec->auto_mute) {
3954                 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
3955                                   CONEXANT_HP_EVENT, cx_auto_hp_automute);
3956                 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
3957                                                 cfg->hp_pins);
3958                 if (spec->detect_line) {
3959                         enable_unsol_pins(codec, cfg->line_outs,
3960                                           cfg->line_out_pins,
3961                                           CONEXANT_LINE_EVENT,
3962                                           cx_auto_line_automute);
3963                         spec->line_present =
3964                                 detect_jacks(codec, cfg->line_outs,
3965                                              cfg->line_out_pins);
3966                 }
3967         }
3968         cx_auto_update_speakers(codec);
3969         /* turn on all EAPDs if no individual EAPD control is available */
3970         if (!spec->pin_eapd_ctrls)
3971                 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
3972         clear_unsol_on_unused_pins(codec);
3973 }
3974
3975 static void cx_auto_init_input(struct hda_codec *codec)
3976 {
3977         struct conexant_spec *spec = codec->spec;
3978         struct auto_pin_cfg *cfg = &spec->autocfg;
3979         int i, val;
3980
3981         for (i = 0; i < spec->num_adc_nids; i++) {
3982                 hda_nid_t nid = spec->adc_nids[i];
3983                 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3984                         continue;
3985                 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
3986                         val = AMP_IN_MUTE(0);
3987                 else
3988                         val = AMP_IN_UNMUTE(0);
3989                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3990                                     val);
3991         }
3992
3993         for (i = 0; i < cfg->num_inputs; i++) {
3994                 hda_nid_t pin = cfg->inputs[i].pin;
3995                 unsigned int type = PIN_IN;
3996                 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3997                         type |= snd_hda_get_default_vref(codec, pin);
3998                 snd_hda_set_pin_ctl(codec, pin, type);
3999         }
4000
4001         if (spec->auto_mic) {
4002                 if (spec->auto_mic_ext >= 0) {
4003                         snd_hda_jack_detect_enable_callback(codec,
4004                                 cfg->inputs[spec->auto_mic_ext].pin,
4005                                 CONEXANT_MIC_EVENT, cx_auto_automic);
4006                 }
4007                 if (spec->auto_mic_dock >= 0) {
4008                         snd_hda_jack_detect_enable_callback(codec,
4009                                 cfg->inputs[spec->auto_mic_dock].pin,
4010                                 CONEXANT_MIC_EVENT, cx_auto_automic);
4011                 }
4012                 cx_auto_automic(codec, NULL);
4013         } else {
4014                 select_input_connection(codec, spec->imux_info[0].adc,
4015                                         spec->imux_info[0].pin);
4016         }
4017 }
4018
4019 static void cx_auto_init_digital(struct hda_codec *codec)
4020 {
4021         struct conexant_spec *spec = codec->spec;
4022         struct auto_pin_cfg *cfg = &spec->autocfg;
4023
4024         if (spec->multiout.dig_out_nid)
4025                 snd_hda_set_pin_ctl(codec, cfg->dig_out_pins[0], PIN_OUT);
4026         if (spec->dig_in_nid)
4027                 snd_hda_set_pin_ctl(codec, cfg->dig_in_pin, PIN_IN);
4028 }
4029
4030 static int cx_auto_init(struct hda_codec *codec)
4031 {
4032         struct conexant_spec *spec = codec->spec;
4033         snd_hda_apply_verbs(codec);
4034         cx_auto_init_output(codec);
4035         cx_auto_init_input(codec);
4036         cx_auto_init_digital(codec);
4037         snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4038         return 0;
4039 }
4040
4041 static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
4042                               const char *dir, int cidx,
4043                               hda_nid_t nid, int hda_dir, int amp_idx, int chs)
4044 {
4045         static char name[44];
4046         static struct snd_kcontrol_new knew[] = {
4047                 HDA_CODEC_VOLUME(name, 0, 0, 0),
4048                 HDA_CODEC_MUTE(name, 0, 0, 0),
4049         };
4050         static const char * const sfx[2] = { "Volume", "Switch" };
4051         int i, err;
4052
4053         for (i = 0; i < 2; i++) {
4054                 struct snd_kcontrol *kctl;
4055                 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx,
4056                                                             hda_dir);
4057                 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4058                 knew[i].index = cidx;
4059                 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4060                 kctl = snd_ctl_new1(&knew[i], codec);
4061                 if (!kctl)
4062                         return -ENOMEM;
4063                 err = snd_hda_ctl_add(codec, nid, kctl);
4064                 if (err < 0)
4065                         return err;
4066                 if (!(query_amp_caps(codec, nid, hda_dir) &
4067                       (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
4068                         break;
4069         }
4070         return 0;
4071 }
4072
4073 #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir)         \
4074         cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3)
4075
4076 #define cx_auto_add_pb_volume(codec, nid, str, idx)                     \
4077         cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4078
4079 static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4080                              hda_nid_t pin, const char *name, int idx)
4081 {
4082         unsigned int caps;
4083         if (dac && !(dac & DAC_SLAVE_FLAG)) {
4084                 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4085                 if (caps & AC_AMPCAP_NUM_STEPS)
4086                         return cx_auto_add_pb_volume(codec, dac, name, idx);
4087         }
4088         caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4089         if (caps & AC_AMPCAP_NUM_STEPS)
4090                 return cx_auto_add_pb_volume(codec, pin, name, idx);
4091         return 0;
4092 }
4093
4094 static bool is_2_1_speaker(struct conexant_spec *spec)
4095 {
4096         int i, type, num_spk = 0;
4097
4098         for (i = 0; i < spec->dac_info_filled; i++) {
4099                 type = spec->dac_info[i].type;
4100                 if (type == AUTO_PIN_LINE_OUT)
4101                         type = spec->autocfg.line_out_type;
4102                 if (type == AUTO_PIN_SPEAKER_OUT)
4103                         num_spk++;
4104         }
4105         return (num_spk == 2 && spec->autocfg.line_out_type != AUTO_PIN_LINE_OUT);
4106 }
4107
4108 static int cx_auto_build_output_controls(struct hda_codec *codec)
4109 {
4110         struct conexant_spec *spec = codec->spec;
4111         int i, err;
4112         int num_line = 0, num_hp = 0, num_spk = 0;
4113         bool speaker_2_1;
4114         static const char * const texts[3] = { "Front", "Surround", "CLFE" };
4115
4116         if (spec->dac_info_filled == 1)
4117                 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4118                                          spec->dac_info[0].pin,
4119                                          "Master", 0);
4120
4121         speaker_2_1 = is_2_1_speaker(spec);
4122
4123         for (i = 0; i < spec->dac_info_filled; i++) {
4124                 const char *label;
4125                 int idx, type;
4126                 hda_nid_t dac = spec->dac_info[i].dac;
4127                 type = spec->dac_info[i].type;
4128                 if (type == AUTO_PIN_LINE_OUT)
4129                         type = spec->autocfg.line_out_type;
4130                 switch (type) {
4131                 case AUTO_PIN_LINE_OUT:
4132                 default:
4133                         label = texts[num_line++];
4134                         idx = 0;
4135                         break;
4136                 case AUTO_PIN_HP_OUT:
4137                         label = "Headphone";
4138                         idx = num_hp++;
4139                         break;
4140                 case AUTO_PIN_SPEAKER_OUT:
4141                         if (speaker_2_1) {
4142                                 label = num_spk++ ? "Bass Speaker" : "Speaker";
4143                                 idx = 0;
4144                         } else {
4145                                 label = "Speaker";
4146                                 idx = num_spk++;
4147                         }
4148                         break;
4149                 }
4150                 err = try_add_pb_volume(codec, dac,
4151                                         spec->dac_info[i].pin,
4152                                         label, idx);
4153                 if (err < 0)
4154                         return err;
4155         }
4156
4157         if (spec->auto_mute) {
4158                 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4159                 if (err < 0)
4160                         return err;
4161         }
4162         
4163         return 0;
4164 }
4165
4166 /* Returns zero if this is a normal stereo channel, and non-zero if it should
4167    be split in two independent channels.
4168    dest_label must be at least 44 characters. */
4169 static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label,
4170                                      char *dest_label, int nid)
4171 {
4172         struct conexant_spec *spec = codec->spec;
4173         int i;
4174
4175         if (!spec->fixup_stereo_dmic)
4176                 return 0;
4177
4178         for (i = 0; i < AUTO_CFG_MAX_INS; i++) {
4179                 int def_conf;
4180                 if (spec->autocfg.inputs[i].pin != nid)
4181                         continue;
4182
4183                 if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC)
4184                         return 0;
4185                 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4186                 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT)
4187                         return 0;
4188
4189                 /* Finally found the inverted internal mic! */
4190                 snprintf(dest_label, 44, "Inverted %s", label);
4191                 return 1;
4192         }
4193         return 0;
4194 }
4195
4196 static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4197                                       const char *label, const char *pfx,
4198                                       int cidx)
4199 {
4200         struct conexant_spec *spec = codec->spec;
4201         int i;
4202
4203         for (i = 0; i < spec->num_adc_nids; i++) {
4204                 char rightch_label[44];
4205                 hda_nid_t adc_nid = spec->adc_nids[i];
4206                 int idx = get_input_connection(codec, adc_nid, nid);
4207                 if (idx < 0)
4208                         continue;
4209                 if (codec->single_adc_amp)
4210                         idx = 0;
4211
4212                 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4213                         /* Make two independent kcontrols for left and right */
4214                         int err = cx_auto_add_volume_idx(codec, label, pfx,
4215                                               cidx, adc_nid, HDA_INPUT, idx, 1);
4216                         if (err < 0)
4217                                 return err;
4218                         return cx_auto_add_volume_idx(codec, rightch_label, pfx,
4219                                                       cidx, adc_nid, HDA_INPUT, idx, 2);
4220                 }
4221                 return cx_auto_add_volume_idx(codec, label, pfx,
4222                                               cidx, adc_nid, HDA_INPUT, idx, 3);
4223         }
4224         return 0;
4225 }
4226
4227 static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4228                                     const char *label, int cidx)
4229 {
4230         struct conexant_spec *spec = codec->spec;
4231         hda_nid_t mux, nid;
4232         int i, con;
4233
4234         nid = spec->imux_info[idx].pin;
4235         if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4236                 char rightch_label[44];
4237                 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4238                         int err = cx_auto_add_volume_idx(codec, label, " Boost",
4239                                                          cidx, nid, HDA_INPUT, 0, 1);
4240                         if (err < 0)
4241                                 return err;
4242                         return cx_auto_add_volume_idx(codec, rightch_label, " Boost",
4243                                                       cidx, nid, HDA_INPUT, 0, 2);
4244                 }
4245                 return cx_auto_add_volume(codec, label, " Boost", cidx,
4246                                           nid, HDA_INPUT);
4247         }
4248         con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4249                                         &mux, false, 0);
4250         if (con < 0)
4251                 return 0;
4252         for (i = 0; i < idx; i++) {
4253                 if (spec->imux_info[i].boost == mux)
4254                         return 0; /* already present */
4255         }
4256
4257         if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
4258                 spec->imux_info[idx].boost = mux;
4259                 return cx_auto_add_volume(codec, label, " Boost", cidx,
4260                                           mux, HDA_OUTPUT);
4261         }
4262         return 0;
4263 }
4264
4265 static int cx_auto_build_input_controls(struct hda_codec *codec)
4266 {
4267         struct conexant_spec *spec = codec->spec;
4268         struct hda_input_mux *imux = &spec->private_imux;
4269         const char *prev_label;
4270         int input_conn[HDA_MAX_NUM_INPUTS];
4271         int i, j, err, cidx;
4272         int multi_connection;
4273
4274         if (!imux->num_items)
4275                 return 0;
4276
4277         multi_connection = 0;
4278         for (i = 0; i < imux->num_items; i++) {
4279                 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4280                                             spec->imux_info[i].pin);
4281                 if (cidx < 0)
4282                         continue;
4283                 input_conn[i] = spec->imux_info[i].adc;
4284                 if (!codec->single_adc_amp)
4285                         input_conn[i] |= cidx << 8;
4286                 if (i > 0 && input_conn[i] != input_conn[0])
4287                         multi_connection = 1;
4288         }
4289
4290         prev_label = NULL;
4291         cidx = 0;
4292         for (i = 0; i < imux->num_items; i++) {
4293                 hda_nid_t nid = spec->imux_info[i].pin;
4294                 const char *label;
4295
4296                 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
4297                                                     spec->imux_info[i].index);
4298                 if (label == prev_label)
4299                         cidx++;
4300                 else
4301                         cidx = 0;
4302                 prev_label = label;
4303
4304                 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4305                 if (err < 0)
4306                         return err;
4307
4308                 if (!multi_connection) {
4309                         if (i > 0)
4310                                 continue;
4311                         err = cx_auto_add_capture_volume(codec, nid,
4312                                                          "Capture", "", cidx);
4313                 } else {
4314                         bool dup_found = false;
4315                         for (j = 0; j < i; j++) {
4316                                 if (input_conn[j] == input_conn[i]) {
4317                                         dup_found = true;
4318                                         break;
4319                                 }
4320                         }
4321                         if (dup_found)
4322                                 continue;
4323                         err = cx_auto_add_capture_volume(codec, nid,
4324                                                          label, " Capture", cidx);
4325                 }
4326                 if (err < 0)
4327                         return err;
4328         }
4329
4330         if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4331                 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4332                 if (err < 0)
4333                         return err;
4334         }
4335
4336         return 0;
4337 }
4338
4339 static int cx_auto_build_controls(struct hda_codec *codec)
4340 {
4341         struct conexant_spec *spec = codec->spec;
4342         int err;
4343
4344         err = cx_auto_build_output_controls(codec);
4345         if (err < 0)
4346                 return err;
4347         err = cx_auto_build_input_controls(codec);
4348         if (err < 0)
4349                 return err;
4350         err = conexant_build_controls(codec);
4351         if (err < 0)
4352                 return err;
4353         err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4354         if (err < 0)
4355                 return err;
4356         if (spec->vmaster_mute.sw_kctl) {
4357                 spec->vmaster_mute.hook = cx_auto_vmaster_hook;
4358                 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4359                                                spec->vmaster_mute_led);
4360                 if (err < 0)
4361                         return err;
4362         }
4363         return 0;
4364 }
4365
4366 static int cx_auto_search_adcs(struct hda_codec *codec)
4367 {
4368         struct conexant_spec *spec = codec->spec;
4369         hda_nid_t nid, end_nid;
4370
4371         end_nid = codec->start_nid + codec->num_nodes;
4372         for (nid = codec->start_nid; nid < end_nid; nid++) {
4373                 unsigned int caps = get_wcaps(codec, nid);
4374                 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4375                         continue;
4376                 if (caps & AC_WCAP_DIGITAL)
4377                         continue;
4378                 if (snd_BUG_ON(spec->num_adc_nids >=
4379                                ARRAY_SIZE(spec->private_adc_nids)))
4380                         break;
4381                 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4382         }
4383         spec->adc_nids = spec->private_adc_nids;
4384         return 0;
4385 }
4386
4387 static const struct hda_codec_ops cx_auto_patch_ops = {
4388         .build_controls = cx_auto_build_controls,
4389         .build_pcms = conexant_build_pcms,
4390         .init = cx_auto_init,
4391         .free = conexant_free,
4392         .unsol_event = snd_hda_jack_unsol_event,
4393 };
4394
4395 /*
4396  * pin fix-up
4397  */
4398 enum {
4399         CXT_PINCFG_LENOVO_X200,
4400         CXT_PINCFG_LENOVO_TP410,
4401         CXT_PINCFG_LEMOTE_A1004,
4402         CXT_PINCFG_LEMOTE_A1205,
4403         CXT_FIXUP_STEREO_DMIC,
4404         CXT_FIXUP_INC_MIC_BOOST,
4405 };
4406
4407 static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
4408                                   const struct hda_fixup *fix, int action)
4409 {
4410         struct conexant_spec *spec = codec->spec;
4411         spec->fixup_stereo_dmic = 1;
4412 }
4413
4414 static void cxt5066_increase_mic_boost(struct hda_codec *codec,
4415                                    const struct hda_fixup *fix, int action)
4416 {
4417         if (action != HDA_FIXUP_ACT_PRE_PROBE)
4418                 return;
4419
4420         snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
4421                                   (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
4422                                   (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4423                                   (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4424                                   (0 << AC_AMPCAP_MUTE_SHIFT));
4425 }
4426
4427 /* ThinkPad X200 & co with cxt5051 */
4428 static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
4429         { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4430         { 0x17, 0x21a11000 }, /* dock-mic */
4431         { 0x19, 0x2121103f }, /* dock-HP */
4432         { 0x1c, 0x21440100 }, /* dock SPDIF out */
4433         {}
4434 };
4435
4436 /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
4437 static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
4438         { 0x19, 0x042110ff }, /* HP (seq# overridden) */
4439         { 0x1a, 0x21a190f0 }, /* dock-mic */
4440         { 0x1c, 0x212140ff }, /* dock-HP */
4441         {}
4442 };
4443
4444 /* Lemote A1004/A1205 with cxt5066 */
4445 static const struct hda_pintbl cxt_pincfg_lemote[] = {
4446         { 0x1a, 0x90a10020 }, /* Internal mic */
4447         { 0x1b, 0x03a11020 }, /* External mic */
4448         { 0x1d, 0x400101f0 }, /* Not used */
4449         { 0x1e, 0x40a701f0 }, /* Not used */
4450         { 0x20, 0x404501f0 }, /* Not used */
4451         { 0x22, 0x404401f0 }, /* Not used */
4452         { 0x23, 0x40a701f0 }, /* Not used */
4453         {}
4454 };
4455
4456 static const struct hda_fixup cxt_fixups[] = {
4457         [CXT_PINCFG_LENOVO_X200] = {
4458                 .type = HDA_FIXUP_PINS,
4459                 .v.pins = cxt_pincfg_lenovo_x200,
4460         },
4461         [CXT_PINCFG_LENOVO_TP410] = {
4462                 .type = HDA_FIXUP_PINS,
4463                 .v.pins = cxt_pincfg_lenovo_tp410,
4464         },
4465         [CXT_PINCFG_LEMOTE_A1004] = {
4466                 .type = HDA_FIXUP_PINS,
4467                 .chained = true,
4468                 .chain_id = CXT_FIXUP_INC_MIC_BOOST,
4469                 .v.pins = cxt_pincfg_lemote,
4470         },
4471         [CXT_PINCFG_LEMOTE_A1205] = {
4472                 .type = HDA_FIXUP_PINS,
4473                 .v.pins = cxt_pincfg_lemote,
4474         },
4475         [CXT_FIXUP_STEREO_DMIC] = {
4476                 .type = HDA_FIXUP_FUNC,
4477                 .v.func = cxt_fixup_stereo_dmic,
4478         },
4479         [CXT_FIXUP_INC_MIC_BOOST] = {
4480                 .type = HDA_FIXUP_FUNC,
4481                 .v.func = cxt5066_increase_mic_boost,
4482         },
4483 };
4484
4485 static const struct snd_pci_quirk cxt5051_fixups[] = {
4486         SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4487         {}
4488 };
4489
4490 static const struct snd_pci_quirk cxt5066_fixups[] = {
4491         SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
4492         SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
4493         SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
4494         SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
4495         SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
4496         SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
4497         SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
4498         SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
4499         SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
4500         SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
4501         SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
4502         {}
4503 };
4504
4505 /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
4506  * can be created (bko#42825)
4507  */
4508 static void add_cx5051_fake_mutes(struct hda_codec *codec)
4509 {
4510         static hda_nid_t out_nids[] = {
4511                 0x10, 0x11, 0
4512         };
4513         hda_nid_t *p;
4514
4515         for (p = out_nids; *p; p++)
4516                 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
4517                                           AC_AMPCAP_MIN_MUTE |
4518                                           query_amp_caps(codec, *p, HDA_OUTPUT));
4519 }
4520
4521 static int patch_conexant_auto(struct hda_codec *codec)
4522 {
4523         struct conexant_spec *spec;
4524         int err;
4525
4526         printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4527                codec->chip_name);
4528
4529         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4530         if (!spec)
4531                 return -ENOMEM;
4532         codec->spec = spec;
4533
4534         switch (codec->vendor_id) {
4535         case 0x14f15045:
4536                 codec->single_adc_amp = 1;
4537                 break;
4538         case 0x14f15051:
4539                 add_cx5051_fake_mutes(codec);
4540                 codec->pin_amp_workaround = 1;
4541                 snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups);
4542                 break;
4543         default:
4544                 codec->pin_amp_workaround = 1;
4545                 snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups);
4546                 break;
4547         }
4548
4549         snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4550
4551         /* Show mute-led control only on HP laptops
4552          * This is a sort of white-list: on HP laptops, EAPD corresponds
4553          * only to the mute-LED without actualy amp function.  Meanwhile,
4554          * others may use EAPD really as an amp switch, so it might be
4555          * not good to expose it blindly.
4556          */
4557         switch (codec->subsystem_id >> 16) {
4558         case 0x103c:
4559                 spec->vmaster_mute_led = 1;
4560                 break;
4561         }
4562
4563         err = cx_auto_search_adcs(codec);
4564         if (err < 0)
4565                 return err;
4566         err = cx_auto_parse_auto_config(codec);
4567         if (err < 0) {
4568                 kfree(codec->spec);
4569                 codec->spec = NULL;
4570                 return err;
4571         }
4572         spec->capture_stream = &cx_auto_pcm_analog_capture;
4573         codec->patch_ops = cx_auto_patch_ops;
4574         if (spec->beep_amp)
4575                 snd_hda_attach_beep_device(codec, spec->beep_amp);
4576
4577         /* Some laptops with Conexant chips show stalls in S3 resume,
4578          * which falls into the single-cmd mode.
4579          * Better to make reset, then.
4580          */
4581         if (!codec->bus->sync_write) {
4582                 snd_printd("hda_codec: "
4583                            "Enable sync_write for stable communication\n");
4584                 codec->bus->sync_write = 1;
4585                 codec->bus->allow_bus_reset = 1;
4586         }
4587
4588         return 0;
4589 }
4590
4591 /*
4592  */
4593
4594 static const struct hda_codec_preset snd_hda_preset_conexant[] = {
4595         { .id = 0x14f15045, .name = "CX20549 (Venice)",
4596           .patch = patch_cxt5045 },
4597         { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4598           .patch = patch_cxt5047 },
4599         { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4600           .patch = patch_cxt5051 },
4601         { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4602           .patch = patch_cxt5066 },
4603         { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4604           .patch = patch_cxt5066 },
4605         { .id = 0x14f15068, .name = "CX20584",
4606           .patch = patch_cxt5066 },
4607         { .id = 0x14f15069, .name = "CX20585",
4608           .patch = patch_cxt5066 },
4609         { .id = 0x14f1506c, .name = "CX20588",
4610           .patch = patch_cxt5066 },
4611         { .id = 0x14f1506e, .name = "CX20590",
4612           .patch = patch_cxt5066 },
4613         { .id = 0x14f15097, .name = "CX20631",
4614           .patch = patch_conexant_auto },
4615         { .id = 0x14f15098, .name = "CX20632",
4616           .patch = patch_conexant_auto },
4617         { .id = 0x14f150a1, .name = "CX20641",
4618           .patch = patch_conexant_auto },
4619         { .id = 0x14f150a2, .name = "CX20642",
4620           .patch = patch_conexant_auto },
4621         { .id = 0x14f150ab, .name = "CX20651",
4622           .patch = patch_conexant_auto },
4623         { .id = 0x14f150ac, .name = "CX20652",
4624           .patch = patch_conexant_auto },
4625         { .id = 0x14f150b8, .name = "CX20664",
4626           .patch = patch_conexant_auto },
4627         { .id = 0x14f150b9, .name = "CX20665",
4628           .patch = patch_conexant_auto },
4629         { .id = 0x14f1510f, .name = "CX20751/2",
4630           .patch = patch_conexant_auto },
4631         { .id = 0x14f15110, .name = "CX20751/2",
4632           .patch = patch_conexant_auto },
4633         { .id = 0x14f15111, .name = "CX20753/4",
4634           .patch = patch_conexant_auto },
4635         {} /* terminator */
4636 };
4637
4638 MODULE_ALIAS("snd-hda-codec-id:14f15045");
4639 MODULE_ALIAS("snd-hda-codec-id:14f15047");
4640 MODULE_ALIAS("snd-hda-codec-id:14f15051");
4641 MODULE_ALIAS("snd-hda-codec-id:14f15066");
4642 MODULE_ALIAS("snd-hda-codec-id:14f15067");
4643 MODULE_ALIAS("snd-hda-codec-id:14f15068");
4644 MODULE_ALIAS("snd-hda-codec-id:14f15069");
4645 MODULE_ALIAS("snd-hda-codec-id:14f1506c");
4646 MODULE_ALIAS("snd-hda-codec-id:14f1506e");
4647 MODULE_ALIAS("snd-hda-codec-id:14f15097");
4648 MODULE_ALIAS("snd-hda-codec-id:14f15098");
4649 MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4650 MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4651 MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4652 MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4653 MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4654 MODULE_ALIAS("snd-hda-codec-id:14f150b9");
4655 MODULE_ALIAS("snd-hda-codec-id:14f1510f");
4656 MODULE_ALIAS("snd-hda-codec-id:14f15110");
4657 MODULE_ALIAS("snd-hda-codec-id:14f15111");
4658
4659 MODULE_LICENSE("GPL");
4660 MODULE_DESCRIPTION("Conexant HD-audio codec");
4661
4662 static struct hda_codec_preset_list conexant_list = {
4663         .preset = snd_hda_preset_conexant,
4664         .owner = THIS_MODULE,
4665 };
4666
4667 static int __init patch_conexant_init(void)
4668 {
4669         return snd_hda_add_codec_preset(&conexant_list);
4670 }
4671
4672 static void __exit patch_conexant_exit(void)
4673 {
4674         snd_hda_delete_codec_preset(&conexant_list);
4675 }
4676
4677 module_init(patch_conexant_init)
4678 module_exit(patch_conexant_exit)