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