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