]> bbs.cooldavid.org Git - net-next-2.6.git/blame - sound/pci/hda/patch_conexant.c
ALSA: hda: Use olpc-xo-1_5 quirk for Toshiba Satellite Pro T130-15F
[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
c9b443d4
TD
60struct conexant_spec {
61
62 struct snd_kcontrol_new *mixers[5];
63 int num_mixers;
dd5746a8 64 hda_nid_t vmaster_nid;
c9b443d4
TD
65
66 const struct hda_verb *init_verbs[5]; /* initialization verbs
67 * don't forget NULL
68 * termination!
69 */
70 unsigned int num_init_verbs;
71
72 /* playback */
73 struct hda_multi_out multiout; /* playback set-up
74 * max_channels, dacs must be set
75 * dig_out_nid and hp_nid are optional
76 */
77 unsigned int cur_eapd;
82f30040 78 unsigned int hp_present;
faddaa5d 79 unsigned int auto_mic;
c9b443d4
TD
80 unsigned int need_dac_fix;
81
82 /* capture */
83 unsigned int num_adc_nids;
84 hda_nid_t *adc_nids;
85 hda_nid_t dig_in_nid; /* digital-in NID; optional */
86
461e2c78
TI
87 unsigned int cur_adc_idx;
88 hda_nid_t cur_adc;
89 unsigned int cur_adc_stream_tag;
90 unsigned int cur_adc_format;
91
c9b443d4
TD
92 /* capture source */
93 const struct hda_input_mux *input_mux;
94 hda_nid_t *capsrc_nids;
95 unsigned int cur_mux[3];
96
97 /* channel model */
98 const struct hda_channel_mode *channel_mode;
99 int num_channel_mode;
100
101 /* PCM information */
102 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
103
c9b443d4
TD
104 unsigned int spdif_route;
105
bc7a166d
UD
106 /* jack detection */
107 struct snd_array jacks;
108
c9b443d4
TD
109 /* dynamic controls, init_verbs and input_mux */
110 struct auto_pin_cfg autocfg;
c9b443d4 111 struct hda_input_mux private_imux;
41923e44 112 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
c9b443d4 113
0fb67e98
DD
114 unsigned int dell_automute;
115 unsigned int port_d_mode;
cfd3d8dc
GA
116 unsigned int dell_vostro:1;
117 unsigned int ideapad:1;
75f8991d
DD
118
119 unsigned int ext_mic_present;
120 unsigned int recording;
121 void (*capture_prepare)(struct hda_codec *codec);
122 void (*capture_cleanup)(struct hda_codec *codec);
c4cfe66c
DD
123
124 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
125 * through the microphone jack.
126 * When the user enables this through a mixer switch, both internal and
127 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
128 * we also allow the bias to be configured through a separate mixer
129 * control. */
130 unsigned int dc_enable;
131 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
132 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
c9b443d4
TD
133};
134
135static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
136 struct hda_codec *codec,
137 struct snd_pcm_substream *substream)
138{
139 struct conexant_spec *spec = codec->spec;
9a08160b
TI
140 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
141 hinfo);
c9b443d4
TD
142}
143
144static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
145 struct hda_codec *codec,
146 unsigned int stream_tag,
147 unsigned int format,
148 struct snd_pcm_substream *substream)
149{
150 struct conexant_spec *spec = codec->spec;
151 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
152 stream_tag,
153 format, substream);
154}
155
156static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
157 struct hda_codec *codec,
158 struct snd_pcm_substream *substream)
159{
160 struct conexant_spec *spec = codec->spec;
161 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
162}
163
164/*
165 * Digital out
166 */
167static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
168 struct hda_codec *codec,
169 struct snd_pcm_substream *substream)
170{
171 struct conexant_spec *spec = codec->spec;
172 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
173}
174
175static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
176 struct hda_codec *codec,
177 struct snd_pcm_substream *substream)
178{
179 struct conexant_spec *spec = codec->spec;
180 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
181}
182
6b97eb45
TI
183static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
184 struct hda_codec *codec,
185 unsigned int stream_tag,
186 unsigned int format,
187 struct snd_pcm_substream *substream)
188{
189 struct conexant_spec *spec = codec->spec;
190 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
191 stream_tag,
192 format, substream);
193}
194
c9b443d4
TD
195/*
196 * Analog capture
197 */
198static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
199 struct hda_codec *codec,
200 unsigned int stream_tag,
201 unsigned int format,
202 struct snd_pcm_substream *substream)
203{
204 struct conexant_spec *spec = codec->spec;
75f8991d
DD
205 if (spec->capture_prepare)
206 spec->capture_prepare(codec);
c9b443d4
TD
207 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
208 stream_tag, 0, format);
209 return 0;
210}
211
212static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
213 struct hda_codec *codec,
214 struct snd_pcm_substream *substream)
215{
216 struct conexant_spec *spec = codec->spec;
888afa15 217 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
75f8991d
DD
218 if (spec->capture_cleanup)
219 spec->capture_cleanup(codec);
c9b443d4
TD
220 return 0;
221}
222
223
224
225static struct hda_pcm_stream conexant_pcm_analog_playback = {
226 .substreams = 1,
227 .channels_min = 2,
228 .channels_max = 2,
229 .nid = 0, /* fill later */
230 .ops = {
231 .open = conexant_playback_pcm_open,
232 .prepare = conexant_playback_pcm_prepare,
233 .cleanup = conexant_playback_pcm_cleanup
234 },
235};
236
237static struct hda_pcm_stream conexant_pcm_analog_capture = {
238 .substreams = 1,
239 .channels_min = 2,
240 .channels_max = 2,
241 .nid = 0, /* fill later */
242 .ops = {
243 .prepare = conexant_capture_pcm_prepare,
244 .cleanup = conexant_capture_pcm_cleanup
245 },
246};
247
248
249static struct hda_pcm_stream conexant_pcm_digital_playback = {
250 .substreams = 1,
251 .channels_min = 2,
252 .channels_max = 2,
253 .nid = 0, /* fill later */
254 .ops = {
255 .open = conexant_dig_playback_pcm_open,
6b97eb45
TI
256 .close = conexant_dig_playback_pcm_close,
257 .prepare = conexant_dig_playback_pcm_prepare
c9b443d4
TD
258 },
259};
260
261static struct hda_pcm_stream conexant_pcm_digital_capture = {
262 .substreams = 1,
263 .channels_min = 2,
264 .channels_max = 2,
265 /* NID is set in alc_build_pcms */
266};
267
461e2c78
TI
268static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
269 struct hda_codec *codec,
270 unsigned int stream_tag,
271 unsigned int format,
272 struct snd_pcm_substream *substream)
273{
274 struct conexant_spec *spec = codec->spec;
275 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
276 spec->cur_adc_stream_tag = stream_tag;
277 spec->cur_adc_format = format;
278 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
279 return 0;
280}
281
282static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
283 struct hda_codec *codec,
284 struct snd_pcm_substream *substream)
285{
286 struct conexant_spec *spec = codec->spec;
888afa15 287 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
461e2c78
TI
288 spec->cur_adc = 0;
289 return 0;
290}
291
292static struct hda_pcm_stream cx5051_pcm_analog_capture = {
293 .substreams = 1,
294 .channels_min = 2,
295 .channels_max = 2,
296 .nid = 0, /* fill later */
297 .ops = {
298 .prepare = cx5051_capture_pcm_prepare,
299 .cleanup = cx5051_capture_pcm_cleanup
300 },
301};
302
c9b443d4
TD
303static int conexant_build_pcms(struct hda_codec *codec)
304{
305 struct conexant_spec *spec = codec->spec;
306 struct hda_pcm *info = spec->pcm_rec;
307
308 codec->num_pcms = 1;
309 codec->pcm_info = info;
310
311 info->name = "CONEXANT Analog";
312 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
313 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
314 spec->multiout.max_channels;
315 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
316 spec->multiout.dac_nids[0];
461e2c78
TI
317 if (codec->vendor_id == 0x14f15051)
318 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
319 cx5051_pcm_analog_capture;
320 else
321 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
322 conexant_pcm_analog_capture;
c9b443d4
TD
323 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
324 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
325
326 if (spec->multiout.dig_out_nid) {
327 info++;
328 codec->num_pcms++;
329 info->name = "Conexant Digital";
7ba72ba1 330 info->pcm_type = HDA_PCM_TYPE_SPDIF;
c9b443d4
TD
331 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
332 conexant_pcm_digital_playback;
333 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
334 spec->multiout.dig_out_nid;
335 if (spec->dig_in_nid) {
336 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
337 conexant_pcm_digital_capture;
338 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
339 spec->dig_in_nid;
340 }
341 }
342
343 return 0;
344}
345
346static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
347 struct snd_ctl_elem_info *uinfo)
348{
349 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
350 struct conexant_spec *spec = codec->spec;
351
352 return snd_hda_input_mux_info(spec->input_mux, uinfo);
353}
354
355static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
356 struct snd_ctl_elem_value *ucontrol)
357{
358 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
359 struct conexant_spec *spec = codec->spec;
360 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
361
362 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
363 return 0;
364}
365
366static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
367 struct snd_ctl_elem_value *ucontrol)
368{
369 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
370 struct conexant_spec *spec = codec->spec;
371 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
372
373 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
374 spec->capsrc_nids[adc_idx],
375 &spec->cur_mux[adc_idx]);
376}
377
8c8145b8 378#ifdef CONFIG_SND_HDA_INPUT_JACK
95c09099
TI
379static void conexant_free_jack_priv(struct snd_jack *jack)
380{
381 struct conexant_jack *jacks = jack->private_data;
382 jacks->nid = 0;
383 jacks->jack = NULL;
384}
385
bc7a166d
UD
386static int conexant_add_jack(struct hda_codec *codec,
387 hda_nid_t nid, int type)
388{
389 struct conexant_spec *spec;
390 struct conexant_jack *jack;
391 const char *name;
95c09099 392 int err;
bc7a166d
UD
393
394 spec = codec->spec;
395 snd_array_init(&spec->jacks, sizeof(*jack), 32);
396 jack = snd_array_new(&spec->jacks);
397 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
398
399 if (!jack)
400 return -ENOMEM;
401
402 jack->nid = nid;
403 jack->type = type;
404
95c09099
TI
405 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
406 if (err < 0)
407 return err;
408 jack->jack->private_data = jack;
409 jack->jack->private_free = conexant_free_jack_priv;
410 return 0;
bc7a166d
UD
411}
412
413static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
414{
415 struct conexant_spec *spec = codec->spec;
416 struct conexant_jack *jacks = spec->jacks.list;
417
418 if (jacks) {
419 int i;
420 for (i = 0; i < spec->jacks.used; i++) {
421 if (jacks->nid == nid) {
422 unsigned int present;
d56757ab 423 present = snd_hda_jack_detect(codec, nid);
bc7a166d
UD
424
425 present = (present) ? jacks->type : 0 ;
426
427 snd_jack_report(jacks->jack,
428 present);
429 }
430 jacks++;
431 }
432 }
433}
434
435static int conexant_init_jacks(struct hda_codec *codec)
436{
bc7a166d
UD
437 struct conexant_spec *spec = codec->spec;
438 int i;
439
440 for (i = 0; i < spec->num_init_verbs; i++) {
441 const struct hda_verb *hv;
442
443 hv = spec->init_verbs[i];
444 while (hv->nid) {
445 int err = 0;
446 switch (hv->param ^ AC_USRSP_EN) {
447 case CONEXANT_HP_EVENT:
448 err = conexant_add_jack(codec, hv->nid,
449 SND_JACK_HEADPHONE);
450 conexant_report_jack(codec, hv->nid);
451 break;
452 case CXT5051_PORTC_EVENT:
453 case CONEXANT_MIC_EVENT:
454 err = conexant_add_jack(codec, hv->nid,
455 SND_JACK_MICROPHONE);
456 conexant_report_jack(codec, hv->nid);
457 break;
458 }
459 if (err < 0)
460 return err;
461 ++hv;
462 }
463 }
bc7a166d
UD
464 return 0;
465
466}
5801f992
TI
467#else
468static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
469{
470}
471
472static inline int conexant_init_jacks(struct hda_codec *codec)
473{
474 return 0;
475}
476#endif
bc7a166d 477
c9b443d4
TD
478static int conexant_init(struct hda_codec *codec)
479{
480 struct conexant_spec *spec = codec->spec;
481 int i;
482
483 for (i = 0; i < spec->num_init_verbs; i++)
484 snd_hda_sequence_write(codec, spec->init_verbs[i]);
485 return 0;
486}
487
488static void conexant_free(struct hda_codec *codec)
489{
8c8145b8 490#ifdef CONFIG_SND_HDA_INPUT_JACK
bc7a166d
UD
491 struct conexant_spec *spec = codec->spec;
492 if (spec->jacks.list) {
493 struct conexant_jack *jacks = spec->jacks.list;
494 int i;
95c09099
TI
495 for (i = 0; i < spec->jacks.used; i++, jacks++) {
496 if (jacks->jack)
497 snd_device_free(codec->bus->card, jacks->jack);
498 }
bc7a166d
UD
499 snd_array_free(&spec->jacks);
500 }
501#endif
c0f8faf0 502 snd_hda_detach_beep_device(codec);
c9b443d4
TD
503 kfree(codec->spec);
504}
505
b880c74a
TI
506static struct snd_kcontrol_new cxt_capture_mixers[] = {
507 {
508 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
509 .name = "Capture Source",
510 .info = conexant_mux_enum_info,
511 .get = conexant_mux_enum_get,
512 .put = conexant_mux_enum_put
513 },
514 {}
515};
516
dd5746a8
TI
517static const char *slave_vols[] = {
518 "Headphone Playback Volume",
519 "Speaker Playback Volume",
520 NULL
521};
522
523static const char *slave_sws[] = {
524 "Headphone Playback Switch",
525 "Speaker Playback Switch",
526 NULL
527};
528
c9b443d4
TD
529static int conexant_build_controls(struct hda_codec *codec)
530{
531 struct conexant_spec *spec = codec->spec;
532 unsigned int i;
533 int err;
534
535 for (i = 0; i < spec->num_mixers; i++) {
536 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
537 if (err < 0)
538 return err;
539 }
540 if (spec->multiout.dig_out_nid) {
541 err = snd_hda_create_spdif_out_ctls(codec,
542 spec->multiout.dig_out_nid);
543 if (err < 0)
544 return err;
9a08160b
TI
545 err = snd_hda_create_spdif_share_sw(codec,
546 &spec->multiout);
547 if (err < 0)
548 return err;
549 spec->multiout.share_spdif = 1;
c9b443d4
TD
550 }
551 if (spec->dig_in_nid) {
552 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
553 if (err < 0)
554 return err;
555 }
dd5746a8
TI
556
557 /* if we have no master control, let's create it */
558 if (spec->vmaster_nid &&
559 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
560 unsigned int vmaster_tlv[4];
561 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
562 HDA_OUTPUT, vmaster_tlv);
563 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
564 vmaster_tlv, slave_vols);
565 if (err < 0)
566 return err;
567 }
568 if (spec->vmaster_nid &&
569 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
570 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
571 NULL, slave_sws);
572 if (err < 0)
573 return err;
574 }
575
b880c74a
TI
576 if (spec->input_mux) {
577 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
578 if (err < 0)
579 return err;
580 }
581
c9b443d4
TD
582 return 0;
583}
584
585static struct hda_codec_ops conexant_patch_ops = {
586 .build_controls = conexant_build_controls,
587 .build_pcms = conexant_build_pcms,
588 .init = conexant_init,
589 .free = conexant_free,
c9b443d4
TD
590};
591
592/*
593 * EAPD control
594 * the private value = nid | (invert << 8)
595 */
596
a5ce8890 597#define cxt_eapd_info snd_ctl_boolean_mono_info
c9b443d4 598
82f30040 599static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
c9b443d4
TD
600 struct snd_ctl_elem_value *ucontrol)
601{
602 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
603 struct conexant_spec *spec = codec->spec;
604 int invert = (kcontrol->private_value >> 8) & 1;
605 if (invert)
606 ucontrol->value.integer.value[0] = !spec->cur_eapd;
607 else
608 ucontrol->value.integer.value[0] = spec->cur_eapd;
609 return 0;
82f30040 610
c9b443d4
TD
611}
612
82f30040 613static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
c9b443d4
TD
614 struct snd_ctl_elem_value *ucontrol)
615{
616 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
617 struct conexant_spec *spec = codec->spec;
618 int invert = (kcontrol->private_value >> 8) & 1;
619 hda_nid_t nid = kcontrol->private_value & 0xff;
620 unsigned int eapd;
82f30040 621
68ea7b2f 622 eapd = !!ucontrol->value.integer.value[0];
c9b443d4
TD
623 if (invert)
624 eapd = !eapd;
82beb8fd 625 if (eapd == spec->cur_eapd)
c9b443d4 626 return 0;
82f30040 627
c9b443d4 628 spec->cur_eapd = eapd;
82beb8fd
TI
629 snd_hda_codec_write_cache(codec, nid,
630 0, AC_VERB_SET_EAPD_BTLENABLE,
631 eapd ? 0x02 : 0x00);
c9b443d4
TD
632 return 1;
633}
634
86d72bdf
TI
635/* controls for test mode */
636#ifdef CONFIG_SND_DEBUG
637
82f30040
TD
638#define CXT_EAPD_SWITCH(xname, nid, mask) \
639 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
640 .info = cxt_eapd_info, \
641 .get = cxt_eapd_get, \
642 .put = cxt_eapd_put, \
643 .private_value = nid | (mask<<16) }
644
645
646
c9b443d4
TD
647static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
648 struct snd_ctl_elem_info *uinfo)
649{
650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
651 struct conexant_spec *spec = codec->spec;
652 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
653 spec->num_channel_mode);
654}
655
656static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
657 struct snd_ctl_elem_value *ucontrol)
658{
659 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
660 struct conexant_spec *spec = codec->spec;
661 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
662 spec->num_channel_mode,
663 spec->multiout.max_channels);
664}
665
666static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
667 struct snd_ctl_elem_value *ucontrol)
668{
669 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670 struct conexant_spec *spec = codec->spec;
671 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
672 spec->num_channel_mode,
673 &spec->multiout.max_channels);
674 if (err >= 0 && spec->need_dac_fix)
675 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
676 return err;
677}
678
679#define CXT_PIN_MODE(xname, nid, dir) \
680 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
681 .info = conexant_ch_mode_info, \
682 .get = conexant_ch_mode_get, \
683 .put = conexant_ch_mode_put, \
684 .private_value = nid | (dir<<16) }
685
86d72bdf
TI
686#endif /* CONFIG_SND_DEBUG */
687
c9b443d4
TD
688/* Conexant 5045 specific */
689
690static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
691static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
692static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
cbef9789 693#define CXT5045_SPDIF_OUT 0x18
c9b443d4 694
5cd57529
TD
695static struct hda_channel_mode cxt5045_modes[1] = {
696 { 2, NULL },
697};
c9b443d4
TD
698
699static struct hda_input_mux cxt5045_capture_source = {
700 .num_items = 2,
701 .items = {
82f30040 702 { "IntMic", 0x1 },
f4beee94 703 { "ExtMic", 0x2 },
c9b443d4
TD
704 }
705};
706
5218c892 707static struct hda_input_mux cxt5045_capture_source_benq = {
22e14130 708 .num_items = 5,
5218c892
JZ
709 .items = {
710 { "IntMic", 0x1 },
711 { "ExtMic", 0x2 },
712 { "LineIn", 0x3 },
22e14130
LM
713 { "CD", 0x4 },
714 { "Mixer", 0x0 },
5218c892
JZ
715 }
716};
717
2de3c232
J
718static struct hda_input_mux cxt5045_capture_source_hp530 = {
719 .num_items = 2,
720 .items = {
721 { "ExtMic", 0x1 },
722 { "IntMic", 0x2 },
723 }
724};
725
c9b443d4
TD
726/* turn on/off EAPD (+ mute HP) as a master switch */
727static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
728 struct snd_ctl_elem_value *ucontrol)
729{
730 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
731 struct conexant_spec *spec = codec->spec;
82f30040 732 unsigned int bits;
c9b443d4 733
82f30040 734 if (!cxt_eapd_put(kcontrol, ucontrol))
c9b443d4
TD
735 return 0;
736
82f30040
TD
737 /* toggle internal speakers mute depending of presence of
738 * the headphone jack
739 */
47fd830a
TI
740 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
741 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
742 HDA_AMP_MUTE, bits);
7f29673b 743
47fd830a
TI
744 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
745 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
746 HDA_AMP_MUTE, bits);
c9b443d4
TD
747 return 1;
748}
749
750/* bind volumes of both NID 0x10 and 0x11 */
cca3b371
TI
751static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
752 .ops = &snd_hda_bind_vol,
753 .values = {
754 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
755 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
756 0
757 },
758};
c9b443d4 759
7f29673b
TD
760/* toggle input of built-in and mic jack appropriately */
761static void cxt5045_hp_automic(struct hda_codec *codec)
762{
763 static struct hda_verb mic_jack_on[] = {
764 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
765 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
766 {}
767 };
768 static struct hda_verb mic_jack_off[] = {
769 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
770 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
771 {}
772 };
773 unsigned int present;
774
d56757ab 775 present = snd_hda_jack_detect(codec, 0x12);
7f29673b
TD
776 if (present)
777 snd_hda_sequence_write(codec, mic_jack_on);
778 else
779 snd_hda_sequence_write(codec, mic_jack_off);
780}
781
c9b443d4
TD
782
783/* mute internal speaker if HP is plugged */
784static void cxt5045_hp_automute(struct hda_codec *codec)
785{
82f30040 786 struct conexant_spec *spec = codec->spec;
dd87da1c 787 unsigned int bits;
c9b443d4 788
d56757ab 789 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
dd87da1c 790
47fd830a
TI
791 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
792 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
793 HDA_AMP_MUTE, bits);
c9b443d4
TD
794}
795
796/* unsolicited event for HP jack sensing */
797static void cxt5045_hp_unsol_event(struct hda_codec *codec,
798 unsigned int res)
799{
800 res >>= 26;
801 switch (res) {
802 case CONEXANT_HP_EVENT:
803 cxt5045_hp_automute(codec);
804 break;
7f29673b
TD
805 case CONEXANT_MIC_EVENT:
806 cxt5045_hp_automic(codec);
807 break;
808
c9b443d4
TD
809 }
810}
811
812static struct snd_kcontrol_new cxt5045_mixers[] = {
c8229c38
TI
813 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
814 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
815 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
816 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
817 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
818 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
819 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
820 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
821 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
822 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
cca3b371 823 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
c9b443d4
TD
824 {
825 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
826 .name = "Master Playback Switch",
82f30040
TD
827 .info = cxt_eapd_info,
828 .get = cxt_eapd_get,
c9b443d4 829 .put = cxt5045_hp_master_sw_put,
82f30040 830 .private_value = 0x10,
c9b443d4
TD
831 },
832
833 {}
834};
835
5218c892 836static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
22e14130
LM
837 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
838 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
839 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
840 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
841
5218c892
JZ
842 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
843 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
844 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
845 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
846
22e14130
LM
847 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
848 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
849
5218c892
JZ
850 {}
851};
852
2de3c232 853static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
2de3c232
J
854 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
855 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
856 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
857 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
858 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
859 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
860 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
861 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
862 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
863 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
864 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
865 {
866 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
867 .name = "Master Playback Switch",
868 .info = cxt_eapd_info,
869 .get = cxt_eapd_get,
870 .put = cxt5045_hp_master_sw_put,
871 .private_value = 0x10,
872 },
873
874 {}
875};
876
c9b443d4
TD
877static struct hda_verb cxt5045_init_verbs[] = {
878 /* Line in, Mic */
4090dffb 879 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
7f29673b 880 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
c9b443d4 881 /* HP, Amp */
c8229c38
TI
882 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
883 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
884 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
885 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
886 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
887 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
888 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
889 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
890 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
82f30040 891 /* Record selector: Int mic */
7f29673b 892 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
82f30040 893 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
c9b443d4
TD
894 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
895 /* SPDIF route: PCM */
cbef9789 896 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
c9b443d4 897 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
c9b443d4 898 /* EAPD */
82f30040 899 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
c9b443d4
TD
900 { } /* end */
901};
902
5218c892
JZ
903static struct hda_verb cxt5045_benq_init_verbs[] = {
904 /* Int Mic, Mic */
905 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
906 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
907 /* Line In,HP, Amp */
908 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
909 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
910 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
911 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
912 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
913 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
914 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
915 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
916 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
917 /* Record selector: Int mic */
918 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
919 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
920 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
921 /* SPDIF route: PCM */
cbef9789 922 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5218c892
JZ
923 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
924 /* EAPD */
925 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
926 { } /* end */
927};
7f29673b
TD
928
929static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
930 /* pin sensing on HP jack */
931 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
d3091fad 932 { } /* end */
7f29673b
TD
933};
934
935static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
936 /* pin sensing on HP jack */
937 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
d3091fad 938 { } /* end */
7f29673b
TD
939};
940
c9b443d4
TD
941#ifdef CONFIG_SND_DEBUG
942/* Test configuration for debugging, modelled after the ALC260 test
943 * configuration.
944 */
945static struct hda_input_mux cxt5045_test_capture_source = {
946 .num_items = 5,
947 .items = {
948 { "MIXER", 0x0 },
949 { "MIC1 pin", 0x1 },
950 { "LINE1 pin", 0x2 },
951 { "HP-OUT pin", 0x3 },
952 { "CD pin", 0x4 },
953 },
954};
955
956static struct snd_kcontrol_new cxt5045_test_mixer[] = {
957
958 /* Output controls */
c9b443d4
TD
959 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
960 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
7f29673b
TD
961 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
962 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
963 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
964 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
c9b443d4
TD
965
966 /* Modes for retasking pin widgets */
967 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
968 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
969
82f30040
TD
970 /* EAPD Switch Control */
971 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
972
c9b443d4 973 /* Loopback mixer controls */
7f29673b
TD
974
975 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
976 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
977 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
978 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
979 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
980 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
981 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
982 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
983 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
984 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
c9b443d4
TD
985 {
986 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
987 .name = "Input Source",
988 .info = conexant_mux_enum_info,
989 .get = conexant_mux_enum_get,
990 .put = conexant_mux_enum_put,
991 },
fb3409e7
TD
992 /* Audio input controls */
993 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
994 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
995 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
996 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
997 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
998 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
999 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1000 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1001 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1002 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
c9b443d4
TD
1003 { } /* end */
1004};
1005
1006static struct hda_verb cxt5045_test_init_verbs[] = {
7f29673b
TD
1007 /* Set connections */
1008 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1009 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1010 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
c9b443d4
TD
1011 /* Enable retasking pins as output, initially without power amp */
1012 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7f29673b 1013 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
c9b443d4
TD
1014
1015 /* Disable digital (SPDIF) pins initially, but users can enable
1016 * them via a mixer switch. In the case of SPDIF-out, this initverb
1017 * payload also sets the generation to 0, output to be in "consumer"
1018 * PCM format, copyright asserted, no pre-emphasis and no validity
1019 * control.
1020 */
cbef9789
TI
1021 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1022 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
c9b443d4
TD
1023
1024 /* Start with output sum widgets muted and their output gains at min */
1025 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1026 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1027
1028 /* Unmute retasking pin widget output buffers since the default
1029 * state appears to be output. As the pin mode is changed by the
1030 * user the pin mode control will take care of enabling the pin's
1031 * input/output buffers as needed.
1032 */
1033 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1034 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1035
1036 /* Mute capture amp left and right */
1037 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1038
1039 /* Set ADC connection select to match default mixer setting (mic1
1040 * pin)
1041 */
1042 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7f29673b 1043 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
c9b443d4
TD
1044
1045 /* Mute all inputs to mixer widget (even unconnected ones) */
1046 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1047 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1048 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1049 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1050 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1051
1052 { }
1053};
1054#endif
1055
1056
1057/* initialize jack-sensing, too */
1058static int cxt5045_init(struct hda_codec *codec)
1059{
1060 conexant_init(codec);
1061 cxt5045_hp_automute(codec);
1062 return 0;
1063}
1064
1065
1066enum {
15908c36
MB
1067 CXT5045_LAPTOP_HPSENSE,
1068 CXT5045_LAPTOP_MICSENSE,
1069 CXT5045_LAPTOP_HPMICSENSE,
5218c892 1070 CXT5045_BENQ,
2de3c232 1071 CXT5045_LAPTOP_HP530,
c9b443d4
TD
1072#ifdef CONFIG_SND_DEBUG
1073 CXT5045_TEST,
1074#endif
f5fcc13c 1075 CXT5045_MODELS
c9b443d4
TD
1076};
1077
f5fcc13c 1078static const char *cxt5045_models[CXT5045_MODELS] = {
15908c36
MB
1079 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1080 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1081 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1082 [CXT5045_BENQ] = "benq",
2de3c232 1083 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
c9b443d4 1084#ifdef CONFIG_SND_DEBUG
f5fcc13c 1085 [CXT5045_TEST] = "test",
c9b443d4 1086#endif
f5fcc13c
TI
1087};
1088
1089static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
2de3c232 1090 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
dea0a509
TI
1091 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1092 CXT5045_LAPTOP_HPSENSE),
6a9dccd6 1093 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
5218c892 1094 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
15908c36
MB
1095 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1096 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
9e464154
TI
1097 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1098 CXT5045_LAPTOP_HPMICSENSE),
15908c36
MB
1099 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1100 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1101 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
dea0a509
TI
1102 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1103 CXT5045_LAPTOP_HPMICSENSE),
15908c36 1104 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
c9b443d4
TD
1105 {}
1106};
1107
1108static int patch_cxt5045(struct hda_codec *codec)
1109{
1110 struct conexant_spec *spec;
1111 int board_config;
1112
1113 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1114 if (!spec)
1115 return -ENOMEM;
c9b443d4 1116 codec->spec = spec;
9421f954 1117 codec->pin_amp_workaround = 1;
c9b443d4
TD
1118
1119 spec->multiout.max_channels = 2;
1120 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1121 spec->multiout.dac_nids = cxt5045_dac_nids;
1122 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1123 spec->num_adc_nids = 1;
1124 spec->adc_nids = cxt5045_adc_nids;
1125 spec->capsrc_nids = cxt5045_capsrc_nids;
1126 spec->input_mux = &cxt5045_capture_source;
1127 spec->num_mixers = 1;
1128 spec->mixers[0] = cxt5045_mixers;
1129 spec->num_init_verbs = 1;
1130 spec->init_verbs[0] = cxt5045_init_verbs;
1131 spec->spdif_route = 0;
5cd57529
TD
1132 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1133 spec->channel_mode = cxt5045_modes,
1134
c9b443d4
TD
1135
1136 codec->patch_ops = conexant_patch_ops;
c9b443d4 1137
f5fcc13c
TI
1138 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1139 cxt5045_models,
1140 cxt5045_cfg_tbl);
c9b443d4 1141 switch (board_config) {
15908c36 1142 case CXT5045_LAPTOP_HPSENSE:
7f29673b
TD
1143 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1144 spec->input_mux = &cxt5045_capture_source;
1145 spec->num_init_verbs = 2;
1146 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1147 spec->mixers[0] = cxt5045_mixers;
1148 codec->patch_ops.init = cxt5045_init;
1149 break;
15908c36 1150 case CXT5045_LAPTOP_MICSENSE:
86376df6 1151 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
c9b443d4
TD
1152 spec->input_mux = &cxt5045_capture_source;
1153 spec->num_init_verbs = 2;
7f29673b 1154 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
c9b443d4
TD
1155 spec->mixers[0] = cxt5045_mixers;
1156 codec->patch_ops.init = cxt5045_init;
1157 break;
15908c36
MB
1158 default:
1159 case CXT5045_LAPTOP_HPMICSENSE:
1160 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1161 spec->input_mux = &cxt5045_capture_source;
1162 spec->num_init_verbs = 3;
1163 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1164 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1165 spec->mixers[0] = cxt5045_mixers;
1166 codec->patch_ops.init = cxt5045_init;
1167 break;
5218c892
JZ
1168 case CXT5045_BENQ:
1169 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1170 spec->input_mux = &cxt5045_capture_source_benq;
1171 spec->num_init_verbs = 1;
1172 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1173 spec->mixers[0] = cxt5045_mixers;
1174 spec->mixers[1] = cxt5045_benq_mixers;
1175 spec->num_mixers = 2;
1176 codec->patch_ops.init = cxt5045_init;
1177 break;
2de3c232
J
1178 case CXT5045_LAPTOP_HP530:
1179 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1180 spec->input_mux = &cxt5045_capture_source_hp530;
1181 spec->num_init_verbs = 2;
1182 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1183 spec->mixers[0] = cxt5045_mixers_hp530;
1184 codec->patch_ops.init = cxt5045_init;
1185 break;
c9b443d4
TD
1186#ifdef CONFIG_SND_DEBUG
1187 case CXT5045_TEST:
1188 spec->input_mux = &cxt5045_test_capture_source;
1189 spec->mixers[0] = cxt5045_test_mixer;
1190 spec->init_verbs[0] = cxt5045_test_init_verbs;
15908c36
MB
1191 break;
1192
c9b443d4
TD
1193#endif
1194 }
48ecb7e8 1195
031005f7
TI
1196 switch (codec->subsystem_id >> 16) {
1197 case 0x103c:
0b587fc4
DC
1198 case 0x1734:
1199 /* HP & Fujitsu-Siemens laptops have really bad sound over 0dB
1200 * on NID 0x17. Fix max PCM level to 0 dB
1201 * (originally it has 0x2b steps with 0dB offset 0x14)
031005f7
TI
1202 */
1203 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1204 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1205 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1206 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1207 (1 << AC_AMPCAP_MUTE_SHIFT));
1208 break;
1209 }
48ecb7e8 1210
c9b443d4
TD
1211 return 0;
1212}
1213
1214
1215/* Conexant 5047 specific */
82f30040 1216#define CXT5047_SPDIF_OUT 0x11
c9b443d4 1217
5b3a7440 1218static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
c9b443d4
TD
1219static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1220static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
c9b443d4 1221
5cd57529
TD
1222static struct hda_channel_mode cxt5047_modes[1] = {
1223 { 2, NULL },
1224};
c9b443d4 1225
82f30040
TD
1226static struct hda_input_mux cxt5047_toshiba_capture_source = {
1227 .num_items = 2,
1228 .items = {
1229 { "ExtMic", 0x2 },
1230 { "Line-In", 0x1 },
c9b443d4
TD
1231 }
1232};
1233
1234/* turn on/off EAPD (+ mute HP) as a master switch */
1235static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1236 struct snd_ctl_elem_value *ucontrol)
1237{
1238 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1239 struct conexant_spec *spec = codec->spec;
82f30040 1240 unsigned int bits;
c9b443d4 1241
82f30040 1242 if (!cxt_eapd_put(kcontrol, ucontrol))
c9b443d4
TD
1243 return 0;
1244
82f30040
TD
1245 /* toggle internal speakers mute depending of presence of
1246 * the headphone jack
1247 */
47fd830a 1248 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
3b7523fc
TI
1249 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1250 * pin widgets unlike other codecs. In this case, we need to
1251 * set index 0x01 for the volume from the mixer amp 0x19.
1252 */
5d75bc55 1253 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
47fd830a
TI
1254 HDA_AMP_MUTE, bits);
1255 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1256 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1257 HDA_AMP_MUTE, bits);
c9b443d4
TD
1258 return 1;
1259}
1260
c9b443d4
TD
1261/* mute internal speaker if HP is plugged */
1262static void cxt5047_hp_automute(struct hda_codec *codec)
1263{
82f30040 1264 struct conexant_spec *spec = codec->spec;
dd87da1c 1265 unsigned int bits;
c9b443d4 1266
d56757ab 1267 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
dd87da1c 1268
47fd830a 1269 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
3b7523fc 1270 /* See the note in cxt5047_hp_master_sw_put */
5d75bc55 1271 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
47fd830a 1272 HDA_AMP_MUTE, bits);
c9b443d4
TD
1273}
1274
1275/* toggle input of built-in and mic jack appropriately */
1276static void cxt5047_hp_automic(struct hda_codec *codec)
1277{
1278 static struct hda_verb mic_jack_on[] = {
9f113e0e
MB
1279 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1280 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
c9b443d4
TD
1281 {}
1282 };
1283 static struct hda_verb mic_jack_off[] = {
9f113e0e
MB
1284 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1285 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
c9b443d4
TD
1286 {}
1287 };
1288 unsigned int present;
1289
d56757ab 1290 present = snd_hda_jack_detect(codec, 0x15);
c9b443d4
TD
1291 if (present)
1292 snd_hda_sequence_write(codec, mic_jack_on);
1293 else
1294 snd_hda_sequence_write(codec, mic_jack_off);
1295}
1296
1297/* unsolicited event for HP jack sensing */
1298static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1299 unsigned int res)
1300{
9f113e0e 1301 switch (res >> 26) {
c9b443d4
TD
1302 case CONEXANT_HP_EVENT:
1303 cxt5047_hp_automute(codec);
1304 break;
1305 case CONEXANT_MIC_EVENT:
1306 cxt5047_hp_automic(codec);
1307 break;
1308 }
1309}
1310
df481e41
TI
1311static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1312 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1313 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1314 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
c9b443d4
TD
1315 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1316 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1317 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1318 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
82f30040
TD
1319 {
1320 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1321 .name = "Master Playback Switch",
1322 .info = cxt_eapd_info,
1323 .get = cxt_eapd_get,
c9b443d4
TD
1324 .put = cxt5047_hp_master_sw_put,
1325 .private_value = 0x13,
1326 },
1327
1328 {}
1329};
1330
df481e41 1331static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
3b7523fc 1332 /* See the note in cxt5047_hp_master_sw_put */
5d75bc55 1333 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
df481e41
TI
1334 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1335 {}
1336};
1337
1338static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
c9b443d4 1339 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
c9b443d4
TD
1340 { } /* end */
1341};
1342
1343static struct hda_verb cxt5047_init_verbs[] = {
1344 /* Line in, Mic, Built-in Mic */
1345 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1346 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1347 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
7f29673b 1348 /* HP, Speaker */
b7589ceb 1349 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
5b3a7440
TI
1350 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1351 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
7f29673b 1352 /* Record selector: Mic */
c9b443d4
TD
1353 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1354 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1355 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
7f29673b
TD
1356 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1357 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1358 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1359 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1360 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
c9b443d4
TD
1361 /* SPDIF route: PCM */
1362 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
82f30040
TD
1363 /* Enable unsolicited events */
1364 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1365 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
c9b443d4
TD
1366 { } /* end */
1367};
1368
1369/* configuration for Toshiba Laptops */
1370static struct hda_verb cxt5047_toshiba_init_verbs[] = {
3b628867 1371 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
c9b443d4
TD
1372 {}
1373};
1374
1375/* Test configuration for debugging, modelled after the ALC260 test
1376 * configuration.
1377 */
1378#ifdef CONFIG_SND_DEBUG
1379static struct hda_input_mux cxt5047_test_capture_source = {
82f30040 1380 .num_items = 4,
c9b443d4 1381 .items = {
82f30040
TD
1382 { "LINE1 pin", 0x0 },
1383 { "MIC1 pin", 0x1 },
1384 { "MIC2 pin", 0x2 },
1385 { "CD pin", 0x3 },
c9b443d4
TD
1386 },
1387};
1388
1389static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1390
1391 /* Output only controls */
82f30040
TD
1392 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1393 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1394 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1395 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
c9b443d4
TD
1396 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1397 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1398 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1399 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
82f30040
TD
1400 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1401 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1402 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1403 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
c9b443d4
TD
1404
1405 /* Modes for retasking pin widgets */
1406 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1407 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1408
82f30040
TD
1409 /* EAPD Switch Control */
1410 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
c9b443d4 1411
82f30040
TD
1412 /* Loopback mixer controls */
1413 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1414 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1415 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1416 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1417 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1418 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1419 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1420 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1421
1422 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1423 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1424 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1425 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1426 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1427 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1428 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1429 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
c9b443d4
TD
1430 {
1431 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1432 .name = "Input Source",
1433 .info = conexant_mux_enum_info,
1434 .get = conexant_mux_enum_get,
1435 .put = conexant_mux_enum_put,
1436 },
854206b0 1437 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
9f113e0e 1438
c9b443d4
TD
1439 { } /* end */
1440};
1441
1442static struct hda_verb cxt5047_test_init_verbs[] = {
c9b443d4
TD
1443 /* Enable retasking pins as output, initially without power amp */
1444 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1445 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1446 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1447
1448 /* Disable digital (SPDIF) pins initially, but users can enable
1449 * them via a mixer switch. In the case of SPDIF-out, this initverb
1450 * payload also sets the generation to 0, output to be in "consumer"
1451 * PCM format, copyright asserted, no pre-emphasis and no validity
1452 * control.
1453 */
1454 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1455
1456 /* Ensure mic1, mic2, line1 pin widgets take input from the
1457 * OUT1 sum bus when acting as an output.
1458 */
1459 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1460 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1461
1462 /* Start with output sum widgets muted and their output gains at min */
1463 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1464 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1465
1466 /* Unmute retasking pin widget output buffers since the default
1467 * state appears to be output. As the pin mode is changed by the
1468 * user the pin mode control will take care of enabling the pin's
1469 * input/output buffers as needed.
1470 */
1471 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1472 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1473 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1474
1475 /* Mute capture amp left and right */
1476 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1477
1478 /* Set ADC connection select to match default mixer setting (mic1
1479 * pin)
1480 */
1481 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1482
1483 /* Mute all inputs to mixer widget (even unconnected ones) */
1484 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1485 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1486 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1487 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1488 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1489 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1490 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1491 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1492
1493 { }
1494};
1495#endif
1496
1497
1498/* initialize jack-sensing, too */
1499static int cxt5047_hp_init(struct hda_codec *codec)
1500{
1501 conexant_init(codec);
1502 cxt5047_hp_automute(codec);
c9b443d4
TD
1503 return 0;
1504}
1505
1506
1507enum {
f5fcc13c
TI
1508 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1509 CXT5047_LAPTOP_HP, /* Some HP laptops */
1510 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
c9b443d4
TD
1511#ifdef CONFIG_SND_DEBUG
1512 CXT5047_TEST,
1513#endif
f5fcc13c 1514 CXT5047_MODELS
c9b443d4
TD
1515};
1516
f5fcc13c
TI
1517static const char *cxt5047_models[CXT5047_MODELS] = {
1518 [CXT5047_LAPTOP] = "laptop",
1519 [CXT5047_LAPTOP_HP] = "laptop-hp",
1520 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
c9b443d4 1521#ifdef CONFIG_SND_DEBUG
f5fcc13c 1522 [CXT5047_TEST] = "test",
c9b443d4 1523#endif
f5fcc13c
TI
1524};
1525
1526static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
ac3e3741 1527 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
dea0a509
TI
1528 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1529 CXT5047_LAPTOP),
f5fcc13c 1530 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
c9b443d4
TD
1531 {}
1532};
1533
1534static int patch_cxt5047(struct hda_codec *codec)
1535{
1536 struct conexant_spec *spec;
1537 int board_config;
1538
1539 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1540 if (!spec)
1541 return -ENOMEM;
c9b443d4 1542 codec->spec = spec;
9421f954 1543 codec->pin_amp_workaround = 1;
c9b443d4
TD
1544
1545 spec->multiout.max_channels = 2;
1546 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1547 spec->multiout.dac_nids = cxt5047_dac_nids;
1548 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1549 spec->num_adc_nids = 1;
1550 spec->adc_nids = cxt5047_adc_nids;
1551 spec->capsrc_nids = cxt5047_capsrc_nids;
c9b443d4 1552 spec->num_mixers = 1;
df481e41 1553 spec->mixers[0] = cxt5047_base_mixers;
c9b443d4
TD
1554 spec->num_init_verbs = 1;
1555 spec->init_verbs[0] = cxt5047_init_verbs;
1556 spec->spdif_route = 0;
5cd57529
TD
1557 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1558 spec->channel_mode = cxt5047_modes,
c9b443d4
TD
1559
1560 codec->patch_ops = conexant_patch_ops;
c9b443d4 1561
f5fcc13c
TI
1562 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1563 cxt5047_models,
1564 cxt5047_cfg_tbl);
c9b443d4
TD
1565 switch (board_config) {
1566 case CXT5047_LAPTOP:
df481e41
TI
1567 spec->num_mixers = 2;
1568 spec->mixers[1] = cxt5047_hp_spk_mixers;
1569 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
c9b443d4
TD
1570 break;
1571 case CXT5047_LAPTOP_HP:
df481e41
TI
1572 spec->num_mixers = 2;
1573 spec->mixers[1] = cxt5047_hp_only_mixers;
fb3409e7 1574 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
c9b443d4
TD
1575 codec->patch_ops.init = cxt5047_hp_init;
1576 break;
1577 case CXT5047_LAPTOP_EAPD:
82f30040 1578 spec->input_mux = &cxt5047_toshiba_capture_source;
df481e41
TI
1579 spec->num_mixers = 2;
1580 spec->mixers[1] = cxt5047_hp_spk_mixers;
c9b443d4
TD
1581 spec->num_init_verbs = 2;
1582 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
fb3409e7 1583 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
c9b443d4
TD
1584 break;
1585#ifdef CONFIG_SND_DEBUG
1586 case CXT5047_TEST:
1587 spec->input_mux = &cxt5047_test_capture_source;
1588 spec->mixers[0] = cxt5047_test_mixer;
1589 spec->init_verbs[0] = cxt5047_test_init_verbs;
fb3409e7 1590 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
c9b443d4
TD
1591#endif
1592 }
dd5746a8 1593 spec->vmaster_nid = 0x13;
025f206c
DC
1594
1595 switch (codec->subsystem_id >> 16) {
1596 case 0x103c:
1597 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1598 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1599 * with 0 dB offset 0x17)
1600 */
1601 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1602 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1603 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1604 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1605 (1 << AC_AMPCAP_MUTE_SHIFT));
1606 break;
1607 }
1608
c9b443d4
TD
1609 return 0;
1610}
1611
461e2c78
TI
1612/* Conexant 5051 specific */
1613static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1614static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
461e2c78
TI
1615
1616static struct hda_channel_mode cxt5051_modes[1] = {
1617 { 2, NULL },
1618};
1619
1620static void cxt5051_update_speaker(struct hda_codec *codec)
1621{
1622 struct conexant_spec *spec = codec->spec;
1623 unsigned int pinctl;
23d2df5b
TI
1624 /* headphone pin */
1625 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1626 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1627 pinctl);
1628 /* speaker pin */
461e2c78
TI
1629 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1630 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1631 pinctl);
1632}
1633
1634/* turn on/off EAPD (+ mute HP) as a master switch */
1635static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1636 struct snd_ctl_elem_value *ucontrol)
1637{
1638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1639
1640 if (!cxt_eapd_put(kcontrol, ucontrol))
1641 return 0;
1642 cxt5051_update_speaker(codec);
1643 return 1;
1644}
1645
1646/* toggle input of built-in and mic jack appropriately */
1647static void cxt5051_portb_automic(struct hda_codec *codec)
1648{
79d7d533 1649 struct conexant_spec *spec = codec->spec;
461e2c78
TI
1650 unsigned int present;
1651
faddaa5d 1652 if (!(spec->auto_mic & AUTO_MIC_PORTB))
79d7d533 1653 return;
d56757ab 1654 present = snd_hda_jack_detect(codec, 0x17);
461e2c78
TI
1655 snd_hda_codec_write(codec, 0x14, 0,
1656 AC_VERB_SET_CONNECT_SEL,
1657 present ? 0x01 : 0x00);
1658}
1659
1660/* switch the current ADC according to the jack state */
1661static void cxt5051_portc_automic(struct hda_codec *codec)
1662{
1663 struct conexant_spec *spec = codec->spec;
1664 unsigned int present;
1665 hda_nid_t new_adc;
1666
faddaa5d 1667 if (!(spec->auto_mic & AUTO_MIC_PORTC))
79d7d533 1668 return;
d56757ab 1669 present = snd_hda_jack_detect(codec, 0x18);
461e2c78
TI
1670 if (present)
1671 spec->cur_adc_idx = 1;
1672 else
1673 spec->cur_adc_idx = 0;
1674 new_adc = spec->adc_nids[spec->cur_adc_idx];
1675 if (spec->cur_adc && spec->cur_adc != new_adc) {
1676 /* stream is running, let's swap the current ADC */
888afa15 1677 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
461e2c78
TI
1678 spec->cur_adc = new_adc;
1679 snd_hda_codec_setup_stream(codec, new_adc,
1680 spec->cur_adc_stream_tag, 0,
1681 spec->cur_adc_format);
1682 }
1683}
1684
1685/* mute internal speaker if HP is plugged */
1686static void cxt5051_hp_automute(struct hda_codec *codec)
1687{
1688 struct conexant_spec *spec = codec->spec;
1689
d56757ab 1690 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
461e2c78
TI
1691 cxt5051_update_speaker(codec);
1692}
1693
1694/* unsolicited event for HP jack sensing */
1695static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1696 unsigned int res)
1697{
acf26c0c 1698 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
461e2c78
TI
1699 switch (res >> 26) {
1700 case CONEXANT_HP_EVENT:
1701 cxt5051_hp_automute(codec);
1702 break;
1703 case CXT5051_PORTB_EVENT:
1704 cxt5051_portb_automic(codec);
1705 break;
1706 case CXT5051_PORTC_EVENT:
1707 cxt5051_portc_automic(codec);
1708 break;
1709 }
acf26c0c 1710 conexant_report_jack(codec, nid);
461e2c78
TI
1711}
1712
2c7a3fb3 1713static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
461e2c78
TI
1714 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1715 {
1716 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1717 .name = "Master Playback Switch",
1718 .info = cxt_eapd_info,
1719 .get = cxt_eapd_get,
1720 .put = cxt5051_hp_master_sw_put,
1721 .private_value = 0x1a,
1722 },
2c7a3fb3
TI
1723 {}
1724};
461e2c78 1725
2c7a3fb3
TI
1726static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1727 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1728 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1729 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1730 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1731 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1732 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
461e2c78
TI
1733 {}
1734};
1735
1736static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1737 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1738 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1739 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1740 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
461e2c78
TI
1741 {}
1742};
1743
79d7d533 1744static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
4e4ac600
TI
1745 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1746 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
79d7d533
TI
1747 {}
1748};
1749
cd9d95a5 1750static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
5f6c3de6
TI
1751 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1752 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
cd9d95a5
KP
1753 {}
1754};
1755
faddaa5d
TI
1756static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1757 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1758 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1759 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1760 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
faddaa5d
TI
1761 {}
1762};
1763
461e2c78
TI
1764static struct hda_verb cxt5051_init_verbs[] = {
1765 /* Line in, Mic */
1766 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1767 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1768 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1769 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1770 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1771 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1772 /* SPK */
1773 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1774 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1775 /* HP, Amp */
1776 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1777 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1778 /* DAC1 */
1779 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1780 /* Record selector: Int mic */
1781 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1782 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1783 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1784 /* SPDIF route: PCM */
1785 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1786 /* EAPD */
1787 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1788 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
461e2c78
TI
1789 { } /* end */
1790};
1791
79d7d533
TI
1792static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1793 /* Line in, Mic */
1794 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1795 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1796 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1797 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1798 /* SPK */
1799 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1800 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1801 /* HP, Amp */
1802 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1803 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1804 /* DAC1 */
1805 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1806 /* Record selector: Int mic */
1807 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1808 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1809 /* SPDIF route: PCM */
1810 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1811 /* EAPD */
1812 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1813 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
79d7d533
TI
1814 { } /* end */
1815};
1816
27e08988
ASRF
1817static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1818 /* Line in, Mic */
1819 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1820 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1821 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1822 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1823 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1824 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1825 /* SPK */
1826 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1827 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1828 /* HP, Amp */
1829 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1830 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1831 /* Docking HP */
1832 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1833 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1834 /* DAC1 */
1835 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1836 /* Record selector: Int mic */
1837 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1838 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1839 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1840 /* SPDIF route: PCM */
1841 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1842 /* EAPD */
1843 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1844 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
27e08988
ASRF
1845 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1846 { } /* end */
1847};
1848
cd9d95a5
KP
1849static struct hda_verb cxt5051_f700_init_verbs[] = {
1850 /* Line in, Mic */
30ed7ed1 1851 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
cd9d95a5
KP
1852 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1853 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1854 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1855 /* SPK */
1856 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1857 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1858 /* HP, Amp */
1859 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1860 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1861 /* DAC1 */
1862 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1863 /* Record selector: Int mic */
1864 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1865 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1866 /* SPDIF route: PCM */
1867 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1868 /* EAPD */
1869 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1870 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
cd9d95a5
KP
1871 { } /* end */
1872};
1873
6953e552
TI
1874static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1875 unsigned int event)
1876{
1877 snd_hda_codec_write(codec, nid, 0,
1878 AC_VERB_SET_UNSOLICITED_ENABLE,
1879 AC_USRSP_EN | event);
1880#ifdef CONFIG_SND_HDA_INPUT_JACK
1881 conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
1882 conexant_report_jack(codec, nid);
1883#endif
1884}
1885
461e2c78
TI
1886/* initialize jack-sensing, too */
1887static int cxt5051_init(struct hda_codec *codec)
1888{
6953e552
TI
1889 struct conexant_spec *spec = codec->spec;
1890
461e2c78 1891 conexant_init(codec);
acf26c0c 1892 conexant_init_jacks(codec);
6953e552
TI
1893
1894 if (spec->auto_mic & AUTO_MIC_PORTB)
1895 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1896 if (spec->auto_mic & AUTO_MIC_PORTC)
1897 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1898
461e2c78
TI
1899 if (codec->patch_ops.unsol_event) {
1900 cxt5051_hp_automute(codec);
1901 cxt5051_portb_automic(codec);
1902 cxt5051_portc_automic(codec);
1903 }
1904 return 0;
1905}
1906
1907
1908enum {
1909 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1910 CXT5051_HP, /* no docking */
79d7d533 1911 CXT5051_HP_DV6736, /* HP without mic switch */
27e08988 1912 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
cd9d95a5 1913 CXT5051_F700, /* HP Compaq Presario F700 */
faddaa5d 1914 CXT5051_TOSHIBA, /* Toshiba M300 & co */
461e2c78
TI
1915 CXT5051_MODELS
1916};
1917
1918static const char *cxt5051_models[CXT5051_MODELS] = {
1919 [CXT5051_LAPTOP] = "laptop",
1920 [CXT5051_HP] = "hp",
79d7d533 1921 [CXT5051_HP_DV6736] = "hp-dv6736",
27e08988 1922 [CXT5051_LENOVO_X200] = "lenovo-x200",
5f6c3de6 1923 [CXT5051_F700] = "hp-700",
faddaa5d 1924 [CXT5051_TOSHIBA] = "toshiba",
461e2c78
TI
1925};
1926
1927static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
79d7d533 1928 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1812e67c 1929 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
5f6c3de6 1930 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
faddaa5d 1931 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
461e2c78
TI
1932 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1933 CXT5051_LAPTOP),
1934 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
27e08988 1935 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
461e2c78
TI
1936 {}
1937};
1938
1939static int patch_cxt5051(struct hda_codec *codec)
1940{
1941 struct conexant_spec *spec;
1942 int board_config;
1943
1944 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1945 if (!spec)
1946 return -ENOMEM;
461e2c78 1947 codec->spec = spec;
9421f954 1948 codec->pin_amp_workaround = 1;
461e2c78
TI
1949
1950 codec->patch_ops = conexant_patch_ops;
1951 codec->patch_ops.init = cxt5051_init;
1952
1953 spec->multiout.max_channels = 2;
1954 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1955 spec->multiout.dac_nids = cxt5051_dac_nids;
1956 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1957 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1958 spec->adc_nids = cxt5051_adc_nids;
2c7a3fb3
TI
1959 spec->num_mixers = 2;
1960 spec->mixers[0] = cxt5051_capture_mixers;
1961 spec->mixers[1] = cxt5051_playback_mixers;
461e2c78
TI
1962 spec->num_init_verbs = 1;
1963 spec->init_verbs[0] = cxt5051_init_verbs;
1964 spec->spdif_route = 0;
1965 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1966 spec->channel_mode = cxt5051_modes;
1967 spec->cur_adc = 0;
1968 spec->cur_adc_idx = 0;
1969
79d7d533
TI
1970 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1971
461e2c78
TI
1972 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1973 cxt5051_models,
1974 cxt5051_cfg_tbl);
faddaa5d 1975 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
461e2c78
TI
1976 switch (board_config) {
1977 case CXT5051_HP:
461e2c78
TI
1978 spec->mixers[0] = cxt5051_hp_mixers;
1979 break;
79d7d533
TI
1980 case CXT5051_HP_DV6736:
1981 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1982 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
faddaa5d 1983 spec->auto_mic = 0;
79d7d533 1984 break;
27e08988
ASRF
1985 case CXT5051_LENOVO_X200:
1986 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
461e2c78 1987 break;
cd9d95a5
KP
1988 case CXT5051_F700:
1989 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1990 spec->mixers[0] = cxt5051_f700_mixers;
faddaa5d
TI
1991 spec->auto_mic = 0;
1992 break;
1993 case CXT5051_TOSHIBA:
1994 spec->mixers[0] = cxt5051_toshiba_mixers;
1995 spec->auto_mic = AUTO_MIC_PORTB;
cd9d95a5 1996 break;
461e2c78
TI
1997 }
1998
1999 return 0;
2000}
2001
0fb67e98
DD
2002/* Conexant 5066 specific */
2003
2004static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2005static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2006static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2007#define CXT5066_SPDIF_OUT 0x21
2008
dbaccc0c
DD
2009/* OLPC's microphone port is DC coupled for use with external sensors,
2010 * therefore we use a 50% mic bias in order to center the input signal with
2011 * the DC input range of the codec. */
2012#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2013
0fb67e98
DD
2014static struct hda_channel_mode cxt5066_modes[1] = {
2015 { 2, NULL },
2016};
2017
2018static void cxt5066_update_speaker(struct hda_codec *codec)
2019{
2020 struct conexant_spec *spec = codec->spec;
2021 unsigned int pinctl;
2022
2023 snd_printdd("CXT5066: update speaker, hp_present=%d\n",
2024 spec->hp_present);
2025
2026 /* Port A (HP) */
2027 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
2028 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2029 pinctl);
2030
2031 /* Port D (HP/LO) */
2032 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
2033 ? spec->port_d_mode : 0;
2034 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2035 pinctl);
2036
2037 /* CLASS_D AMP */
2038 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2039 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2040 pinctl);
2041
2042 if (spec->dell_automute) {
2043 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
2044 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
2045 ? PIN_OUT : 0;
2046 snd_hda_codec_write(codec, 0x1c, 0,
2047 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
2048 }
2049}
2050
2051/* turn on/off EAPD (+ mute HP) as a master switch */
2052static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2053 struct snd_ctl_elem_value *ucontrol)
2054{
2055 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2056
2057 if (!cxt_eapd_put(kcontrol, ucontrol))
2058 return 0;
2059
2060 cxt5066_update_speaker(codec);
2061 return 1;
2062}
2063
c4cfe66c
DD
2064static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2065 .num_items = 3,
2066 .items = {
2067 { "Off", PIN_IN },
2068 { "50%", PIN_VREF50 },
2069 { "80%", PIN_VREF80 },
2070 },
2071};
2072
2073static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2074{
2075 struct conexant_spec *spec = codec->spec;
2076 /* Even though port F is the DC input, the bias is controlled on port B.
2077 * we also leave that port as an active input (but unselected) in DC mode
2078 * just in case that is necessary to make the bias setting take effect. */
2079 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2080 AC_VERB_SET_PIN_WIDGET_CONTROL,
2081 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2082}
2083
75f8991d
DD
2084/* OLPC defers mic widget control until when capture is started because the
2085 * microphone LED comes on as soon as these settings are put in place. if we
2086 * did this before recording, it would give the false indication that recording
2087 * is happening when it is not. */
2088static void cxt5066_olpc_select_mic(struct hda_codec *codec)
0fb67e98 2089{
dbaccc0c 2090 struct conexant_spec *spec = codec->spec;
75f8991d
DD
2091 if (!spec->recording)
2092 return;
0fb67e98 2093
c4cfe66c
DD
2094 if (spec->dc_enable) {
2095 /* in DC mode we ignore presence detection and just use the jack
2096 * through our special DC port */
2097 const struct hda_verb enable_dc_mode[] = {
2098 /* disble internal mic, port C */
2099 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2100
2101 /* enable DC capture, port F */
2102 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2103 {},
2104 };
2105
2106 snd_hda_sequence_write(codec, enable_dc_mode);
2107 /* port B input disabled (and bias set) through the following call */
2108 cxt5066_set_olpc_dc_bias(codec);
2109 return;
2110 }
2111
2112 /* disable DC (port F) */
2113 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2114
75f8991d
DD
2115 /* external mic, port B */
2116 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2117 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
0fb67e98 2118
75f8991d
DD
2119 /* internal mic, port C */
2120 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2121 spec->ext_mic_present ? 0 : PIN_VREF80);
2122}
0fb67e98 2123
75f8991d
DD
2124/* toggle input of built-in and mic jack appropriately */
2125static void cxt5066_olpc_automic(struct hda_codec *codec)
2126{
2127 struct conexant_spec *spec = codec->spec;
0fb67e98
DD
2128 unsigned int present;
2129
c4cfe66c
DD
2130 if (spec->dc_enable) /* don't do presence detection in DC mode */
2131 return;
2132
75f8991d
DD
2133 present = snd_hda_codec_read(codec, 0x1a, 0,
2134 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2135 if (present)
0fb67e98 2136 snd_printdd("CXT5066: external microphone detected\n");
75f8991d 2137 else
0fb67e98 2138 snd_printdd("CXT5066: external microphone absent\n");
75f8991d
DD
2139
2140 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2141 present ? 0 : 1);
2142 spec->ext_mic_present = !!present;
2143
2144 cxt5066_olpc_select_mic(codec);
0fb67e98
DD
2145}
2146
95a618bd
ER
2147/* toggle input of built-in digital mic and mic jack appropriately */
2148static void cxt5066_vostro_automic(struct hda_codec *codec)
2149{
95a618bd
ER
2150 unsigned int present;
2151
2152 struct hda_verb ext_mic_present[] = {
2153 /* enable external mic, port B */
75f8991d 2154 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
95a618bd
ER
2155
2156 /* switch to external mic input */
2157 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2158 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2159
2160 /* disable internal digital mic */
2161 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2162 {}
2163 };
2164 static struct hda_verb ext_mic_absent[] = {
2165 /* enable internal mic, port C */
2166 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2167
2168 /* switch to internal mic input */
2169 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2170
2171 /* disable external mic, port B */
2172 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2173 {}
2174 };
2175
2176 present = snd_hda_jack_detect(codec, 0x1a);
2177 if (present) {
2178 snd_printdd("CXT5066: external microphone detected\n");
2179 snd_hda_sequence_write(codec, ext_mic_present);
2180 } else {
2181 snd_printdd("CXT5066: external microphone absent\n");
2182 snd_hda_sequence_write(codec, ext_mic_absent);
2183 }
2184}
2185
cfd3d8dc
GA
2186/* toggle input of built-in digital mic and mic jack appropriately */
2187static void cxt5066_ideapad_automic(struct hda_codec *codec)
2188{
2189 unsigned int present;
2190
2191 struct hda_verb ext_mic_present[] = {
2192 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2193 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2194 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2195 {}
2196 };
2197 static struct hda_verb ext_mic_absent[] = {
2198 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2199 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2200 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2201 {}
2202 };
2203
2204 present = snd_hda_jack_detect(codec, 0x1b);
2205 if (present) {
2206 snd_printdd("CXT5066: external microphone detected\n");
2207 snd_hda_sequence_write(codec, ext_mic_present);
2208 } else {
2209 snd_printdd("CXT5066: external microphone absent\n");
2210 snd_hda_sequence_write(codec, ext_mic_absent);
2211 }
2212}
2213
0fb67e98
DD
2214/* mute internal speaker if HP is plugged */
2215static void cxt5066_hp_automute(struct hda_codec *codec)
2216{
2217 struct conexant_spec *spec = codec->spec;
2218 unsigned int portA, portD;
2219
2220 /* Port A */
d56757ab 2221 portA = snd_hda_jack_detect(codec, 0x19);
0fb67e98
DD
2222
2223 /* Port D */
d56757ab 2224 portD = snd_hda_jack_detect(codec, 0x1c);
0fb67e98
DD
2225
2226 spec->hp_present = !!(portA | portD);
2227 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2228 portA, portD, spec->hp_present);
2229 cxt5066_update_speaker(codec);
2230}
2231
2232/* unsolicited event for jack sensing */
75f8991d 2233static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
0fb67e98 2234{
c4cfe66c 2235 struct conexant_spec *spec = codec->spec;
0fb67e98
DD
2236 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2237 switch (res >> 26) {
2238 case CONEXANT_HP_EVENT:
2239 cxt5066_hp_automute(codec);
2240 break;
2241 case CONEXANT_MIC_EVENT:
c4cfe66c
DD
2242 /* ignore mic events in DC mode; we're always using the jack */
2243 if (!spec->dc_enable)
2244 cxt5066_olpc_automic(codec);
0fb67e98
DD
2245 break;
2246 }
2247}
2248
95a618bd
ER
2249/* unsolicited event for jack sensing */
2250static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
2251{
2252 snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
2253 switch (res >> 26) {
2254 case CONEXANT_HP_EVENT:
2255 cxt5066_hp_automute(codec);
2256 break;
2257 case CONEXANT_MIC_EVENT:
2258 cxt5066_vostro_automic(codec);
2259 break;
2260 }
2261}
2262
cfd3d8dc
GA
2263/* unsolicited event for jack sensing */
2264static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
2265{
2266 snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26);
2267 switch (res >> 26) {
2268 case CONEXANT_HP_EVENT:
2269 cxt5066_hp_automute(codec);
2270 break;
2271 case CONEXANT_MIC_EVENT:
2272 cxt5066_ideapad_automic(codec);
2273 break;
2274 }
2275}
2276
0fb67e98
DD
2277static const struct hda_input_mux cxt5066_analog_mic_boost = {
2278 .num_items = 5,
2279 .items = {
2280 { "0dB", 0 },
2281 { "10dB", 1 },
2282 { "20dB", 2 },
2283 { "30dB", 3 },
2284 { "40dB", 4 },
2285 },
2286};
2287
cfd3d8dc 2288static void cxt5066_set_mic_boost(struct hda_codec *codec)
c4cfe66c
DD
2289{
2290 struct conexant_spec *spec = codec->spec;
cfd3d8dc 2291 snd_hda_codec_write_cache(codec, 0x17, 0,
c4cfe66c
DD
2292 AC_VERB_SET_AMP_GAIN_MUTE,
2293 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2294 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
cfd3d8dc
GA
2295 if (spec->ideapad) {
2296 /* adjust the internal mic as well...it is not through 0x17 */
2297 snd_hda_codec_write_cache(codec, 0x23, 0,
2298 AC_VERB_SET_AMP_GAIN_MUTE,
2299 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2300 cxt5066_analog_mic_boost.
2301 items[spec->mic_boost].index);
2302 }
c4cfe66c
DD
2303}
2304
0fb67e98
DD
2305static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2306 struct snd_ctl_elem_info *uinfo)
2307{
2308 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2309}
2310
2311static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2312 struct snd_ctl_elem_value *ucontrol)
2313{
2314 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
c4cfe66c
DD
2315 struct conexant_spec *spec = codec->spec;
2316 ucontrol->value.enumerated.item[0] = spec->mic_boost;
0fb67e98
DD
2317 return 0;
2318}
2319
2320static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2321 struct snd_ctl_elem_value *ucontrol)
2322{
2323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
c4cfe66c 2324 struct conexant_spec *spec = codec->spec;
0fb67e98
DD
2325 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2326 unsigned int idx;
c4cfe66c
DD
2327 idx = ucontrol->value.enumerated.item[0];
2328 if (idx >= imux->num_items)
2329 idx = imux->num_items - 1;
2330
2331 spec->mic_boost = idx;
2332 if (!spec->dc_enable)
2333 cxt5066_set_mic_boost(codec);
2334 return 1;
2335}
2336
2337static void cxt5066_enable_dc(struct hda_codec *codec)
2338{
2339 const struct hda_verb enable_dc_mode[] = {
2340 /* disable gain */
2341 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2342
2343 /* switch to DC input */
2344 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2345 {}
2346 };
2347
2348 /* configure as input source */
2349 snd_hda_sequence_write(codec, enable_dc_mode);
2350 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2351}
2352
2353static void cxt5066_disable_dc(struct hda_codec *codec)
2354{
2355 /* reconfigure input source */
2356 cxt5066_set_mic_boost(codec);
2357 /* automic also selects the right mic if we're recording */
2358 cxt5066_olpc_automic(codec);
2359}
2360
2361static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2362 struct snd_ctl_elem_value *ucontrol)
2363{
2364 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2365 struct conexant_spec *spec = codec->spec;
2366 ucontrol->value.integer.value[0] = spec->dc_enable;
2367 return 0;
2368}
0fb67e98 2369
c4cfe66c
DD
2370static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2371 struct snd_ctl_elem_value *ucontrol)
2372{
2373 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2374 struct conexant_spec *spec = codec->spec;
2375 int dc_enable = !!ucontrol->value.integer.value[0];
2376
2377 if (dc_enable == spec->dc_enable)
0fb67e98 2378 return 0;
c4cfe66c
DD
2379
2380 spec->dc_enable = dc_enable;
2381 if (dc_enable)
2382 cxt5066_enable_dc(codec);
2383 else
2384 cxt5066_disable_dc(codec);
2385
2386 return 1;
2387}
2388
2389static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2390 struct snd_ctl_elem_info *uinfo)
2391{
2392 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2393}
2394
2395static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2396 struct snd_ctl_elem_value *ucontrol)
2397{
2398 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2399 struct conexant_spec *spec = codec->spec;
2400 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2401 return 0;
2402}
2403
2404static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2405 struct snd_ctl_elem_value *ucontrol)
2406{
2407 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2408 struct conexant_spec *spec = codec->spec;
2409 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2410 unsigned int idx;
2411
0fb67e98
DD
2412 idx = ucontrol->value.enumerated.item[0];
2413 if (idx >= imux->num_items)
2414 idx = imux->num_items - 1;
2415
c4cfe66c
DD
2416 spec->dc_input_bias = idx;
2417 if (spec->dc_enable)
2418 cxt5066_set_olpc_dc_bias(codec);
0fb67e98
DD
2419 return 1;
2420}
2421
75f8991d
DD
2422static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2423{
2424 struct conexant_spec *spec = codec->spec;
2425 /* mark as recording and configure the microphone widget so that the
2426 * recording LED comes on. */
2427 spec->recording = 1;
2428 cxt5066_olpc_select_mic(codec);
2429}
2430
2431static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2432{
2433 struct conexant_spec *spec = codec->spec;
2434 const struct hda_verb disable_mics[] = {
2435 /* disable external mic, port B */
2436 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2437
2438 /* disble internal mic, port C */
2439 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
c4cfe66c
DD
2440
2441 /* disable DC capture, port F */
2442 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
75f8991d
DD
2443 {},
2444 };
2445
2446 snd_hda_sequence_write(codec, disable_mics);
2447 spec->recording = 0;
2448}
2449
0fb67e98
DD
2450static struct hda_input_mux cxt5066_capture_source = {
2451 .num_items = 4,
2452 .items = {
2453 { "Mic B", 0 },
2454 { "Mic C", 1 },
2455 { "Mic E", 2 },
2456 { "Mic F", 3 },
2457 },
2458};
2459
2460static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2461 .ops = &snd_hda_bind_vol,
2462 .values = {
2463 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2464 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2465 0
2466 },
2467};
2468
2469static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2470 .ops = &snd_hda_bind_sw,
2471 .values = {
2472 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2473 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2474 0
2475 },
2476};
2477
2478static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2479 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2480 {}
2481};
2482
2483static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2484 {
2485 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2486 .name = "Master Playback Volume",
2487 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2488 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2489 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
5e26dfd0 2490 .subdevice = HDA_SUBDEV_AMP_FLAG,
0fb67e98
DD
2491 .info = snd_hda_mixer_amp_volume_info,
2492 .get = snd_hda_mixer_amp_volume_get,
2493 .put = snd_hda_mixer_amp_volume_put,
2494 .tlv = { .c = snd_hda_mixer_amp_tlv },
2495 /* offset by 28 volume steps to limit minimum gain to -46dB */
2496 .private_value =
2497 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2498 },
2499 {}
2500};
2501
c4cfe66c
DD
2502static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2503 {
2504 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2505 .name = "DC Mode Enable Switch",
2506 .info = snd_ctl_boolean_mono_info,
2507 .get = cxt5066_olpc_dc_get,
2508 .put = cxt5066_olpc_dc_put,
2509 },
2510 {
2511 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2512 .name = "DC Input Bias Enum",
2513 .info = cxt5066_olpc_dc_bias_enum_info,
2514 .get = cxt5066_olpc_dc_bias_enum_get,
2515 .put = cxt5066_olpc_dc_bias_enum_put,
2516 },
2517 {}
2518};
2519
0fb67e98
DD
2520static struct snd_kcontrol_new cxt5066_mixers[] = {
2521 {
2522 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2523 .name = "Master Playback Switch",
2524 .info = cxt_eapd_info,
2525 .get = cxt_eapd_get,
2526 .put = cxt5066_hp_master_sw_put,
2527 .private_value = 0x1d,
2528 },
2529
2530 {
2531 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
c4cfe66c 2532 .name = "Analog Mic Boost Capture Enum",
0fb67e98
DD
2533 .info = cxt5066_mic_boost_mux_enum_info,
2534 .get = cxt5066_mic_boost_mux_enum_get,
2535 .put = cxt5066_mic_boost_mux_enum_put,
2536 },
2537
2538 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2539 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2540 {}
2541};
2542
254bba6a
ER
2543static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2544 {
2545 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2546 .name = "Int Mic Boost Capture Enum",
2547 .info = cxt5066_mic_boost_mux_enum_info,
2548 .get = cxt5066_mic_boost_mux_enum_get,
2549 .put = cxt5066_mic_boost_mux_enum_put,
2550 .private_value = 0x23 | 0x100,
2551 },
c0f8faf0 2552 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
254bba6a
ER
2553 {}
2554};
2555
0fb67e98
DD
2556static struct hda_verb cxt5066_init_verbs[] = {
2557 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2558 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2559 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2560 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2561
2562 /* Speakers */
2563 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2564 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2565
2566 /* HP, Amp */
2567 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2568 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2569
2570 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2571 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2572
2573 /* DAC1 */
2574 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2575
2576 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2577 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2578 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2579 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2580 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2581 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2582
2583 /* no digital microphone support yet */
2584 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2585
2586 /* Audio input selector */
2587 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2588
2589 /* SPDIF route: PCM */
2590 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2591 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2592
2593 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2594 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2595
2596 /* EAPD */
2597 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2598
2599 /* not handling these yet */
2600 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2601 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2602 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2603 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2604 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2605 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2606 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2607 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2608 { } /* end */
2609};
2610
2611static struct hda_verb cxt5066_init_verbs_olpc[] = {
2612 /* Port A: headphones */
2613 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2614 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2615
2616 /* Port B: external microphone */
75f8991d 2617 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
0fb67e98
DD
2618
2619 /* Port C: internal microphone */
75f8991d 2620 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
0fb67e98
DD
2621
2622 /* Port D: unused */
2623 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2624
2625 /* Port E: unused, but has primary EAPD */
2626 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2627 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2628
c4cfe66c 2629 /* Port F: external DC input through microphone port */
0fb67e98
DD
2630 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2631
2632 /* Port G: internal speakers */
2633 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2634 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2635
2636 /* DAC1 */
2637 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2638
2639 /* DAC2: unused */
2640 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2641
2642 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2643 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2644 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2645 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2646 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2647 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2648 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2649 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2650 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2651 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2652 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2653 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2654
2655 /* Disable digital microphone port */
2656 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2657
2658 /* Audio input selectors */
2659 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2660 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2661
2662 /* Disable SPDIF */
2663 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2664 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2665
2666 /* enable unsolicited events for Port A and B */
2667 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2668 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2669 { } /* end */
2670};
2671
95a618bd
ER
2672static struct hda_verb cxt5066_init_verbs_vostro[] = {
2673 /* Port A: headphones */
2674 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2675 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2676
2677 /* Port B: external microphone */
2678 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2679
2680 /* Port C: unused */
2681 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2682
2683 /* Port D: unused */
2684 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2685
2686 /* Port E: unused, but has primary EAPD */
2687 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2688 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2689
2690 /* Port F: unused */
2691 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2692
2693 /* Port G: internal speakers */
2694 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2695 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2696
2697 /* DAC1 */
2698 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2699
2700 /* DAC2: unused */
2701 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2702
2703 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2704 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2705 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2706 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2707 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2708 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2709 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2710 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2711 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2712 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2713 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2714 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2715
2716 /* Digital microphone port */
2717 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2718
2719 /* Audio input selectors */
2720 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2721 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2722
2723 /* Disable SPDIF */
2724 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2725 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2726
2727 /* enable unsolicited events for Port A and B */
2728 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2729 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2730 { } /* end */
2731};
2732
cfd3d8dc
GA
2733static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2734 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2735 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2736 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2737 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2738
2739 /* Speakers */
2740 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2741 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2742
2743 /* HP, Amp */
2744 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2745 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2746
2747 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2748 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2749
2750 /* DAC1 */
2751 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2752
2753 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2754 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2755 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2756 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2757 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2758 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2759 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2760
2761 /* Audio input selector */
2762 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2763 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2764
2765 /* SPDIF route: PCM */
2766 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2767 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2768
2769 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2770 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2771
2772 /* internal microphone */
2773 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
2774
2775 /* EAPD */
2776 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2777
2778 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2779 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2780 { } /* end */
2781};
2782
0fb67e98
DD
2783static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2784 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2785 { } /* end */
2786};
2787
2788/* initialize jack-sensing, too */
2789static int cxt5066_init(struct hda_codec *codec)
2790{
254bba6a
ER
2791 struct conexant_spec *spec = codec->spec;
2792
0fb67e98
DD
2793 snd_printdd("CXT5066: init\n");
2794 conexant_init(codec);
2795 if (codec->patch_ops.unsol_event) {
2796 cxt5066_hp_automute(codec);
254bba6a
ER
2797 if (spec->dell_vostro)
2798 cxt5066_vostro_automic(codec);
cfd3d8dc
GA
2799 else if (spec->ideapad)
2800 cxt5066_ideapad_automic(codec);
0fb67e98 2801 }
c4cfe66c 2802 cxt5066_set_mic_boost(codec);
0fb67e98
DD
2803 return 0;
2804}
2805
75f8991d
DD
2806static int cxt5066_olpc_init(struct hda_codec *codec)
2807{
c4cfe66c 2808 struct conexant_spec *spec = codec->spec;
75f8991d
DD
2809 snd_printdd("CXT5066: init\n");
2810 conexant_init(codec);
2811 cxt5066_hp_automute(codec);
c4cfe66c
DD
2812 if (!spec->dc_enable) {
2813 cxt5066_set_mic_boost(codec);
2814 cxt5066_olpc_automic(codec);
2815 } else {
2816 cxt5066_enable_dc(codec);
2817 }
75f8991d
DD
2818 return 0;
2819}
2820
0fb67e98
DD
2821enum {
2822 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2823 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2824 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
95a618bd 2825 CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
cfd3d8dc 2826 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
0fb67e98
DD
2827 CXT5066_MODELS
2828};
2829
2830static const char *cxt5066_models[CXT5066_MODELS] = {
2831 [CXT5066_LAPTOP] = "laptop",
2832 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2833 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
cfd3d8dc
GA
2834 [CXT5066_DELL_VOSTO] = "dell-vostro",
2835 [CXT5066_IDEAPAD] = "ideapad",
0fb67e98
DD
2836};
2837
2838static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2839 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2840 CXT5066_LAPTOP),
2841 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
2842 CXT5066_DELL_LAPTOP),
798a8a15 2843 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
95a618bd 2844 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
4442dd46 2845 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
cfd3d8dc 2846 SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
0fb67e98
DD
2847 {}
2848};
2849
2850static int patch_cxt5066(struct hda_codec *codec)
2851{
2852 struct conexant_spec *spec;
2853 int board_config;
2854
2855 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2856 if (!spec)
2857 return -ENOMEM;
2858 codec->spec = spec;
2859
2860 codec->patch_ops = conexant_patch_ops;
75f8991d 2861 codec->patch_ops.init = conexant_init;
0fb67e98
DD
2862
2863 spec->dell_automute = 0;
2864 spec->multiout.max_channels = 2;
2865 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2866 spec->multiout.dac_nids = cxt5066_dac_nids;
2867 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
2868 spec->num_adc_nids = 1;
2869 spec->adc_nids = cxt5066_adc_nids;
2870 spec->capsrc_nids = cxt5066_capsrc_nids;
2871 spec->input_mux = &cxt5066_capture_source;
2872
2873 spec->port_d_mode = PIN_HP;
2874
2875 spec->num_init_verbs = 1;
2876 spec->init_verbs[0] = cxt5066_init_verbs;
2877 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
2878 spec->channel_mode = cxt5066_modes;
2879 spec->cur_adc = 0;
2880 spec->cur_adc_idx = 0;
2881
2882 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2883 cxt5066_models, cxt5066_cfg_tbl);
2884 switch (board_config) {
2885 default:
2886 case CXT5066_LAPTOP:
2887 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2888 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2889 break;
2890 case CXT5066_DELL_LAPTOP:
2891 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2892 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2893
2894 spec->port_d_mode = PIN_OUT;
2895 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
2896 spec->num_init_verbs++;
2897 spec->dell_automute = 1;
2898 break;
2899 case CXT5066_OLPC_XO_1_5:
75f8991d
DD
2900 codec->patch_ops.init = cxt5066_olpc_init;
2901 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
0fb67e98
DD
2902 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
2903 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
c4cfe66c 2904 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
0fb67e98
DD
2905 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2906 spec->port_d_mode = 0;
c4cfe66c 2907 spec->mic_boost = 3; /* default 30dB gain */
0fb67e98
DD
2908
2909 /* no S/PDIF out */
2910 spec->multiout.dig_out_nid = 0;
2911
95a618bd
ER
2912 /* input source automatically selected */
2913 spec->input_mux = NULL;
75f8991d
DD
2914
2915 /* our capture hooks which allow us to turn on the microphone LED
2916 * at the right time */
2917 spec->capture_prepare = cxt5066_olpc_capture_prepare;
2918 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
95a618bd
ER
2919 break;
2920 case CXT5066_DELL_VOSTO:
75f8991d 2921 codec->patch_ops.init = cxt5066_init;
95a618bd
ER
2922 codec->patch_ops.unsol_event = cxt5066_vostro_event;
2923 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
2924 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2925 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
254bba6a 2926 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
95a618bd 2927 spec->port_d_mode = 0;
254bba6a 2928 spec->dell_vostro = 1;
c4cfe66c 2929 spec->mic_boost = 3; /* default 30dB gain */
c0f8faf0 2930 snd_hda_attach_beep_device(codec, 0x13);
95a618bd
ER
2931
2932 /* no S/PDIF out */
2933 spec->multiout.dig_out_nid = 0;
2934
cfd3d8dc
GA
2935 /* input source automatically selected */
2936 spec->input_mux = NULL;
2937 break;
2938 case CXT5066_IDEAPAD:
2939 codec->patch_ops.init = cxt5066_init;
2940 codec->patch_ops.unsol_event = cxt5066_ideapad_event;
2941 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2942 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2943 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
2944 spec->port_d_mode = 0;
2945 spec->ideapad = 1;
2946 spec->mic_boost = 2; /* default 20dB gain */
2947
2948 /* no S/PDIF out */
2949 spec->multiout.dig_out_nid = 0;
2950
0fb67e98
DD
2951 /* input source automatically selected */
2952 spec->input_mux = NULL;
2953 break;
2954 }
2955
2956 return 0;
2957}
461e2c78
TI
2958
2959/*
2960 */
2961
1289e9e8 2962static struct hda_codec_preset snd_hda_preset_conexant[] = {
82f30040
TD
2963 { .id = 0x14f15045, .name = "CX20549 (Venice)",
2964 .patch = patch_cxt5045 },
2965 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
2966 .patch = patch_cxt5047 },
461e2c78
TI
2967 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
2968 .patch = patch_cxt5051 },
0fb67e98
DD
2969 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
2970 .patch = patch_cxt5066 },
95a618bd
ER
2971 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
2972 .patch = patch_cxt5066 },
c9b443d4
TD
2973 {} /* terminator */
2974};
1289e9e8
TI
2975
2976MODULE_ALIAS("snd-hda-codec-id:14f15045");
2977MODULE_ALIAS("snd-hda-codec-id:14f15047");
2978MODULE_ALIAS("snd-hda-codec-id:14f15051");
0fb67e98 2979MODULE_ALIAS("snd-hda-codec-id:14f15066");
95a618bd 2980MODULE_ALIAS("snd-hda-codec-id:14f15067");
1289e9e8
TI
2981
2982MODULE_LICENSE("GPL");
2983MODULE_DESCRIPTION("Conexant HD-audio codec");
2984
2985static struct hda_codec_preset_list conexant_list = {
2986 .preset = snd_hda_preset_conexant,
2987 .owner = THIS_MODULE,
2988};
2989
2990static int __init patch_conexant_init(void)
2991{
2992 return snd_hda_add_codec_preset(&conexant_list);
2993}
2994
2995static void __exit patch_conexant_exit(void)
2996{
2997 snd_hda_delete_codec_preset(&conexant_list);
2998}
2999
3000module_init(patch_conexant_init)
3001module_exit(patch_conexant_exit)