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