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