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