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