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