ALSA: hda - Add comments for the previous fix for conexant codecs
[deliverable/linux.git] / sound / pci / hda / patch_conexant.c
CommitLineData
c9b443d4
TD
1/*
2 * HD audio interface patch for Conexant HDA audio codec
3 *
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
7 *
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
c9b443d4
TD
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/slab.h>
26#include <linux/pci.h>
27#include <sound/core.h>
bc7a166d
UD
28#include <sound/jack.h>
29
c9b443d4
TD
30#include "hda_codec.h"
31#include "hda_local.h"
32
33#define CXT_PIN_DIR_IN 0x00
34#define CXT_PIN_DIR_OUT 0x01
35#define CXT_PIN_DIR_INOUT 0x02
36#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
37#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
38
39#define CONEXANT_HP_EVENT 0x37
40#define CONEXANT_MIC_EVENT 0x38
41
bc7a166d
UD
42/* Conexant 5051 specific */
43
44#define CXT5051_SPDIF_OUT 0x1C
45#define CXT5051_PORTB_EVENT 0x38
46#define CXT5051_PORTC_EVENT 0x39
c9b443d4
TD
47
48
bc7a166d
UD
49struct conexant_jack {
50
51 hda_nid_t nid;
52 int type;
53 struct snd_jack *jack;
54
55};
56
c9b443d4
TD
57struct conexant_spec {
58
59 struct snd_kcontrol_new *mixers[5];
60 int num_mixers;
dd5746a8 61 hda_nid_t vmaster_nid;
c9b443d4
TD
62
63 const struct hda_verb *init_verbs[5]; /* initialization verbs
64 * don't forget NULL
65 * termination!
66 */
67 unsigned int num_init_verbs;
68
69 /* playback */
70 struct hda_multi_out multiout; /* playback set-up
71 * max_channels, dacs must be set
72 * dig_out_nid and hp_nid are optional
73 */
74 unsigned int cur_eapd;
82f30040 75 unsigned int hp_present;
79d7d533 76 unsigned int no_auto_mic;
c9b443d4
TD
77 unsigned int need_dac_fix;
78
79 /* capture */
80 unsigned int num_adc_nids;
81 hda_nid_t *adc_nids;
82 hda_nid_t dig_in_nid; /* digital-in NID; optional */
83
461e2c78
TI
84 unsigned int cur_adc_idx;
85 hda_nid_t cur_adc;
86 unsigned int cur_adc_stream_tag;
87 unsigned int cur_adc_format;
88
c9b443d4
TD
89 /* capture source */
90 const struct hda_input_mux *input_mux;
91 hda_nid_t *capsrc_nids;
92 unsigned int cur_mux[3];
93
94 /* channel model */
95 const struct hda_channel_mode *channel_mode;
96 int num_channel_mode;
97
98 /* PCM information */
99 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
100
c9b443d4
TD
101 unsigned int spdif_route;
102
bc7a166d
UD
103 /* jack detection */
104 struct snd_array jacks;
105
c9b443d4
TD
106 /* dynamic controls, init_verbs and input_mux */
107 struct auto_pin_cfg autocfg;
c9b443d4 108 struct hda_input_mux private_imux;
41923e44 109 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
c9b443d4
TD
110
111};
112
113static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
114 struct hda_codec *codec,
115 struct snd_pcm_substream *substream)
116{
117 struct conexant_spec *spec = codec->spec;
9a08160b
TI
118 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
119 hinfo);
c9b443d4
TD
120}
121
122static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
123 struct hda_codec *codec,
124 unsigned int stream_tag,
125 unsigned int format,
126 struct snd_pcm_substream *substream)
127{
128 struct conexant_spec *spec = codec->spec;
129 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
130 stream_tag,
131 format, substream);
132}
133
134static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
135 struct hda_codec *codec,
136 struct snd_pcm_substream *substream)
137{
138 struct conexant_spec *spec = codec->spec;
139 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
140}
141
142/*
143 * Digital out
144 */
145static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
146 struct hda_codec *codec,
147 struct snd_pcm_substream *substream)
148{
149 struct conexant_spec *spec = codec->spec;
150 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
151}
152
153static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
154 struct hda_codec *codec,
155 struct snd_pcm_substream *substream)
156{
157 struct conexant_spec *spec = codec->spec;
158 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
159}
160
6b97eb45
TI
161static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
162 struct hda_codec *codec,
163 unsigned int stream_tag,
164 unsigned int format,
165 struct snd_pcm_substream *substream)
166{
167 struct conexant_spec *spec = codec->spec;
168 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
169 stream_tag,
170 format, substream);
171}
172
c9b443d4
TD
173/*
174 * Analog capture
175 */
176static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
177 struct hda_codec *codec,
178 unsigned int stream_tag,
179 unsigned int format,
180 struct snd_pcm_substream *substream)
181{
182 struct conexant_spec *spec = codec->spec;
183 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
184 stream_tag, 0, format);
185 return 0;
186}
187
188static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
189 struct hda_codec *codec,
190 struct snd_pcm_substream *substream)
191{
192 struct conexant_spec *spec = codec->spec;
888afa15 193 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
c9b443d4
TD
194 return 0;
195}
196
197
198
199static struct hda_pcm_stream conexant_pcm_analog_playback = {
200 .substreams = 1,
201 .channels_min = 2,
202 .channels_max = 2,
203 .nid = 0, /* fill later */
204 .ops = {
205 .open = conexant_playback_pcm_open,
206 .prepare = conexant_playback_pcm_prepare,
207 .cleanup = conexant_playback_pcm_cleanup
208 },
209};
210
211static struct hda_pcm_stream conexant_pcm_analog_capture = {
212 .substreams = 1,
213 .channels_min = 2,
214 .channels_max = 2,
215 .nid = 0, /* fill later */
216 .ops = {
217 .prepare = conexant_capture_pcm_prepare,
218 .cleanup = conexant_capture_pcm_cleanup
219 },
220};
221
222
223static struct hda_pcm_stream conexant_pcm_digital_playback = {
224 .substreams = 1,
225 .channels_min = 2,
226 .channels_max = 2,
227 .nid = 0, /* fill later */
228 .ops = {
229 .open = conexant_dig_playback_pcm_open,
6b97eb45
TI
230 .close = conexant_dig_playback_pcm_close,
231 .prepare = conexant_dig_playback_pcm_prepare
c9b443d4
TD
232 },
233};
234
235static struct hda_pcm_stream conexant_pcm_digital_capture = {
236 .substreams = 1,
237 .channels_min = 2,
238 .channels_max = 2,
239 /* NID is set in alc_build_pcms */
240};
241
461e2c78
TI
242static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
243 struct hda_codec *codec,
244 unsigned int stream_tag,
245 unsigned int format,
246 struct snd_pcm_substream *substream)
247{
248 struct conexant_spec *spec = codec->spec;
249 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
250 spec->cur_adc_stream_tag = stream_tag;
251 spec->cur_adc_format = format;
252 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
253 return 0;
254}
255
256static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
257 struct hda_codec *codec,
258 struct snd_pcm_substream *substream)
259{
260 struct conexant_spec *spec = codec->spec;
888afa15 261 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
461e2c78
TI
262 spec->cur_adc = 0;
263 return 0;
264}
265
266static struct hda_pcm_stream cx5051_pcm_analog_capture = {
267 .substreams = 1,
268 .channels_min = 2,
269 .channels_max = 2,
270 .nid = 0, /* fill later */
271 .ops = {
272 .prepare = cx5051_capture_pcm_prepare,
273 .cleanup = cx5051_capture_pcm_cleanup
274 },
275};
276
c9b443d4
TD
277static int conexant_build_pcms(struct hda_codec *codec)
278{
279 struct conexant_spec *spec = codec->spec;
280 struct hda_pcm *info = spec->pcm_rec;
281
282 codec->num_pcms = 1;
283 codec->pcm_info = info;
284
285 info->name = "CONEXANT Analog";
286 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
287 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
288 spec->multiout.max_channels;
289 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
290 spec->multiout.dac_nids[0];
461e2c78
TI
291 if (codec->vendor_id == 0x14f15051)
292 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
293 cx5051_pcm_analog_capture;
294 else
295 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
296 conexant_pcm_analog_capture;
c9b443d4
TD
297 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
298 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
299
300 if (spec->multiout.dig_out_nid) {
301 info++;
302 codec->num_pcms++;
303 info->name = "Conexant Digital";
7ba72ba1 304 info->pcm_type = HDA_PCM_TYPE_SPDIF;
c9b443d4
TD
305 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
306 conexant_pcm_digital_playback;
307 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
308 spec->multiout.dig_out_nid;
309 if (spec->dig_in_nid) {
310 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
311 conexant_pcm_digital_capture;
312 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
313 spec->dig_in_nid;
314 }
315 }
316
317 return 0;
318}
319
320static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
321 struct snd_ctl_elem_info *uinfo)
322{
323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
324 struct conexant_spec *spec = codec->spec;
325
326 return snd_hda_input_mux_info(spec->input_mux, uinfo);
327}
328
329static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
330 struct snd_ctl_elem_value *ucontrol)
331{
332 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
333 struct conexant_spec *spec = codec->spec;
334 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
335
336 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
337 return 0;
338}
339
340static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
341 struct snd_ctl_elem_value *ucontrol)
342{
343 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
344 struct conexant_spec *spec = codec->spec;
345 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
346
347 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
348 spec->capsrc_nids[adc_idx],
349 &spec->cur_mux[adc_idx]);
350}
351
5801f992 352#ifdef CONFIG_SND_JACK
bc7a166d
UD
353static int conexant_add_jack(struct hda_codec *codec,
354 hda_nid_t nid, int type)
355{
356 struct conexant_spec *spec;
357 struct conexant_jack *jack;
358 const char *name;
359
360 spec = codec->spec;
361 snd_array_init(&spec->jacks, sizeof(*jack), 32);
362 jack = snd_array_new(&spec->jacks);
363 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
364
365 if (!jack)
366 return -ENOMEM;
367
368 jack->nid = nid;
369 jack->type = type;
370
371 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
372}
373
374static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
375{
376 struct conexant_spec *spec = codec->spec;
377 struct conexant_jack *jacks = spec->jacks.list;
378
379 if (jacks) {
380 int i;
381 for (i = 0; i < spec->jacks.used; i++) {
382 if (jacks->nid == nid) {
383 unsigned int present;
384 present = snd_hda_codec_read(codec, nid, 0,
385 AC_VERB_GET_PIN_SENSE, 0) &
386 AC_PINSENSE_PRESENCE;
387
388 present = (present) ? jacks->type : 0 ;
389
390 snd_jack_report(jacks->jack,
391 present);
392 }
393 jacks++;
394 }
395 }
396}
397
398static int conexant_init_jacks(struct hda_codec *codec)
399{
bc7a166d
UD
400 struct conexant_spec *spec = codec->spec;
401 int i;
402
403 for (i = 0; i < spec->num_init_verbs; i++) {
404 const struct hda_verb *hv;
405
406 hv = spec->init_verbs[i];
407 while (hv->nid) {
408 int err = 0;
409 switch (hv->param ^ AC_USRSP_EN) {
410 case CONEXANT_HP_EVENT:
411 err = conexant_add_jack(codec, hv->nid,
412 SND_JACK_HEADPHONE);
413 conexant_report_jack(codec, hv->nid);
414 break;
415 case CXT5051_PORTC_EVENT:
416 case CONEXANT_MIC_EVENT:
417 err = conexant_add_jack(codec, hv->nid,
418 SND_JACK_MICROPHONE);
419 conexant_report_jack(codec, hv->nid);
420 break;
421 }
422 if (err < 0)
423 return err;
424 ++hv;
425 }
426 }
bc7a166d
UD
427 return 0;
428
429}
5801f992
TI
430#else
431static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
432{
433}
434
435static inline int conexant_init_jacks(struct hda_codec *codec)
436{
437 return 0;
438}
439#endif
bc7a166d 440
c9b443d4
TD
441static int conexant_init(struct hda_codec *codec)
442{
443 struct conexant_spec *spec = codec->spec;
444 int i;
445
446 for (i = 0; i < spec->num_init_verbs; i++)
447 snd_hda_sequence_write(codec, spec->init_verbs[i]);
448 return 0;
449}
450
451static void conexant_free(struct hda_codec *codec)
452{
bc7a166d
UD
453#ifdef CONFIG_SND_JACK
454 struct conexant_spec *spec = codec->spec;
455 if (spec->jacks.list) {
456 struct conexant_jack *jacks = spec->jacks.list;
457 int i;
458 for (i = 0; i < spec->jacks.used; i++)
459 snd_device_free(codec->bus->card, &jacks[i].jack);
460 snd_array_free(&spec->jacks);
461 }
462#endif
c9b443d4
TD
463 kfree(codec->spec);
464}
465
b880c74a
TI
466static struct snd_kcontrol_new cxt_capture_mixers[] = {
467 {
468 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
469 .name = "Capture Source",
470 .info = conexant_mux_enum_info,
471 .get = conexant_mux_enum_get,
472 .put = conexant_mux_enum_put
473 },
474 {}
475};
476
dd5746a8
TI
477static const char *slave_vols[] = {
478 "Headphone Playback Volume",
479 "Speaker Playback Volume",
480 NULL
481};
482
483static const char *slave_sws[] = {
484 "Headphone Playback Switch",
485 "Speaker Playback Switch",
486 NULL
487};
488
c9b443d4
TD
489static int conexant_build_controls(struct hda_codec *codec)
490{
491 struct conexant_spec *spec = codec->spec;
492 unsigned int i;
493 int err;
494
495 for (i = 0; i < spec->num_mixers; i++) {
496 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
497 if (err < 0)
498 return err;
499 }
500 if (spec->multiout.dig_out_nid) {
501 err = snd_hda_create_spdif_out_ctls(codec,
502 spec->multiout.dig_out_nid);
503 if (err < 0)
504 return err;
9a08160b
TI
505 err = snd_hda_create_spdif_share_sw(codec,
506 &spec->multiout);
507 if (err < 0)
508 return err;
509 spec->multiout.share_spdif = 1;
c9b443d4
TD
510 }
511 if (spec->dig_in_nid) {
512 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
513 if (err < 0)
514 return err;
515 }
dd5746a8
TI
516
517 /* if we have no master control, let's create it */
518 if (spec->vmaster_nid &&
519 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
520 unsigned int vmaster_tlv[4];
521 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
522 HDA_OUTPUT, vmaster_tlv);
523 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
524 vmaster_tlv, slave_vols);
525 if (err < 0)
526 return err;
527 }
528 if (spec->vmaster_nid &&
529 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
530 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
531 NULL, slave_sws);
532 if (err < 0)
533 return err;
534 }
535
b880c74a
TI
536 if (spec->input_mux) {
537 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
538 if (err < 0)
539 return err;
540 }
541
c9b443d4
TD
542 return 0;
543}
544
545static struct hda_codec_ops conexant_patch_ops = {
546 .build_controls = conexant_build_controls,
547 .build_pcms = conexant_build_pcms,
548 .init = conexant_init,
549 .free = conexant_free,
c9b443d4
TD
550};
551
552/*
553 * EAPD control
554 * the private value = nid | (invert << 8)
555 */
556
a5ce8890 557#define cxt_eapd_info snd_ctl_boolean_mono_info
c9b443d4 558
82f30040 559static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
c9b443d4
TD
560 struct snd_ctl_elem_value *ucontrol)
561{
562 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
563 struct conexant_spec *spec = codec->spec;
564 int invert = (kcontrol->private_value >> 8) & 1;
565 if (invert)
566 ucontrol->value.integer.value[0] = !spec->cur_eapd;
567 else
568 ucontrol->value.integer.value[0] = spec->cur_eapd;
569 return 0;
82f30040 570
c9b443d4
TD
571}
572
82f30040 573static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
c9b443d4
TD
574 struct snd_ctl_elem_value *ucontrol)
575{
576 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
577 struct conexant_spec *spec = codec->spec;
578 int invert = (kcontrol->private_value >> 8) & 1;
579 hda_nid_t nid = kcontrol->private_value & 0xff;
580 unsigned int eapd;
82f30040 581
68ea7b2f 582 eapd = !!ucontrol->value.integer.value[0];
c9b443d4
TD
583 if (invert)
584 eapd = !eapd;
82beb8fd 585 if (eapd == spec->cur_eapd)
c9b443d4 586 return 0;
82f30040 587
c9b443d4 588 spec->cur_eapd = eapd;
82beb8fd
TI
589 snd_hda_codec_write_cache(codec, nid,
590 0, AC_VERB_SET_EAPD_BTLENABLE,
591 eapd ? 0x02 : 0x00);
c9b443d4
TD
592 return 1;
593}
594
86d72bdf
TI
595/* controls for test mode */
596#ifdef CONFIG_SND_DEBUG
597
82f30040
TD
598#define CXT_EAPD_SWITCH(xname, nid, mask) \
599 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
600 .info = cxt_eapd_info, \
601 .get = cxt_eapd_get, \
602 .put = cxt_eapd_put, \
603 .private_value = nid | (mask<<16) }
604
605
606
c9b443d4
TD
607static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
608 struct snd_ctl_elem_info *uinfo)
609{
610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
611 struct conexant_spec *spec = codec->spec;
612 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
613 spec->num_channel_mode);
614}
615
616static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
617 struct snd_ctl_elem_value *ucontrol)
618{
619 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
620 struct conexant_spec *spec = codec->spec;
621 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
622 spec->num_channel_mode,
623 spec->multiout.max_channels);
624}
625
626static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
627 struct snd_ctl_elem_value *ucontrol)
628{
629 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
630 struct conexant_spec *spec = codec->spec;
631 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
632 spec->num_channel_mode,
633 &spec->multiout.max_channels);
634 if (err >= 0 && spec->need_dac_fix)
635 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
636 return err;
637}
638
639#define CXT_PIN_MODE(xname, nid, dir) \
640 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
641 .info = conexant_ch_mode_info, \
642 .get = conexant_ch_mode_get, \
643 .put = conexant_ch_mode_put, \
644 .private_value = nid | (dir<<16) }
645
86d72bdf
TI
646#endif /* CONFIG_SND_DEBUG */
647
c9b443d4
TD
648/* Conexant 5045 specific */
649
650static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
651static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
652static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
cbef9789 653#define CXT5045_SPDIF_OUT 0x18
c9b443d4 654
5cd57529
TD
655static struct hda_channel_mode cxt5045_modes[1] = {
656 { 2, NULL },
657};
c9b443d4
TD
658
659static struct hda_input_mux cxt5045_capture_source = {
660 .num_items = 2,
661 .items = {
82f30040 662 { "IntMic", 0x1 },
f4beee94 663 { "ExtMic", 0x2 },
c9b443d4
TD
664 }
665};
666
5218c892
JZ
667static struct hda_input_mux cxt5045_capture_source_benq = {
668 .num_items = 3,
669 .items = {
670 { "IntMic", 0x1 },
671 { "ExtMic", 0x2 },
672 { "LineIn", 0x3 },
673 }
674};
675
2de3c232
J
676static struct hda_input_mux cxt5045_capture_source_hp530 = {
677 .num_items = 2,
678 .items = {
679 { "ExtMic", 0x1 },
680 { "IntMic", 0x2 },
681 }
682};
683
c9b443d4
TD
684/* turn on/off EAPD (+ mute HP) as a master switch */
685static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
686 struct snd_ctl_elem_value *ucontrol)
687{
688 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
689 struct conexant_spec *spec = codec->spec;
82f30040 690 unsigned int bits;
c9b443d4 691
82f30040 692 if (!cxt_eapd_put(kcontrol, ucontrol))
c9b443d4
TD
693 return 0;
694
82f30040
TD
695 /* toggle internal speakers mute depending of presence of
696 * the headphone jack
697 */
47fd830a
TI
698 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
699 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
700 HDA_AMP_MUTE, bits);
7f29673b 701
47fd830a
TI
702 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
703 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
704 HDA_AMP_MUTE, bits);
c9b443d4
TD
705 return 1;
706}
707
708/* bind volumes of both NID 0x10 and 0x11 */
cca3b371
TI
709static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
710 .ops = &snd_hda_bind_vol,
711 .values = {
712 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
713 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
714 0
715 },
716};
c9b443d4 717
7f29673b
TD
718/* toggle input of built-in and mic jack appropriately */
719static void cxt5045_hp_automic(struct hda_codec *codec)
720{
721 static struct hda_verb mic_jack_on[] = {
722 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
723 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
724 {}
725 };
726 static struct hda_verb mic_jack_off[] = {
727 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
728 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
729 {}
730 };
731 unsigned int present;
732
733 present = snd_hda_codec_read(codec, 0x12, 0,
734 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
735 if (present)
736 snd_hda_sequence_write(codec, mic_jack_on);
737 else
738 snd_hda_sequence_write(codec, mic_jack_off);
739}
740
c9b443d4
TD
741
742/* mute internal speaker if HP is plugged */
743static void cxt5045_hp_automute(struct hda_codec *codec)
744{
82f30040 745 struct conexant_spec *spec = codec->spec;
dd87da1c 746 unsigned int bits;
c9b443d4 747
82f30040 748 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
c9b443d4 749 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
dd87da1c 750
47fd830a
TI
751 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
752 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
753 HDA_AMP_MUTE, bits);
c9b443d4
TD
754}
755
756/* unsolicited event for HP jack sensing */
757static void cxt5045_hp_unsol_event(struct hda_codec *codec,
758 unsigned int res)
759{
760 res >>= 26;
761 switch (res) {
762 case CONEXANT_HP_EVENT:
763 cxt5045_hp_automute(codec);
764 break;
7f29673b
TD
765 case CONEXANT_MIC_EVENT:
766 cxt5045_hp_automic(codec);
767 break;
768
c9b443d4
TD
769 }
770}
771
772static struct snd_kcontrol_new cxt5045_mixers[] = {
c8229c38
TI
773 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
774 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
775 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
776 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
777 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
778 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
779 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
780 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
781 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
782 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
cca3b371 783 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
c9b443d4
TD
784 {
785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
786 .name = "Master Playback Switch",
82f30040
TD
787 .info = cxt_eapd_info,
788 .get = cxt_eapd_get,
c9b443d4 789 .put = cxt5045_hp_master_sw_put,
82f30040 790 .private_value = 0x10,
c9b443d4
TD
791 },
792
793 {}
794};
795
5218c892
JZ
796static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
797 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
798 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
799 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
800 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
801
802 {}
803};
804
2de3c232 805static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
2de3c232
J
806 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
807 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
808 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
809 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
810 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
811 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
812 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
813 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
814 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
815 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
816 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
817 {
818 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
819 .name = "Master Playback Switch",
820 .info = cxt_eapd_info,
821 .get = cxt_eapd_get,
822 .put = cxt5045_hp_master_sw_put,
823 .private_value = 0x10,
824 },
825
826 {}
827};
828
c9b443d4
TD
829static struct hda_verb cxt5045_init_verbs[] = {
830 /* Line in, Mic */
4090dffb 831 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
7f29673b 832 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
c9b443d4 833 /* HP, Amp */
c8229c38
TI
834 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
835 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
836 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
837 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
838 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
839 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
840 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
841 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
842 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
82f30040 843 /* Record selector: Int mic */
7f29673b 844 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
82f30040 845 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
c9b443d4
TD
846 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
847 /* SPDIF route: PCM */
cbef9789 848 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
c9b443d4 849 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
c9b443d4 850 /* EAPD */
82f30040 851 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
c9b443d4
TD
852 { } /* end */
853};
854
5218c892
JZ
855static struct hda_verb cxt5045_benq_init_verbs[] = {
856 /* Int Mic, Mic */
857 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
858 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
859 /* Line In,HP, Amp */
860 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
861 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
862 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
863 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
864 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
865 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
866 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
867 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
868 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
869 /* Record selector: Int mic */
870 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
871 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
872 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
873 /* SPDIF route: PCM */
cbef9789 874 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5218c892
JZ
875 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
876 /* EAPD */
877 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
878 { } /* end */
879};
7f29673b
TD
880
881static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
882 /* pin sensing on HP jack */
883 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
d3091fad 884 { } /* end */
7f29673b
TD
885};
886
887static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
888 /* pin sensing on HP jack */
889 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
d3091fad 890 { } /* end */
7f29673b
TD
891};
892
c9b443d4
TD
893#ifdef CONFIG_SND_DEBUG
894/* Test configuration for debugging, modelled after the ALC260 test
895 * configuration.
896 */
897static struct hda_input_mux cxt5045_test_capture_source = {
898 .num_items = 5,
899 .items = {
900 { "MIXER", 0x0 },
901 { "MIC1 pin", 0x1 },
902 { "LINE1 pin", 0x2 },
903 { "HP-OUT pin", 0x3 },
904 { "CD pin", 0x4 },
905 },
906};
907
908static struct snd_kcontrol_new cxt5045_test_mixer[] = {
909
910 /* Output controls */
c9b443d4
TD
911 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
912 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
7f29673b
TD
913 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
914 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
915 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
916 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
c9b443d4
TD
917
918 /* Modes for retasking pin widgets */
919 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
920 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
921
82f30040
TD
922 /* EAPD Switch Control */
923 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
924
c9b443d4 925 /* Loopback mixer controls */
7f29673b
TD
926
927 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
928 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
929 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
930 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
931 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
932 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
933 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
934 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
935 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
936 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
c9b443d4
TD
937 {
938 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
939 .name = "Input Source",
940 .info = conexant_mux_enum_info,
941 .get = conexant_mux_enum_get,
942 .put = conexant_mux_enum_put,
943 },
fb3409e7
TD
944 /* Audio input controls */
945 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
946 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
947 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
948 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
949 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
950 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
951 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
952 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
953 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
954 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
c9b443d4
TD
955 { } /* end */
956};
957
958static struct hda_verb cxt5045_test_init_verbs[] = {
7f29673b
TD
959 /* Set connections */
960 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
961 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
962 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
c9b443d4
TD
963 /* Enable retasking pins as output, initially without power amp */
964 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7f29673b 965 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
c9b443d4
TD
966
967 /* Disable digital (SPDIF) pins initially, but users can enable
968 * them via a mixer switch. In the case of SPDIF-out, this initverb
969 * payload also sets the generation to 0, output to be in "consumer"
970 * PCM format, copyright asserted, no pre-emphasis and no validity
971 * control.
972 */
cbef9789
TI
973 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
974 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
c9b443d4
TD
975
976 /* Start with output sum widgets muted and their output gains at min */
977 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
978 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
979
980 /* Unmute retasking pin widget output buffers since the default
981 * state appears to be output. As the pin mode is changed by the
982 * user the pin mode control will take care of enabling the pin's
983 * input/output buffers as needed.
984 */
985 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
986 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
987
988 /* Mute capture amp left and right */
989 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
990
991 /* Set ADC connection select to match default mixer setting (mic1
992 * pin)
993 */
994 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7f29673b 995 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
c9b443d4
TD
996
997 /* Mute all inputs to mixer widget (even unconnected ones) */
998 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
999 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1000 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1001 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1002 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1003
1004 { }
1005};
1006#endif
1007
1008
1009/* initialize jack-sensing, too */
1010static int cxt5045_init(struct hda_codec *codec)
1011{
1012 conexant_init(codec);
1013 cxt5045_hp_automute(codec);
1014 return 0;
1015}
1016
1017
1018enum {
15908c36
MB
1019 CXT5045_LAPTOP_HPSENSE,
1020 CXT5045_LAPTOP_MICSENSE,
1021 CXT5045_LAPTOP_HPMICSENSE,
5218c892 1022 CXT5045_BENQ,
2de3c232 1023 CXT5045_LAPTOP_HP530,
c9b443d4
TD
1024#ifdef CONFIG_SND_DEBUG
1025 CXT5045_TEST,
1026#endif
f5fcc13c 1027 CXT5045_MODELS
c9b443d4
TD
1028};
1029
f5fcc13c 1030static const char *cxt5045_models[CXT5045_MODELS] = {
15908c36
MB
1031 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1032 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1033 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1034 [CXT5045_BENQ] = "benq",
2de3c232 1035 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
c9b443d4 1036#ifdef CONFIG_SND_DEBUG
f5fcc13c 1037 [CXT5045_TEST] = "test",
c9b443d4 1038#endif
f5fcc13c
TI
1039};
1040
1041static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
2de3c232 1042 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
dea0a509
TI
1043 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1044 CXT5045_LAPTOP_HPSENSE),
6a9dccd6 1045 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
5218c892 1046 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
15908c36
MB
1047 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1048 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
9e464154
TI
1049 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1050 CXT5045_LAPTOP_HPMICSENSE),
15908c36
MB
1051 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1052 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1053 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
dea0a509
TI
1054 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1055 CXT5045_LAPTOP_HPMICSENSE),
15908c36 1056 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
c9b443d4
TD
1057 {}
1058};
1059
1060static int patch_cxt5045(struct hda_codec *codec)
1061{
1062 struct conexant_spec *spec;
1063 int board_config;
1064
1065 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1066 if (!spec)
1067 return -ENOMEM;
c9b443d4
TD
1068 codec->spec = spec;
1069
1070 spec->multiout.max_channels = 2;
1071 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1072 spec->multiout.dac_nids = cxt5045_dac_nids;
1073 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1074 spec->num_adc_nids = 1;
1075 spec->adc_nids = cxt5045_adc_nids;
1076 spec->capsrc_nids = cxt5045_capsrc_nids;
1077 spec->input_mux = &cxt5045_capture_source;
1078 spec->num_mixers = 1;
1079 spec->mixers[0] = cxt5045_mixers;
1080 spec->num_init_verbs = 1;
1081 spec->init_verbs[0] = cxt5045_init_verbs;
1082 spec->spdif_route = 0;
5cd57529
TD
1083 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1084 spec->channel_mode = cxt5045_modes,
1085
c9b443d4
TD
1086
1087 codec->patch_ops = conexant_patch_ops;
c9b443d4 1088
f5fcc13c
TI
1089 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1090 cxt5045_models,
1091 cxt5045_cfg_tbl);
c9b443d4 1092 switch (board_config) {
15908c36 1093 case CXT5045_LAPTOP_HPSENSE:
7f29673b
TD
1094 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1095 spec->input_mux = &cxt5045_capture_source;
1096 spec->num_init_verbs = 2;
1097 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1098 spec->mixers[0] = cxt5045_mixers;
1099 codec->patch_ops.init = cxt5045_init;
1100 break;
15908c36 1101 case CXT5045_LAPTOP_MICSENSE:
86376df6 1102 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
c9b443d4
TD
1103 spec->input_mux = &cxt5045_capture_source;
1104 spec->num_init_verbs = 2;
7f29673b 1105 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
c9b443d4
TD
1106 spec->mixers[0] = cxt5045_mixers;
1107 codec->patch_ops.init = cxt5045_init;
1108 break;
15908c36
MB
1109 default:
1110 case CXT5045_LAPTOP_HPMICSENSE:
1111 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1112 spec->input_mux = &cxt5045_capture_source;
1113 spec->num_init_verbs = 3;
1114 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1115 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1116 spec->mixers[0] = cxt5045_mixers;
1117 codec->patch_ops.init = cxt5045_init;
1118 break;
5218c892
JZ
1119 case CXT5045_BENQ:
1120 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1121 spec->input_mux = &cxt5045_capture_source_benq;
1122 spec->num_init_verbs = 1;
1123 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1124 spec->mixers[0] = cxt5045_mixers;
1125 spec->mixers[1] = cxt5045_benq_mixers;
1126 spec->num_mixers = 2;
1127 codec->patch_ops.init = cxt5045_init;
1128 break;
2de3c232
J
1129 case CXT5045_LAPTOP_HP530:
1130 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1131 spec->input_mux = &cxt5045_capture_source_hp530;
1132 spec->num_init_verbs = 2;
1133 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1134 spec->mixers[0] = cxt5045_mixers_hp530;
1135 codec->patch_ops.init = cxt5045_init;
1136 break;
c9b443d4
TD
1137#ifdef CONFIG_SND_DEBUG
1138 case CXT5045_TEST:
1139 spec->input_mux = &cxt5045_test_capture_source;
1140 spec->mixers[0] = cxt5045_test_mixer;
1141 spec->init_verbs[0] = cxt5045_test_init_verbs;
15908c36
MB
1142 break;
1143
c9b443d4
TD
1144#endif
1145 }
48ecb7e8 1146
031005f7
TI
1147 switch (codec->subsystem_id >> 16) {
1148 case 0x103c:
1149 /* HP laptop has a really bad sound over 0dB on NID 0x17.
1150 * Fix max PCM level to 0 dB
1151 * (originall it has 0x2b steps with 0dB offset 0x14)
1152 */
1153 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1154 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1155 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1156 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1157 (1 << AC_AMPCAP_MUTE_SHIFT));
1158 break;
1159 }
48ecb7e8 1160
c9b443d4
TD
1161 return 0;
1162}
1163
1164
1165/* Conexant 5047 specific */
82f30040 1166#define CXT5047_SPDIF_OUT 0x11
c9b443d4 1167
5b3a7440 1168static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
c9b443d4
TD
1169static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1170static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
c9b443d4 1171
5cd57529
TD
1172static struct hda_channel_mode cxt5047_modes[1] = {
1173 { 2, NULL },
1174};
c9b443d4 1175
82f30040
TD
1176static struct hda_input_mux cxt5047_toshiba_capture_source = {
1177 .num_items = 2,
1178 .items = {
1179 { "ExtMic", 0x2 },
1180 { "Line-In", 0x1 },
c9b443d4
TD
1181 }
1182};
1183
1184/* turn on/off EAPD (+ mute HP) as a master switch */
1185static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1186 struct snd_ctl_elem_value *ucontrol)
1187{
1188 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1189 struct conexant_spec *spec = codec->spec;
82f30040 1190 unsigned int bits;
c9b443d4 1191
82f30040 1192 if (!cxt_eapd_put(kcontrol, ucontrol))
c9b443d4
TD
1193 return 0;
1194
82f30040
TD
1195 /* toggle internal speakers mute depending of presence of
1196 * the headphone jack
1197 */
47fd830a 1198 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
3b7523fc
TI
1199 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1200 * pin widgets unlike other codecs. In this case, we need to
1201 * set index 0x01 for the volume from the mixer amp 0x19.
1202 */
5d75bc55 1203 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
47fd830a
TI
1204 HDA_AMP_MUTE, bits);
1205 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1206 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1207 HDA_AMP_MUTE, bits);
c9b443d4
TD
1208 return 1;
1209}
1210
c9b443d4
TD
1211/* mute internal speaker if HP is plugged */
1212static void cxt5047_hp_automute(struct hda_codec *codec)
1213{
82f30040 1214 struct conexant_spec *spec = codec->spec;
dd87da1c 1215 unsigned int bits;
c9b443d4 1216
82f30040 1217 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
c9b443d4 1218 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
dd87da1c 1219
47fd830a 1220 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
3b7523fc 1221 /* See the note in cxt5047_hp_master_sw_put */
5d75bc55 1222 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
47fd830a 1223 HDA_AMP_MUTE, bits);
c9b443d4
TD
1224}
1225
1226/* toggle input of built-in and mic jack appropriately */
1227static void cxt5047_hp_automic(struct hda_codec *codec)
1228{
1229 static struct hda_verb mic_jack_on[] = {
9f113e0e
MB
1230 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1231 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
c9b443d4
TD
1232 {}
1233 };
1234 static struct hda_verb mic_jack_off[] = {
9f113e0e
MB
1235 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1236 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
c9b443d4
TD
1237 {}
1238 };
1239 unsigned int present;
1240
7f29673b 1241 present = snd_hda_codec_read(codec, 0x15, 0,
c9b443d4
TD
1242 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1243 if (present)
1244 snd_hda_sequence_write(codec, mic_jack_on);
1245 else
1246 snd_hda_sequence_write(codec, mic_jack_off);
1247}
1248
1249/* unsolicited event for HP jack sensing */
1250static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1251 unsigned int res)
1252{
9f113e0e 1253 switch (res >> 26) {
c9b443d4
TD
1254 case CONEXANT_HP_EVENT:
1255 cxt5047_hp_automute(codec);
1256 break;
1257 case CONEXANT_MIC_EVENT:
1258 cxt5047_hp_automic(codec);
1259 break;
1260 }
1261}
1262
df481e41
TI
1263static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1264 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1265 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1266 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
c9b443d4
TD
1267 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1268 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1269 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1270 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
82f30040
TD
1271 {
1272 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1273 .name = "Master Playback Switch",
1274 .info = cxt_eapd_info,
1275 .get = cxt_eapd_get,
c9b443d4
TD
1276 .put = cxt5047_hp_master_sw_put,
1277 .private_value = 0x13,
1278 },
1279
1280 {}
1281};
1282
df481e41 1283static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
3b7523fc 1284 /* See the note in cxt5047_hp_master_sw_put */
5d75bc55 1285 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
df481e41
TI
1286 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1287 {}
1288};
1289
1290static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
c9b443d4 1291 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
c9b443d4
TD
1292 { } /* end */
1293};
1294
1295static struct hda_verb cxt5047_init_verbs[] = {
1296 /* Line in, Mic, Built-in Mic */
1297 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1298 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1299 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
7f29673b 1300 /* HP, Speaker */
b7589ceb 1301 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
5b3a7440
TI
1302 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1303 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
7f29673b 1304 /* Record selector: Mic */
c9b443d4
TD
1305 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1306 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1307 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
7f29673b
TD
1308 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1309 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1310 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1311 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1312 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
c9b443d4
TD
1313 /* SPDIF route: PCM */
1314 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
82f30040
TD
1315 /* Enable unsolicited events */
1316 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1317 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
c9b443d4
TD
1318 { } /* end */
1319};
1320
1321/* configuration for Toshiba Laptops */
1322static struct hda_verb cxt5047_toshiba_init_verbs[] = {
3b628867 1323 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
c9b443d4
TD
1324 {}
1325};
1326
1327/* Test configuration for debugging, modelled after the ALC260 test
1328 * configuration.
1329 */
1330#ifdef CONFIG_SND_DEBUG
1331static struct hda_input_mux cxt5047_test_capture_source = {
82f30040 1332 .num_items = 4,
c9b443d4 1333 .items = {
82f30040
TD
1334 { "LINE1 pin", 0x0 },
1335 { "MIC1 pin", 0x1 },
1336 { "MIC2 pin", 0x2 },
1337 { "CD pin", 0x3 },
c9b443d4
TD
1338 },
1339};
1340
1341static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1342
1343 /* Output only controls */
82f30040
TD
1344 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1345 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1346 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1347 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
c9b443d4
TD
1348 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1349 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1350 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1351 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
82f30040
TD
1352 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1353 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1354 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1355 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
c9b443d4
TD
1356
1357 /* Modes for retasking pin widgets */
1358 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1359 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1360
82f30040
TD
1361 /* EAPD Switch Control */
1362 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
c9b443d4 1363
82f30040
TD
1364 /* Loopback mixer controls */
1365 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1366 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1367 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1368 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1369 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1370 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1371 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1372 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1373
1374 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1375 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1376 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1377 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1378 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1379 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1380 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1381 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
c9b443d4
TD
1382 {
1383 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1384 .name = "Input Source",
1385 .info = conexant_mux_enum_info,
1386 .get = conexant_mux_enum_get,
1387 .put = conexant_mux_enum_put,
1388 },
9f113e0e
MB
1389 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1390 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1391 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1392 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1393 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1394 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1395 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1396 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1397 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1398 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1399
c9b443d4
TD
1400 { } /* end */
1401};
1402
1403static struct hda_verb cxt5047_test_init_verbs[] = {
c9b443d4
TD
1404 /* Enable retasking pins as output, initially without power amp */
1405 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1406 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1407 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1408
1409 /* Disable digital (SPDIF) pins initially, but users can enable
1410 * them via a mixer switch. In the case of SPDIF-out, this initverb
1411 * payload also sets the generation to 0, output to be in "consumer"
1412 * PCM format, copyright asserted, no pre-emphasis and no validity
1413 * control.
1414 */
1415 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1416
1417 /* Ensure mic1, mic2, line1 pin widgets take input from the
1418 * OUT1 sum bus when acting as an output.
1419 */
1420 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1421 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1422
1423 /* Start with output sum widgets muted and their output gains at min */
1424 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1425 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1426
1427 /* Unmute retasking pin widget output buffers since the default
1428 * state appears to be output. As the pin mode is changed by the
1429 * user the pin mode control will take care of enabling the pin's
1430 * input/output buffers as needed.
1431 */
1432 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1433 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1434 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1435
1436 /* Mute capture amp left and right */
1437 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1438
1439 /* Set ADC connection select to match default mixer setting (mic1
1440 * pin)
1441 */
1442 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1443
1444 /* Mute all inputs to mixer widget (even unconnected ones) */
1445 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1446 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1447 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1448 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1449 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1450 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1451 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1452 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1453
1454 { }
1455};
1456#endif
1457
1458
1459/* initialize jack-sensing, too */
1460static int cxt5047_hp_init(struct hda_codec *codec)
1461{
1462 conexant_init(codec);
1463 cxt5047_hp_automute(codec);
c9b443d4
TD
1464 return 0;
1465}
1466
1467
1468enum {
f5fcc13c
TI
1469 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1470 CXT5047_LAPTOP_HP, /* Some HP laptops */
1471 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
c9b443d4
TD
1472#ifdef CONFIG_SND_DEBUG
1473 CXT5047_TEST,
1474#endif
f5fcc13c 1475 CXT5047_MODELS
c9b443d4
TD
1476};
1477
f5fcc13c
TI
1478static const char *cxt5047_models[CXT5047_MODELS] = {
1479 [CXT5047_LAPTOP] = "laptop",
1480 [CXT5047_LAPTOP_HP] = "laptop-hp",
1481 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
c9b443d4 1482#ifdef CONFIG_SND_DEBUG
f5fcc13c 1483 [CXT5047_TEST] = "test",
c9b443d4 1484#endif
f5fcc13c
TI
1485};
1486
1487static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
ac3e3741 1488 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
dea0a509
TI
1489 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1490 CXT5047_LAPTOP),
f5fcc13c 1491 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
c9b443d4
TD
1492 {}
1493};
1494
1495static int patch_cxt5047(struct hda_codec *codec)
1496{
1497 struct conexant_spec *spec;
1498 int board_config;
1499
1500 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1501 if (!spec)
1502 return -ENOMEM;
c9b443d4
TD
1503 codec->spec = spec;
1504
1505 spec->multiout.max_channels = 2;
1506 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1507 spec->multiout.dac_nids = cxt5047_dac_nids;
1508 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1509 spec->num_adc_nids = 1;
1510 spec->adc_nids = cxt5047_adc_nids;
1511 spec->capsrc_nids = cxt5047_capsrc_nids;
c9b443d4 1512 spec->num_mixers = 1;
df481e41 1513 spec->mixers[0] = cxt5047_base_mixers;
c9b443d4
TD
1514 spec->num_init_verbs = 1;
1515 spec->init_verbs[0] = cxt5047_init_verbs;
1516 spec->spdif_route = 0;
5cd57529
TD
1517 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1518 spec->channel_mode = cxt5047_modes,
c9b443d4
TD
1519
1520 codec->patch_ops = conexant_patch_ops;
c9b443d4 1521
f5fcc13c
TI
1522 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1523 cxt5047_models,
1524 cxt5047_cfg_tbl);
c9b443d4
TD
1525 switch (board_config) {
1526 case CXT5047_LAPTOP:
df481e41
TI
1527 spec->num_mixers = 2;
1528 spec->mixers[1] = cxt5047_hp_spk_mixers;
1529 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
c9b443d4
TD
1530 break;
1531 case CXT5047_LAPTOP_HP:
df481e41
TI
1532 spec->num_mixers = 2;
1533 spec->mixers[1] = cxt5047_hp_only_mixers;
fb3409e7 1534 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
c9b443d4
TD
1535 codec->patch_ops.init = cxt5047_hp_init;
1536 break;
1537 case CXT5047_LAPTOP_EAPD:
82f30040 1538 spec->input_mux = &cxt5047_toshiba_capture_source;
df481e41
TI
1539 spec->num_mixers = 2;
1540 spec->mixers[1] = cxt5047_hp_spk_mixers;
c9b443d4
TD
1541 spec->num_init_verbs = 2;
1542 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
fb3409e7 1543 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
c9b443d4
TD
1544 break;
1545#ifdef CONFIG_SND_DEBUG
1546 case CXT5047_TEST:
1547 spec->input_mux = &cxt5047_test_capture_source;
1548 spec->mixers[0] = cxt5047_test_mixer;
1549 spec->init_verbs[0] = cxt5047_test_init_verbs;
fb3409e7 1550 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
c9b443d4
TD
1551#endif
1552 }
dd5746a8 1553 spec->vmaster_nid = 0x13;
c9b443d4
TD
1554 return 0;
1555}
1556
461e2c78
TI
1557/* Conexant 5051 specific */
1558static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1559static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
461e2c78
TI
1560
1561static struct hda_channel_mode cxt5051_modes[1] = {
1562 { 2, NULL },
1563};
1564
1565static void cxt5051_update_speaker(struct hda_codec *codec)
1566{
1567 struct conexant_spec *spec = codec->spec;
1568 unsigned int pinctl;
1569 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1570 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1571 pinctl);
1572}
1573
1574/* turn on/off EAPD (+ mute HP) as a master switch */
1575static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1576 struct snd_ctl_elem_value *ucontrol)
1577{
1578 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1579
1580 if (!cxt_eapd_put(kcontrol, ucontrol))
1581 return 0;
1582 cxt5051_update_speaker(codec);
1583 return 1;
1584}
1585
1586/* toggle input of built-in and mic jack appropriately */
1587static void cxt5051_portb_automic(struct hda_codec *codec)
1588{
79d7d533 1589 struct conexant_spec *spec = codec->spec;
461e2c78
TI
1590 unsigned int present;
1591
79d7d533
TI
1592 if (spec->no_auto_mic)
1593 return;
461e2c78
TI
1594 present = snd_hda_codec_read(codec, 0x17, 0,
1595 AC_VERB_GET_PIN_SENSE, 0) &
1596 AC_PINSENSE_PRESENCE;
1597 snd_hda_codec_write(codec, 0x14, 0,
1598 AC_VERB_SET_CONNECT_SEL,
1599 present ? 0x01 : 0x00);
1600}
1601
1602/* switch the current ADC according to the jack state */
1603static void cxt5051_portc_automic(struct hda_codec *codec)
1604{
1605 struct conexant_spec *spec = codec->spec;
1606 unsigned int present;
1607 hda_nid_t new_adc;
1608
79d7d533
TI
1609 if (spec->no_auto_mic)
1610 return;
461e2c78
TI
1611 present = snd_hda_codec_read(codec, 0x18, 0,
1612 AC_VERB_GET_PIN_SENSE, 0) &
1613 AC_PINSENSE_PRESENCE;
1614 if (present)
1615 spec->cur_adc_idx = 1;
1616 else
1617 spec->cur_adc_idx = 0;
1618 new_adc = spec->adc_nids[spec->cur_adc_idx];
1619 if (spec->cur_adc && spec->cur_adc != new_adc) {
1620 /* stream is running, let's swap the current ADC */
888afa15 1621 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
461e2c78
TI
1622 spec->cur_adc = new_adc;
1623 snd_hda_codec_setup_stream(codec, new_adc,
1624 spec->cur_adc_stream_tag, 0,
1625 spec->cur_adc_format);
1626 }
1627}
1628
1629/* mute internal speaker if HP is plugged */
1630static void cxt5051_hp_automute(struct hda_codec *codec)
1631{
1632 struct conexant_spec *spec = codec->spec;
1633
1634 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1635 AC_VERB_GET_PIN_SENSE, 0) &
1636 AC_PINSENSE_PRESENCE;
1637 cxt5051_update_speaker(codec);
1638}
1639
1640/* unsolicited event for HP jack sensing */
1641static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1642 unsigned int res)
1643{
acf26c0c 1644 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
461e2c78
TI
1645 switch (res >> 26) {
1646 case CONEXANT_HP_EVENT:
1647 cxt5051_hp_automute(codec);
1648 break;
1649 case CXT5051_PORTB_EVENT:
1650 cxt5051_portb_automic(codec);
1651 break;
1652 case CXT5051_PORTC_EVENT:
1653 cxt5051_portc_automic(codec);
1654 break;
1655 }
acf26c0c 1656 conexant_report_jack(codec, nid);
461e2c78
TI
1657}
1658
1659static struct snd_kcontrol_new cxt5051_mixers[] = {
1660 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1661 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1662 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1663 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1664 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1665 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1666 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1667 {
1668 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1669 .name = "Master Playback Switch",
1670 .info = cxt_eapd_info,
1671 .get = cxt_eapd_get,
1672 .put = cxt5051_hp_master_sw_put,
1673 .private_value = 0x1a,
1674 },
1675
1676 {}
1677};
1678
1679static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1680 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1681 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1682 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1683 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1684 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1685 {
1686 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1687 .name = "Master Playback Switch",
1688 .info = cxt_eapd_info,
1689 .get = cxt_eapd_get,
1690 .put = cxt5051_hp_master_sw_put,
1691 .private_value = 0x1a,
1692 },
1693
1694 {}
1695};
1696
79d7d533
TI
1697static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1698 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
1699 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
1700 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1701 {
1702 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1703 .name = "Master Playback Switch",
1704 .info = cxt_eapd_info,
1705 .get = cxt_eapd_get,
1706 .put = cxt5051_hp_master_sw_put,
1707 .private_value = 0x1a,
1708 },
1709
1710 {}
1711};
1712
461e2c78
TI
1713static struct hda_verb cxt5051_init_verbs[] = {
1714 /* Line in, Mic */
1715 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1716 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1717 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1718 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1719 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1720 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1721 /* SPK */
1722 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1723 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1724 /* HP, Amp */
1725 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1726 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1727 /* DAC1 */
1728 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1729 /* Record selector: Int mic */
1730 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1731 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1732 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1733 /* SPDIF route: PCM */
1734 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1735 /* EAPD */
1736 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1737 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1738 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1739 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1740 { } /* end */
1741};
1742
79d7d533
TI
1743static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1744 /* Line in, Mic */
1745 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1746 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1747 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1748 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1749 /* SPK */
1750 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1751 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1752 /* HP, Amp */
1753 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1754 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1755 /* DAC1 */
1756 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1757 /* Record selector: Int mic */
1758 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1759 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1760 /* SPDIF route: PCM */
1761 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1762 /* EAPD */
1763 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1764 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1765 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1766 { } /* end */
1767};
1768
27e08988
ASRF
1769static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1770 /* Line in, Mic */
1771 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1772 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1773 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1774 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1775 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1776 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1777 /* SPK */
1778 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1779 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1780 /* HP, Amp */
1781 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1782 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1783 /* Docking HP */
1784 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1785 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1786 /* DAC1 */
1787 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1788 /* Record selector: Int mic */
1789 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1790 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1791 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1792 /* SPDIF route: PCM */
1793 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1794 /* EAPD */
1795 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1796 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1797 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1798 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1799 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1800 { } /* end */
1801};
1802
461e2c78
TI
1803/* initialize jack-sensing, too */
1804static int cxt5051_init(struct hda_codec *codec)
1805{
1806 conexant_init(codec);
acf26c0c 1807 conexant_init_jacks(codec);
461e2c78
TI
1808 if (codec->patch_ops.unsol_event) {
1809 cxt5051_hp_automute(codec);
1810 cxt5051_portb_automic(codec);
1811 cxt5051_portc_automic(codec);
1812 }
1813 return 0;
1814}
1815
1816
1817enum {
1818 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1819 CXT5051_HP, /* no docking */
79d7d533 1820 CXT5051_HP_DV6736, /* HP without mic switch */
27e08988 1821 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
461e2c78
TI
1822 CXT5051_MODELS
1823};
1824
1825static const char *cxt5051_models[CXT5051_MODELS] = {
1826 [CXT5051_LAPTOP] = "laptop",
1827 [CXT5051_HP] = "hp",
79d7d533 1828 [CXT5051_HP_DV6736] = "hp-dv6736",
27e08988 1829 [CXT5051_LENOVO_X200] = "lenovo-x200",
461e2c78
TI
1830};
1831
1832static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
79d7d533 1833 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
461e2c78
TI
1834 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1835 CXT5051_LAPTOP),
1836 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
27e08988 1837 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
461e2c78
TI
1838 {}
1839};
1840
1841static int patch_cxt5051(struct hda_codec *codec)
1842{
1843 struct conexant_spec *spec;
1844 int board_config;
1845
1846 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1847 if (!spec)
1848 return -ENOMEM;
461e2c78
TI
1849 codec->spec = spec;
1850
1851 codec->patch_ops = conexant_patch_ops;
1852 codec->patch_ops.init = cxt5051_init;
1853
1854 spec->multiout.max_channels = 2;
1855 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1856 spec->multiout.dac_nids = cxt5051_dac_nids;
1857 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1858 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1859 spec->adc_nids = cxt5051_adc_nids;
1860 spec->num_mixers = 1;
1861 spec->mixers[0] = cxt5051_mixers;
1862 spec->num_init_verbs = 1;
1863 spec->init_verbs[0] = cxt5051_init_verbs;
1864 spec->spdif_route = 0;
1865 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1866 spec->channel_mode = cxt5051_modes;
1867 spec->cur_adc = 0;
1868 spec->cur_adc_idx = 0;
1869
79d7d533
TI
1870 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1871
461e2c78
TI
1872 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1873 cxt5051_models,
1874 cxt5051_cfg_tbl);
1875 switch (board_config) {
1876 case CXT5051_HP:
461e2c78
TI
1877 spec->mixers[0] = cxt5051_hp_mixers;
1878 break;
79d7d533
TI
1879 case CXT5051_HP_DV6736:
1880 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1881 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1882 spec->no_auto_mic = 1;
1883 break;
27e08988
ASRF
1884 case CXT5051_LENOVO_X200:
1885 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
461e2c78
TI
1886 break;
1887 }
1888
1889 return 0;
1890}
1891
1892
1893/*
1894 */
1895
1289e9e8 1896static struct hda_codec_preset snd_hda_preset_conexant[] = {
82f30040
TD
1897 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1898 .patch = patch_cxt5045 },
1899 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1900 .patch = patch_cxt5047 },
461e2c78
TI
1901 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1902 .patch = patch_cxt5051 },
c9b443d4
TD
1903 {} /* terminator */
1904};
1289e9e8
TI
1905
1906MODULE_ALIAS("snd-hda-codec-id:14f15045");
1907MODULE_ALIAS("snd-hda-codec-id:14f15047");
1908MODULE_ALIAS("snd-hda-codec-id:14f15051");
1909
1910MODULE_LICENSE("GPL");
1911MODULE_DESCRIPTION("Conexant HD-audio codec");
1912
1913static struct hda_codec_preset_list conexant_list = {
1914 .preset = snd_hda_preset_conexant,
1915 .owner = THIS_MODULE,
1916};
1917
1918static int __init patch_conexant_init(void)
1919{
1920 return snd_hda_add_codec_preset(&conexant_list);
1921}
1922
1923static void __exit patch_conexant_exit(void)
1924{
1925 snd_hda_delete_codec_preset(&conexant_list);
1926}
1927
1928module_init(patch_conexant_init)
1929module_exit(patch_conexant_exit)
This page took 0.311821 seconds and 5 git commands to generate.