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