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