blob: 0177ef8f4c9e9f2af8206a21c307d6795e3dbbd3 [file] [log] [blame]
Tobin Davisc9b443d2006-11-14 12:13:39 +01001/*
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
Tobin Davisc9b443d2006-11-14 12:13:39 +010023#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/slab.h>
26#include <linux/pci.h>
27#include <sound/core.h>
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010028#include <sound/jack.h>
29
Tobin Davisc9b443d2006-11-14 12:13:39 +010030#include "hda_codec.h"
31#include "hda_local.h"
32
33#define CXT_PIN_DIR_IN 0x00
34#define CXT_PIN_DIR_OUT 0x01
35#define CXT_PIN_DIR_INOUT 0x02
36#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
37#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
38
39#define CONEXANT_HP_EVENT 0x37
40#define CONEXANT_MIC_EVENT 0x38
41
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010042/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010043
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010044#define CXT5051_SPDIF_OUT 0x1C
45#define CXT5051_PORTB_EVENT 0x38
46#define CXT5051_PORTC_EVENT 0x39
47
48
49struct conexant_jack {
50
51 hda_nid_t nid;
52 int type;
53 struct snd_jack *jack;
54
55};
Tobin Davisc9b443d2006-11-14 12:13:39 +010056
57struct conexant_spec {
58
59 struct snd_kcontrol_new *mixers[5];
60 int num_mixers;
61
62 const struct hda_verb *init_verbs[5]; /* initialization verbs
63 * don't forget NULL
64 * termination!
65 */
66 unsigned int num_init_verbs;
67
68 /* playback */
69 struct hda_multi_out multiout; /* playback set-up
70 * max_channels, dacs must be set
71 * dig_out_nid and hp_nid are optional
72 */
73 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010074 unsigned int hp_present;
Tobin Davisc9b443d2006-11-14 12:13:39 +010075 unsigned int need_dac_fix;
76
77 /* capture */
78 unsigned int num_adc_nids;
79 hda_nid_t *adc_nids;
80 hda_nid_t dig_in_nid; /* digital-in NID; optional */
81
Takashi Iwai461e2c72008-01-25 11:35:17 +010082 unsigned int cur_adc_idx;
83 hda_nid_t cur_adc;
84 unsigned int cur_adc_stream_tag;
85 unsigned int cur_adc_format;
86
Tobin Davisc9b443d2006-11-14 12:13:39 +010087 /* capture source */
88 const struct hda_input_mux *input_mux;
89 hda_nid_t *capsrc_nids;
90 unsigned int cur_mux[3];
91
92 /* channel model */
93 const struct hda_channel_mode *channel_mode;
94 int num_channel_mode;
95
96 /* PCM information */
97 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
98
Tobin Davisc9b443d2006-11-14 12:13:39 +010099 unsigned int spdif_route;
100
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100101 /* jack detection */
102 struct snd_array jacks;
103
Tobin Davisc9b443d2006-11-14 12:13:39 +0100104 /* dynamic controls, init_verbs and input_mux */
105 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100106 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +0200107 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100108
109};
110
111static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
112 struct hda_codec *codec,
113 struct snd_pcm_substream *substream)
114{
115 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100116 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
117 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100118}
119
120static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
121 struct hda_codec *codec,
122 unsigned int stream_tag,
123 unsigned int format,
124 struct snd_pcm_substream *substream)
125{
126 struct conexant_spec *spec = codec->spec;
127 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
128 stream_tag,
129 format, substream);
130}
131
132static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
133 struct hda_codec *codec,
134 struct snd_pcm_substream *substream)
135{
136 struct conexant_spec *spec = codec->spec;
137 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
138}
139
140/*
141 * Digital out
142 */
143static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
144 struct hda_codec *codec,
145 struct snd_pcm_substream *substream)
146{
147 struct conexant_spec *spec = codec->spec;
148 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
149}
150
151static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
152 struct hda_codec *codec,
153 struct snd_pcm_substream *substream)
154{
155 struct conexant_spec *spec = codec->spec;
156 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
157}
158
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200159static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
160 struct hda_codec *codec,
161 unsigned int stream_tag,
162 unsigned int format,
163 struct snd_pcm_substream *substream)
164{
165 struct conexant_spec *spec = codec->spec;
166 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
167 stream_tag,
168 format, substream);
169}
170
Tobin Davisc9b443d2006-11-14 12:13:39 +0100171/*
172 * Analog capture
173 */
174static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
175 struct hda_codec *codec,
176 unsigned int stream_tag,
177 unsigned int format,
178 struct snd_pcm_substream *substream)
179{
180 struct conexant_spec *spec = codec->spec;
181 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
182 stream_tag, 0, format);
183 return 0;
184}
185
186static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
187 struct hda_codec *codec,
188 struct snd_pcm_substream *substream)
189{
190 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100191 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100192 return 0;
193}
194
195
196
197static struct hda_pcm_stream conexant_pcm_analog_playback = {
198 .substreams = 1,
199 .channels_min = 2,
200 .channels_max = 2,
201 .nid = 0, /* fill later */
202 .ops = {
203 .open = conexant_playback_pcm_open,
204 .prepare = conexant_playback_pcm_prepare,
205 .cleanup = conexant_playback_pcm_cleanup
206 },
207};
208
209static struct hda_pcm_stream conexant_pcm_analog_capture = {
210 .substreams = 1,
211 .channels_min = 2,
212 .channels_max = 2,
213 .nid = 0, /* fill later */
214 .ops = {
215 .prepare = conexant_capture_pcm_prepare,
216 .cleanup = conexant_capture_pcm_cleanup
217 },
218};
219
220
221static struct hda_pcm_stream conexant_pcm_digital_playback = {
222 .substreams = 1,
223 .channels_min = 2,
224 .channels_max = 2,
225 .nid = 0, /* fill later */
226 .ops = {
227 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200228 .close = conexant_dig_playback_pcm_close,
229 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100230 },
231};
232
233static struct hda_pcm_stream conexant_pcm_digital_capture = {
234 .substreams = 1,
235 .channels_min = 2,
236 .channels_max = 2,
237 /* NID is set in alc_build_pcms */
238};
239
Takashi Iwai461e2c72008-01-25 11:35:17 +0100240static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
241 struct hda_codec *codec,
242 unsigned int stream_tag,
243 unsigned int format,
244 struct snd_pcm_substream *substream)
245{
246 struct conexant_spec *spec = codec->spec;
247 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
248 spec->cur_adc_stream_tag = stream_tag;
249 spec->cur_adc_format = format;
250 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
251 return 0;
252}
253
254static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
255 struct hda_codec *codec,
256 struct snd_pcm_substream *substream)
257{
258 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100259 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100260 spec->cur_adc = 0;
261 return 0;
262}
263
264static struct hda_pcm_stream cx5051_pcm_analog_capture = {
265 .substreams = 1,
266 .channels_min = 2,
267 .channels_max = 2,
268 .nid = 0, /* fill later */
269 .ops = {
270 .prepare = cx5051_capture_pcm_prepare,
271 .cleanup = cx5051_capture_pcm_cleanup
272 },
273};
274
Tobin Davisc9b443d2006-11-14 12:13:39 +0100275static int conexant_build_pcms(struct hda_codec *codec)
276{
277 struct conexant_spec *spec = codec->spec;
278 struct hda_pcm *info = spec->pcm_rec;
279
280 codec->num_pcms = 1;
281 codec->pcm_info = info;
282
283 info->name = "CONEXANT Analog";
284 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
285 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
286 spec->multiout.max_channels;
287 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
288 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100289 if (codec->vendor_id == 0x14f15051)
290 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
291 cx5051_pcm_analog_capture;
292 else
293 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
294 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100295 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
296 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
297
298 if (spec->multiout.dig_out_nid) {
299 info++;
300 codec->num_pcms++;
301 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100302 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100303 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
304 conexant_pcm_digital_playback;
305 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
306 spec->multiout.dig_out_nid;
307 if (spec->dig_in_nid) {
308 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
309 conexant_pcm_digital_capture;
310 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
311 spec->dig_in_nid;
312 }
313 }
314
315 return 0;
316}
317
318static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
319 struct snd_ctl_elem_info *uinfo)
320{
321 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
322 struct conexant_spec *spec = codec->spec;
323
324 return snd_hda_input_mux_info(spec->input_mux, uinfo);
325}
326
327static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
328 struct snd_ctl_elem_value *ucontrol)
329{
330 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
331 struct conexant_spec *spec = codec->spec;
332 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
333
334 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
335 return 0;
336}
337
338static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
339 struct snd_ctl_elem_value *ucontrol)
340{
341 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
342 struct conexant_spec *spec = codec->spec;
343 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
344
345 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
346 spec->capsrc_nids[adc_idx],
347 &spec->cur_mux[adc_idx]);
348}
349
Takashi Iwai5801f992009-01-27 12:53:22 +0100350#ifdef CONFIG_SND_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100351static int conexant_add_jack(struct hda_codec *codec,
352 hda_nid_t nid, int type)
353{
354 struct conexant_spec *spec;
355 struct conexant_jack *jack;
356 const char *name;
357
358 spec = codec->spec;
359 snd_array_init(&spec->jacks, sizeof(*jack), 32);
360 jack = snd_array_new(&spec->jacks);
361 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
362
363 if (!jack)
364 return -ENOMEM;
365
366 jack->nid = nid;
367 jack->type = type;
368
369 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
370}
371
372static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
373{
374 struct conexant_spec *spec = codec->spec;
375 struct conexant_jack *jacks = spec->jacks.list;
376
377 if (jacks) {
378 int i;
379 for (i = 0; i < spec->jacks.used; i++) {
380 if (jacks->nid == nid) {
381 unsigned int present;
382 present = snd_hda_codec_read(codec, nid, 0,
383 AC_VERB_GET_PIN_SENSE, 0) &
384 AC_PINSENSE_PRESENCE;
385
386 present = (present) ? jacks->type : 0 ;
387
388 snd_jack_report(jacks->jack,
389 present);
390 }
391 jacks++;
392 }
393 }
394}
395
396static int conexant_init_jacks(struct hda_codec *codec)
397{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100398 struct conexant_spec *spec = codec->spec;
399 int i;
400
401 for (i = 0; i < spec->num_init_verbs; i++) {
402 const struct hda_verb *hv;
403
404 hv = spec->init_verbs[i];
405 while (hv->nid) {
406 int err = 0;
407 switch (hv->param ^ AC_USRSP_EN) {
408 case CONEXANT_HP_EVENT:
409 err = conexant_add_jack(codec, hv->nid,
410 SND_JACK_HEADPHONE);
411 conexant_report_jack(codec, hv->nid);
412 break;
413 case CXT5051_PORTC_EVENT:
414 case CONEXANT_MIC_EVENT:
415 err = conexant_add_jack(codec, hv->nid,
416 SND_JACK_MICROPHONE);
417 conexant_report_jack(codec, hv->nid);
418 break;
419 }
420 if (err < 0)
421 return err;
422 ++hv;
423 }
424 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100425 return 0;
426
427}
Takashi Iwai5801f992009-01-27 12:53:22 +0100428#else
429static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
430{
431}
432
433static inline int conexant_init_jacks(struct hda_codec *codec)
434{
435 return 0;
436}
437#endif
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100438
Tobin Davisc9b443d2006-11-14 12:13:39 +0100439static int conexant_init(struct hda_codec *codec)
440{
441 struct conexant_spec *spec = codec->spec;
442 int i;
443
444 for (i = 0; i < spec->num_init_verbs; i++)
445 snd_hda_sequence_write(codec, spec->init_verbs[i]);
446 return 0;
447}
448
449static void conexant_free(struct hda_codec *codec)
450{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100451#ifdef CONFIG_SND_JACK
452 struct conexant_spec *spec = codec->spec;
453 if (spec->jacks.list) {
454 struct conexant_jack *jacks = spec->jacks.list;
455 int i;
456 for (i = 0; i < spec->jacks.used; i++)
457 snd_device_free(codec->bus->card, &jacks[i].jack);
458 snd_array_free(&spec->jacks);
459 }
460#endif
Tobin Davisc9b443d2006-11-14 12:13:39 +0100461 kfree(codec->spec);
462}
463
Tobin Davisc9b443d2006-11-14 12:13:39 +0100464static int conexant_build_controls(struct hda_codec *codec)
465{
466 struct conexant_spec *spec = codec->spec;
467 unsigned int i;
468 int err;
469
470 for (i = 0; i < spec->num_mixers; i++) {
471 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
472 if (err < 0)
473 return err;
474 }
475 if (spec->multiout.dig_out_nid) {
476 err = snd_hda_create_spdif_out_ctls(codec,
477 spec->multiout.dig_out_nid);
478 if (err < 0)
479 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100480 err = snd_hda_create_spdif_share_sw(codec,
481 &spec->multiout);
482 if (err < 0)
483 return err;
484 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100485 }
486 if (spec->dig_in_nid) {
487 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
488 if (err < 0)
489 return err;
490 }
491 return 0;
492}
493
494static struct hda_codec_ops conexant_patch_ops = {
495 .build_controls = conexant_build_controls,
496 .build_pcms = conexant_build_pcms,
497 .init = conexant_init,
498 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100499};
500
501/*
502 * EAPD control
503 * the private value = nid | (invert << 8)
504 */
505
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200506#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100507
Tobin Davis82f30042007-02-13 12:45:44 +0100508static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100509 struct snd_ctl_elem_value *ucontrol)
510{
511 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
512 struct conexant_spec *spec = codec->spec;
513 int invert = (kcontrol->private_value >> 8) & 1;
514 if (invert)
515 ucontrol->value.integer.value[0] = !spec->cur_eapd;
516 else
517 ucontrol->value.integer.value[0] = spec->cur_eapd;
518 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100519
Tobin Davisc9b443d2006-11-14 12:13:39 +0100520}
521
Tobin Davis82f30042007-02-13 12:45:44 +0100522static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100523 struct snd_ctl_elem_value *ucontrol)
524{
525 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
526 struct conexant_spec *spec = codec->spec;
527 int invert = (kcontrol->private_value >> 8) & 1;
528 hda_nid_t nid = kcontrol->private_value & 0xff;
529 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100530
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100531 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100532 if (invert)
533 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200534 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100535 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100536
Tobin Davisc9b443d2006-11-14 12:13:39 +0100537 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200538 snd_hda_codec_write_cache(codec, nid,
539 0, AC_VERB_SET_EAPD_BTLENABLE,
540 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100541 return 1;
542}
543
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100544/* controls for test mode */
545#ifdef CONFIG_SND_DEBUG
546
Tobin Davis82f30042007-02-13 12:45:44 +0100547#define CXT_EAPD_SWITCH(xname, nid, mask) \
548 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
549 .info = cxt_eapd_info, \
550 .get = cxt_eapd_get, \
551 .put = cxt_eapd_put, \
552 .private_value = nid | (mask<<16) }
553
554
555
Tobin Davisc9b443d2006-11-14 12:13:39 +0100556static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
557 struct snd_ctl_elem_info *uinfo)
558{
559 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
560 struct conexant_spec *spec = codec->spec;
561 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
562 spec->num_channel_mode);
563}
564
565static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
566 struct snd_ctl_elem_value *ucontrol)
567{
568 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
569 struct conexant_spec *spec = codec->spec;
570 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
571 spec->num_channel_mode,
572 spec->multiout.max_channels);
573}
574
575static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
576 struct snd_ctl_elem_value *ucontrol)
577{
578 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
579 struct conexant_spec *spec = codec->spec;
580 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
581 spec->num_channel_mode,
582 &spec->multiout.max_channels);
583 if (err >= 0 && spec->need_dac_fix)
584 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
585 return err;
586}
587
588#define CXT_PIN_MODE(xname, nid, dir) \
589 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
590 .info = conexant_ch_mode_info, \
591 .get = conexant_ch_mode_get, \
592 .put = conexant_ch_mode_put, \
593 .private_value = nid | (dir<<16) }
594
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100595#endif /* CONFIG_SND_DEBUG */
596
Tobin Davisc9b443d2006-11-14 12:13:39 +0100597/* Conexant 5045 specific */
598
599static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
600static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
601static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100602#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100603
Tobin Davis5cd57522006-11-20 17:42:09 +0100604static struct hda_channel_mode cxt5045_modes[1] = {
605 { 2, NULL },
606};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100607
608static struct hda_input_mux cxt5045_capture_source = {
609 .num_items = 2,
610 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100611 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100612 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100613 }
614};
615
Jiang Zhe5218c892008-01-17 11:18:41 +0100616static struct hda_input_mux cxt5045_capture_source_benq = {
617 .num_items = 3,
618 .items = {
619 { "IntMic", 0x1 },
620 { "ExtMic", 0x2 },
621 { "LineIn", 0x3 },
622 }
623};
624
Jiang zhe2de3c232008-03-06 11:09:09 +0100625static struct hda_input_mux cxt5045_capture_source_hp530 = {
626 .num_items = 2,
627 .items = {
628 { "ExtMic", 0x1 },
629 { "IntMic", 0x2 },
630 }
631};
632
Tobin Davisc9b443d2006-11-14 12:13:39 +0100633/* turn on/off EAPD (+ mute HP) as a master switch */
634static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
635 struct snd_ctl_elem_value *ucontrol)
636{
637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
638 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100639 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100640
Tobin Davis82f30042007-02-13 12:45:44 +0100641 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100642 return 0;
643
Tobin Davis82f30042007-02-13 12:45:44 +0100644 /* toggle internal speakers mute depending of presence of
645 * the headphone jack
646 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200647 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
648 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
649 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100650
Takashi Iwai47fd8302007-08-10 17:11:07 +0200651 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
652 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
653 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100654 return 1;
655}
656
657/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200658static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
659 .ops = &snd_hda_bind_vol,
660 .values = {
661 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
662 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
663 0
664 },
665};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100666
Tobin Davis7f296732007-03-12 11:39:01 +0100667/* toggle input of built-in and mic jack appropriately */
668static void cxt5045_hp_automic(struct hda_codec *codec)
669{
670 static struct hda_verb mic_jack_on[] = {
671 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
672 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
673 {}
674 };
675 static struct hda_verb mic_jack_off[] = {
676 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
677 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
678 {}
679 };
680 unsigned int present;
681
682 present = snd_hda_codec_read(codec, 0x12, 0,
683 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
684 if (present)
685 snd_hda_sequence_write(codec, mic_jack_on);
686 else
687 snd_hda_sequence_write(codec, mic_jack_off);
688}
689
Tobin Davisc9b443d2006-11-14 12:13:39 +0100690
691/* mute internal speaker if HP is plugged */
692static void cxt5045_hp_automute(struct hda_codec *codec)
693{
Tobin Davis82f30042007-02-13 12:45:44 +0100694 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100695 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100696
Tobin Davis82f30042007-02-13 12:45:44 +0100697 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100698 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100699
Takashi Iwai47fd8302007-08-10 17:11:07 +0200700 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
701 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
702 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100703}
704
705/* unsolicited event for HP jack sensing */
706static void cxt5045_hp_unsol_event(struct hda_codec *codec,
707 unsigned int res)
708{
709 res >>= 26;
710 switch (res) {
711 case CONEXANT_HP_EVENT:
712 cxt5045_hp_automute(codec);
713 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100714 case CONEXANT_MIC_EVENT:
715 cxt5045_hp_automic(codec);
716 break;
717
Tobin Davisc9b443d2006-11-14 12:13:39 +0100718 }
719}
720
721static struct snd_kcontrol_new cxt5045_mixers[] = {
722 {
723 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
724 .name = "Capture Source",
725 .info = conexant_mux_enum_info,
726 .get = conexant_mux_enum_get,
727 .put = conexant_mux_enum_put
728 },
Takashi Iwaic8229c32007-10-19 08:06:21 +0200729 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
730 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
731 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
732 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
733 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
734 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
735 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
736 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
737 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
738 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200739 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100740 {
741 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
742 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100743 .info = cxt_eapd_info,
744 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100745 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100746 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100747 },
748
749 {}
750};
751
Jiang Zhe5218c892008-01-17 11:18:41 +0100752static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
753 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
754 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
755 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
756 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
757
758 {}
759};
760
Jiang zhe2de3c232008-03-06 11:09:09 +0100761static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
762 {
763 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
764 .name = "Capture Source",
765 .info = conexant_mux_enum_info,
766 .get = conexant_mux_enum_get,
767 .put = conexant_mux_enum_put
768 },
769 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
770 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
771 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
772 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
773 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
774 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
775 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
776 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
777 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
778 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
779 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
780 {
781 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
782 .name = "Master Playback Switch",
783 .info = cxt_eapd_info,
784 .get = cxt_eapd_get,
785 .put = cxt5045_hp_master_sw_put,
786 .private_value = 0x10,
787 },
788
789 {}
790};
791
Tobin Davisc9b443d2006-11-14 12:13:39 +0100792static struct hda_verb cxt5045_init_verbs[] = {
793 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200794 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100795 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100796 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200797 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
798 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
799 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
800 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
801 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
802 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
803 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
804 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
805 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100806 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100807 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100808 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100809 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
810 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100811 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100812 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100813 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100814 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100815 { } /* end */
816};
817
Jiang Zhe5218c892008-01-17 11:18:41 +0100818static struct hda_verb cxt5045_benq_init_verbs[] = {
819 /* Int Mic, Mic */
820 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
821 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
822 /* Line In,HP, Amp */
823 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
824 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
825 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
826 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
827 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
828 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
829 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
830 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
831 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
832 /* Record selector: Int mic */
833 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
834 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
835 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
836 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100837 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100838 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
839 /* EAPD */
840 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
841 { } /* end */
842};
Tobin Davis7f296732007-03-12 11:39:01 +0100843
844static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
845 /* pin sensing on HP jack */
846 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200847 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100848};
849
850static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
851 /* pin sensing on HP jack */
852 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200853 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100854};
855
Tobin Davisc9b443d2006-11-14 12:13:39 +0100856#ifdef CONFIG_SND_DEBUG
857/* Test configuration for debugging, modelled after the ALC260 test
858 * configuration.
859 */
860static struct hda_input_mux cxt5045_test_capture_source = {
861 .num_items = 5,
862 .items = {
863 { "MIXER", 0x0 },
864 { "MIC1 pin", 0x1 },
865 { "LINE1 pin", 0x2 },
866 { "HP-OUT pin", 0x3 },
867 { "CD pin", 0x4 },
868 },
869};
870
871static struct snd_kcontrol_new cxt5045_test_mixer[] = {
872
873 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100874 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
875 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100876 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
877 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
878 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
879 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100880
881 /* Modes for retasking pin widgets */
882 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
883 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
884
Tobin Davis82f30042007-02-13 12:45:44 +0100885 /* EAPD Switch Control */
886 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
887
Tobin Davisc9b443d2006-11-14 12:13:39 +0100888 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100889
Tobin Davis7f296732007-03-12 11:39:01 +0100890 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
891 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
892 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
893 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
894 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
895 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
896 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
897 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
898 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
899 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100900 {
901 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
902 .name = "Input Source",
903 .info = conexant_mux_enum_info,
904 .get = conexant_mux_enum_get,
905 .put = conexant_mux_enum_put,
906 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200907 /* Audio input controls */
908 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
909 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
910 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
911 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
912 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
913 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
914 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
915 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
916 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
917 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100918 { } /* end */
919};
920
921static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100922 /* Set connections */
923 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
924 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
925 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100926 /* Enable retasking pins as output, initially without power amp */
927 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100928 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100929
930 /* Disable digital (SPDIF) pins initially, but users can enable
931 * them via a mixer switch. In the case of SPDIF-out, this initverb
932 * payload also sets the generation to 0, output to be in "consumer"
933 * PCM format, copyright asserted, no pre-emphasis and no validity
934 * control.
935 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100936 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
937 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100938
939 /* Start with output sum widgets muted and their output gains at min */
940 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
941 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
942
943 /* Unmute retasking pin widget output buffers since the default
944 * state appears to be output. As the pin mode is changed by the
945 * user the pin mode control will take care of enabling the pin's
946 * input/output buffers as needed.
947 */
948 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
949 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
950
951 /* Mute capture amp left and right */
952 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
953
954 /* Set ADC connection select to match default mixer setting (mic1
955 * pin)
956 */
957 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +0100958 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100959
960 /* Mute all inputs to mixer widget (even unconnected ones) */
961 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
962 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
963 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
964 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
965 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
966
967 { }
968};
969#endif
970
971
972/* initialize jack-sensing, too */
973static int cxt5045_init(struct hda_codec *codec)
974{
975 conexant_init(codec);
976 cxt5045_hp_automute(codec);
977 return 0;
978}
979
980
981enum {
Marc Boucher15908c32008-01-22 15:15:59 +0100982 CXT5045_LAPTOP_HPSENSE,
983 CXT5045_LAPTOP_MICSENSE,
984 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +0100985 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +0100986 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100987#ifdef CONFIG_SND_DEBUG
988 CXT5045_TEST,
989#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100990 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100991};
992
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100993static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +0100994 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
995 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
996 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
997 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +0100998 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100999#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001000 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001001#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001002};
1003
1004static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001005 SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
1006 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
1007 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
1008 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
1009 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
1010 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
Takashi Iwai0f6a5152008-01-29 13:26:04 +01001011 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
Jiang zhe2de3c232008-03-06 11:09:09 +01001012 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Marc Boucher15908c32008-01-22 15:15:59 +01001013 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001014 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001015 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001016 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1017 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001018 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1019 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001020 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1021 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1022 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1023 SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
1024 SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
1025 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001026 {}
1027};
1028
1029static int patch_cxt5045(struct hda_codec *codec)
1030{
1031 struct conexant_spec *spec;
1032 int board_config;
1033
1034 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1035 if (!spec)
1036 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001037 codec->spec = spec;
1038
1039 spec->multiout.max_channels = 2;
1040 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1041 spec->multiout.dac_nids = cxt5045_dac_nids;
1042 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1043 spec->num_adc_nids = 1;
1044 spec->adc_nids = cxt5045_adc_nids;
1045 spec->capsrc_nids = cxt5045_capsrc_nids;
1046 spec->input_mux = &cxt5045_capture_source;
1047 spec->num_mixers = 1;
1048 spec->mixers[0] = cxt5045_mixers;
1049 spec->num_init_verbs = 1;
1050 spec->init_verbs[0] = cxt5045_init_verbs;
1051 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001052 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1053 spec->channel_mode = cxt5045_modes,
1054
Tobin Davisc9b443d2006-11-14 12:13:39 +01001055
1056 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001057
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001058 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1059 cxt5045_models,
1060 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001061 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001062 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001063 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001064 spec->input_mux = &cxt5045_capture_source;
1065 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001066 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1067 spec->mixers[0] = cxt5045_mixers;
1068 codec->patch_ops.init = cxt5045_init;
1069 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001070 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001071 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001072 spec->input_mux = &cxt5045_capture_source;
1073 spec->num_init_verbs = 2;
1074 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001075 spec->mixers[0] = cxt5045_mixers;
1076 codec->patch_ops.init = cxt5045_init;
1077 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001078 default:
1079 case CXT5045_LAPTOP_HPMICSENSE:
1080 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1081 spec->input_mux = &cxt5045_capture_source;
1082 spec->num_init_verbs = 3;
1083 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1084 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1085 spec->mixers[0] = cxt5045_mixers;
1086 codec->patch_ops.init = cxt5045_init;
1087 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001088 case CXT5045_BENQ:
1089 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1090 spec->input_mux = &cxt5045_capture_source_benq;
1091 spec->num_init_verbs = 1;
1092 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1093 spec->mixers[0] = cxt5045_mixers;
1094 spec->mixers[1] = cxt5045_benq_mixers;
1095 spec->num_mixers = 2;
1096 codec->patch_ops.init = cxt5045_init;
1097 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001098 case CXT5045_LAPTOP_HP530:
1099 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1100 spec->input_mux = &cxt5045_capture_source_hp530;
1101 spec->num_init_verbs = 2;
1102 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1103 spec->mixers[0] = cxt5045_mixers_hp530;
1104 codec->patch_ops.init = cxt5045_init;
1105 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001106#ifdef CONFIG_SND_DEBUG
1107 case CXT5045_TEST:
1108 spec->input_mux = &cxt5045_test_capture_source;
1109 spec->mixers[0] = cxt5045_test_mixer;
1110 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001111 break;
1112
Tobin Davisc9b443d2006-11-14 12:13:39 +01001113#endif
1114 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001115
Takashi Iwai031005f2008-06-26 14:49:58 +02001116 switch (codec->subsystem_id >> 16) {
1117 case 0x103c:
1118 /* HP laptop has a really bad sound over 0dB on NID 0x17.
1119 * Fix max PCM level to 0 dB
1120 * (originall it has 0x2b steps with 0dB offset 0x14)
1121 */
1122 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1123 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1124 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1125 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1126 (1 << AC_AMPCAP_MUTE_SHIFT));
1127 break;
1128 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001129
Tobin Davisc9b443d2006-11-14 12:13:39 +01001130 return 0;
1131}
1132
1133
1134/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001135#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001136
Tobin Davis82f30042007-02-13 12:45:44 +01001137static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001138static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1139static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001140
Tobin Davis5cd57522006-11-20 17:42:09 +01001141static struct hda_channel_mode cxt5047_modes[1] = {
1142 { 2, NULL },
1143};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001144
1145static struct hda_input_mux cxt5047_capture_source = {
Tobin Davis7f296732007-03-12 11:39:01 +01001146 .num_items = 1,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001147 .items = {
Tobin Davis7f296732007-03-12 11:39:01 +01001148 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001149 }
1150};
1151
1152static struct hda_input_mux cxt5047_hp_capture_source = {
1153 .num_items = 1,
1154 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001155 { "ExtMic", 0x2 },
1156 }
1157};
1158
1159static struct hda_input_mux cxt5047_toshiba_capture_source = {
1160 .num_items = 2,
1161 .items = {
1162 { "ExtMic", 0x2 },
1163 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001164 }
1165};
1166
1167/* turn on/off EAPD (+ mute HP) as a master switch */
1168static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1169 struct snd_ctl_elem_value *ucontrol)
1170{
1171 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1172 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001173 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001174
Tobin Davis82f30042007-02-13 12:45:44 +01001175 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001176 return 0;
1177
Tobin Davis82f30042007-02-13 12:45:44 +01001178 /* toggle internal speakers mute depending of presence of
1179 * the headphone jack
1180 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001181 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1182 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1183 HDA_AMP_MUTE, bits);
1184 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1185 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1186 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001187 return 1;
1188}
1189
Tobin Davis82f30042007-02-13 12:45:44 +01001190/* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001191static struct hda_bind_ctls cxt5047_bind_master_vol = {
1192 .ops = &snd_hda_bind_vol,
1193 .values = {
1194 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1195 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1196 0
1197 },
1198};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001199
1200/* mute internal speaker if HP is plugged */
1201static void cxt5047_hp_automute(struct hda_codec *codec)
1202{
Tobin Davis82f30042007-02-13 12:45:44 +01001203 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001204 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001205
Tobin Davis82f30042007-02-13 12:45:44 +01001206 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001207 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +01001208
Takashi Iwai47fd8302007-08-10 17:11:07 +02001209 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1210 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1211 HDA_AMP_MUTE, bits);
Tobin Davis82f30042007-02-13 12:45:44 +01001212 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001213 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1214 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001215}
1216
Tobin Davisfb3409e2007-05-17 09:40:47 +02001217/* mute internal speaker if HP is plugged */
1218static void cxt5047_hp2_automute(struct hda_codec *codec)
1219{
1220 struct conexant_spec *spec = codec->spec;
1221 unsigned int bits;
1222
1223 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1224 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1225
Takashi Iwai47fd8302007-08-10 17:11:07 +02001226 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1227 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1228 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001229 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001230 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1231 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001232}
1233
Tobin Davisc9b443d2006-11-14 12:13:39 +01001234/* toggle input of built-in and mic jack appropriately */
1235static void cxt5047_hp_automic(struct hda_codec *codec)
1236{
1237 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001238 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1239 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001240 {}
1241 };
1242 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001243 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1244 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001245 {}
1246 };
1247 unsigned int present;
1248
Tobin Davis7f296732007-03-12 11:39:01 +01001249 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001250 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1251 if (present)
1252 snd_hda_sequence_write(codec, mic_jack_on);
1253 else
1254 snd_hda_sequence_write(codec, mic_jack_off);
1255}
1256
1257/* unsolicited event for HP jack sensing */
1258static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1259 unsigned int res)
1260{
Marc Boucher9f113e02008-01-22 15:18:08 +01001261 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001262 case CONEXANT_HP_EVENT:
1263 cxt5047_hp_automute(codec);
1264 break;
1265 case CONEXANT_MIC_EVENT:
1266 cxt5047_hp_automic(codec);
1267 break;
1268 }
1269}
1270
Tobin Davisfb3409e2007-05-17 09:40:47 +02001271/* unsolicited event for HP jack sensing - non-EAPD systems */
1272static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1273 unsigned int res)
1274{
1275 res >>= 26;
1276 switch (res) {
1277 case CONEXANT_HP_EVENT:
1278 cxt5047_hp2_automute(codec);
1279 break;
1280 case CONEXANT_MIC_EVENT:
1281 cxt5047_hp_automic(codec);
1282 break;
1283 }
1284}
1285
Tobin Davisc9b443d2006-11-14 12:13:39 +01001286static struct snd_kcontrol_new cxt5047_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001287 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1288 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001289 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1290 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001291 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1292 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1293 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1294 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001295 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1296 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
Tobin Davisb7589ce2007-04-24 17:56:55 +02001297 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1298 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1299 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1300 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001301
1302 {}
1303};
1304
1305static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1306 {
1307 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1308 .name = "Capture Source",
1309 .info = conexant_mux_enum_info,
1310 .get = conexant_mux_enum_get,
1311 .put = conexant_mux_enum_put
1312 },
1313 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1314 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
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),
Takashi Iwaicca3b372007-08-10 17:12:15 +02001319 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
Tobin Davis82f30042007-02-13 12:45:44 +01001320 {
1321 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1322 .name = "Master Playback Switch",
1323 .info = cxt_eapd_info,
1324 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001325 .put = cxt5047_hp_master_sw_put,
1326 .private_value = 0x13,
1327 },
1328
1329 {}
1330};
1331
1332static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1333 {
1334 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1335 .name = "Capture Source",
1336 .info = conexant_mux_enum_info,
1337 .get = conexant_mux_enum_get,
1338 .put = conexant_mux_enum_put
1339 },
1340 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1341 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1342 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1343 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1344 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1345 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1346 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1347 {
1348 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1349 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001350 .info = cxt_eapd_info,
1351 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001352 .put = cxt5047_hp_master_sw_put,
1353 .private_value = 0x13,
1354 },
1355 { } /* end */
1356};
1357
1358static struct hda_verb cxt5047_init_verbs[] = {
1359 /* Line in, Mic, Built-in Mic */
1360 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1361 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1362 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001363 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001364 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1365 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis7f296732007-03-12 11:39:01 +01001366 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1367 /* Record selector: Mic */
1368 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1369 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1370 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1371 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001372 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1373 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1374 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1375 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001376 /* SPDIF route: PCM */
1377 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001378 /* Enable unsolicited events */
1379 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1380 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001381 { } /* end */
1382};
1383
1384/* configuration for Toshiba Laptops */
1385static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1386 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1387 /* pin sensing on HP and Mic jacks */
1388 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1389 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001390 /* Speaker routing */
1391 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001392 {}
1393};
1394
1395/* configuration for HP Laptops */
1396static struct hda_verb cxt5047_hp_init_verbs[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001397 /* pin sensing on HP jack */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001398 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaib84f08d2008-02-18 12:36:11 +01001399 /* 0x13 is actually shared by both HP and speaker;
1400 * setting the connection to 0 (=0x19) makes the master volume control
1401 * working mysteriouslly...
1402 */
1403 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
Tobin Davis82f30042007-02-13 12:45:44 +01001404 /* Record selector: Ext Mic */
1405 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
Tobin Davis82f30042007-02-13 12:45:44 +01001406 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1407 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1408 /* Speaker routing */
1409 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001410 {}
1411};
1412
1413/* Test configuration for debugging, modelled after the ALC260 test
1414 * configuration.
1415 */
1416#ifdef CONFIG_SND_DEBUG
1417static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001418 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001419 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001420 { "LINE1 pin", 0x0 },
1421 { "MIC1 pin", 0x1 },
1422 { "MIC2 pin", 0x2 },
1423 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001424 },
1425};
1426
1427static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1428
1429 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001430 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1431 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1432 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1433 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001434 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1435 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1436 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1437 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001438 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1439 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1440 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1441 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001442
1443 /* Modes for retasking pin widgets */
1444 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1445 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1446
Tobin Davis82f30042007-02-13 12:45:44 +01001447 /* EAPD Switch Control */
1448 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1449
Tobin Davisc9b443d2006-11-14 12:13:39 +01001450 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001451 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1452 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1453 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1454 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1455 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1456 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1457 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1458 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001459
Tobin Davis82f30042007-02-13 12:45:44 +01001460 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1461 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1462 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1463 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1464 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1465 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1466 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1467 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001468 {
1469 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1470 .name = "Input Source",
1471 .info = conexant_mux_enum_info,
1472 .get = conexant_mux_enum_get,
1473 .put = conexant_mux_enum_put,
1474 },
Marc Boucher9f113e02008-01-22 15:18:08 +01001475 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1476 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1477 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1478 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1479 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1480 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1481 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1482 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1483 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1484 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1485
Tobin Davisc9b443d2006-11-14 12:13:39 +01001486 { } /* end */
1487};
1488
1489static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001490 /* Enable retasking pins as output, initially without power amp */
1491 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1492 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1493 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1494
1495 /* Disable digital (SPDIF) pins initially, but users can enable
1496 * them via a mixer switch. In the case of SPDIF-out, this initverb
1497 * payload also sets the generation to 0, output to be in "consumer"
1498 * PCM format, copyright asserted, no pre-emphasis and no validity
1499 * control.
1500 */
1501 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1502
1503 /* Ensure mic1, mic2, line1 pin widgets take input from the
1504 * OUT1 sum bus when acting as an output.
1505 */
1506 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1507 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1508
1509 /* Start with output sum widgets muted and their output gains at min */
1510 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1511 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1512
1513 /* Unmute retasking pin widget output buffers since the default
1514 * state appears to be output. As the pin mode is changed by the
1515 * user the pin mode control will take care of enabling the pin's
1516 * input/output buffers as needed.
1517 */
1518 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1519 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1520 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1521
1522 /* Mute capture amp left and right */
1523 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1524
1525 /* Set ADC connection select to match default mixer setting (mic1
1526 * pin)
1527 */
1528 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1529
1530 /* Mute all inputs to mixer widget (even unconnected ones) */
1531 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1532 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1533 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1534 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1535 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1536 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1537 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1538 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1539
1540 { }
1541};
1542#endif
1543
1544
1545/* initialize jack-sensing, too */
1546static int cxt5047_hp_init(struct hda_codec *codec)
1547{
1548 conexant_init(codec);
1549 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001550 return 0;
1551}
1552
1553
1554enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001555 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1556 CXT5047_LAPTOP_HP, /* Some HP laptops */
1557 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001558#ifdef CONFIG_SND_DEBUG
1559 CXT5047_TEST,
1560#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001561 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001562};
1563
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001564static const char *cxt5047_models[CXT5047_MODELS] = {
1565 [CXT5047_LAPTOP] = "laptop",
1566 [CXT5047_LAPTOP_HP] = "laptop-hp",
1567 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001568#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001569 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001570#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001571};
1572
1573static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1574 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001575 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001576 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
Tobin Davis82f30042007-02-13 12:45:44 +01001577 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
Joerg Schirottkeaa9d8232009-01-27 11:01:34 +01001578 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6700", CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001579 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001580 {}
1581};
1582
1583static int patch_cxt5047(struct hda_codec *codec)
1584{
1585 struct conexant_spec *spec;
1586 int board_config;
1587
1588 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1589 if (!spec)
1590 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001591 codec->spec = spec;
1592
1593 spec->multiout.max_channels = 2;
1594 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1595 spec->multiout.dac_nids = cxt5047_dac_nids;
1596 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1597 spec->num_adc_nids = 1;
1598 spec->adc_nids = cxt5047_adc_nids;
1599 spec->capsrc_nids = cxt5047_capsrc_nids;
1600 spec->input_mux = &cxt5047_capture_source;
1601 spec->num_mixers = 1;
1602 spec->mixers[0] = cxt5047_mixers;
1603 spec->num_init_verbs = 1;
1604 spec->init_verbs[0] = cxt5047_init_verbs;
1605 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001606 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1607 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001608
1609 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001610
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001611 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1612 cxt5047_models,
1613 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001614 switch (board_config) {
1615 case CXT5047_LAPTOP:
Tobin Davisfb3409e2007-05-17 09:40:47 +02001616 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001617 break;
1618 case CXT5047_LAPTOP_HP:
1619 spec->input_mux = &cxt5047_hp_capture_source;
1620 spec->num_init_verbs = 2;
1621 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1622 spec->mixers[0] = cxt5047_hp_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001623 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001624 codec->patch_ops.init = cxt5047_hp_init;
1625 break;
1626 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001627 spec->input_mux = &cxt5047_toshiba_capture_source;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001628 spec->num_init_verbs = 2;
1629 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davis82f30042007-02-13 12:45:44 +01001630 spec->mixers[0] = cxt5047_toshiba_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001631 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001632 break;
1633#ifdef CONFIG_SND_DEBUG
1634 case CXT5047_TEST:
1635 spec->input_mux = &cxt5047_test_capture_source;
1636 spec->mixers[0] = cxt5047_test_mixer;
1637 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001638 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001639#endif
1640 }
1641 return 0;
1642}
1643
Takashi Iwai461e2c72008-01-25 11:35:17 +01001644/* Conexant 5051 specific */
1645static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1646static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001647
1648static struct hda_channel_mode cxt5051_modes[1] = {
1649 { 2, NULL },
1650};
1651
1652static void cxt5051_update_speaker(struct hda_codec *codec)
1653{
1654 struct conexant_spec *spec = codec->spec;
1655 unsigned int pinctl;
1656 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1657 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1658 pinctl);
1659}
1660
1661/* turn on/off EAPD (+ mute HP) as a master switch */
1662static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1663 struct snd_ctl_elem_value *ucontrol)
1664{
1665 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1666
1667 if (!cxt_eapd_put(kcontrol, ucontrol))
1668 return 0;
1669 cxt5051_update_speaker(codec);
1670 return 1;
1671}
1672
1673/* toggle input of built-in and mic jack appropriately */
1674static void cxt5051_portb_automic(struct hda_codec *codec)
1675{
1676 unsigned int present;
1677
1678 present = snd_hda_codec_read(codec, 0x17, 0,
1679 AC_VERB_GET_PIN_SENSE, 0) &
1680 AC_PINSENSE_PRESENCE;
1681 snd_hda_codec_write(codec, 0x14, 0,
1682 AC_VERB_SET_CONNECT_SEL,
1683 present ? 0x01 : 0x00);
1684}
1685
1686/* switch the current ADC according to the jack state */
1687static void cxt5051_portc_automic(struct hda_codec *codec)
1688{
1689 struct conexant_spec *spec = codec->spec;
1690 unsigned int present;
1691 hda_nid_t new_adc;
1692
1693 present = snd_hda_codec_read(codec, 0x18, 0,
1694 AC_VERB_GET_PIN_SENSE, 0) &
1695 AC_PINSENSE_PRESENCE;
1696 if (present)
1697 spec->cur_adc_idx = 1;
1698 else
1699 spec->cur_adc_idx = 0;
1700 new_adc = spec->adc_nids[spec->cur_adc_idx];
1701 if (spec->cur_adc && spec->cur_adc != new_adc) {
1702 /* stream is running, let's swap the current ADC */
Takashi Iwai888afa12008-03-18 09:57:50 +01001703 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001704 spec->cur_adc = new_adc;
1705 snd_hda_codec_setup_stream(codec, new_adc,
1706 spec->cur_adc_stream_tag, 0,
1707 spec->cur_adc_format);
1708 }
1709}
1710
1711/* mute internal speaker if HP is plugged */
1712static void cxt5051_hp_automute(struct hda_codec *codec)
1713{
1714 struct conexant_spec *spec = codec->spec;
1715
1716 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1717 AC_VERB_GET_PIN_SENSE, 0) &
1718 AC_PINSENSE_PRESENCE;
1719 cxt5051_update_speaker(codec);
1720}
1721
1722/* unsolicited event for HP jack sensing */
1723static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1724 unsigned int res)
1725{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001726 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001727 switch (res >> 26) {
1728 case CONEXANT_HP_EVENT:
1729 cxt5051_hp_automute(codec);
1730 break;
1731 case CXT5051_PORTB_EVENT:
1732 cxt5051_portb_automic(codec);
1733 break;
1734 case CXT5051_PORTC_EVENT:
1735 cxt5051_portc_automic(codec);
1736 break;
1737 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001738 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001739}
1740
1741static struct snd_kcontrol_new cxt5051_mixers[] = {
1742 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1743 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1744 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1745 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1746 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1747 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1748 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1749 {
1750 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1751 .name = "Master Playback Switch",
1752 .info = cxt_eapd_info,
1753 .get = cxt_eapd_get,
1754 .put = cxt5051_hp_master_sw_put,
1755 .private_value = 0x1a,
1756 },
1757
1758 {}
1759};
1760
1761static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1762 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1763 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1764 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1765 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1766 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1767 {
1768 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1769 .name = "Master Playback Switch",
1770 .info = cxt_eapd_info,
1771 .get = cxt_eapd_get,
1772 .put = cxt5051_hp_master_sw_put,
1773 .private_value = 0x1a,
1774 },
1775
1776 {}
1777};
1778
1779static struct hda_verb cxt5051_init_verbs[] = {
1780 /* Line in, Mic */
1781 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1782 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1783 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1784 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1785 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1786 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1787 /* SPK */
1788 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1789 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1790 /* HP, Amp */
1791 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1792 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1793 /* DAC1 */
1794 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1795 /* Record selector: Int mic */
1796 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1797 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1798 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1799 /* SPDIF route: PCM */
1800 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1801 /* EAPD */
1802 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1803 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1804 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1805 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1806 { } /* end */
1807};
1808
1809/* initialize jack-sensing, too */
1810static int cxt5051_init(struct hda_codec *codec)
1811{
1812 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001813 conexant_init_jacks(codec);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001814 if (codec->patch_ops.unsol_event) {
1815 cxt5051_hp_automute(codec);
1816 cxt5051_portb_automic(codec);
1817 cxt5051_portc_automic(codec);
1818 }
1819 return 0;
1820}
1821
1822
1823enum {
1824 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1825 CXT5051_HP, /* no docking */
1826 CXT5051_MODELS
1827};
1828
1829static const char *cxt5051_models[CXT5051_MODELS] = {
1830 [CXT5051_LAPTOP] = "laptop",
1831 [CXT5051_HP] = "hp",
1832};
1833
1834static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1835 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1836 CXT5051_LAPTOP),
1837 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1838 {}
1839};
1840
1841static int patch_cxt5051(struct hda_codec *codec)
1842{
1843 struct conexant_spec *spec;
1844 int board_config;
1845
1846 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1847 if (!spec)
1848 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001849 codec->spec = spec;
1850
1851 codec->patch_ops = conexant_patch_ops;
1852 codec->patch_ops.init = cxt5051_init;
1853
1854 spec->multiout.max_channels = 2;
1855 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1856 spec->multiout.dac_nids = cxt5051_dac_nids;
1857 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1858 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1859 spec->adc_nids = cxt5051_adc_nids;
1860 spec->num_mixers = 1;
1861 spec->mixers[0] = cxt5051_mixers;
1862 spec->num_init_verbs = 1;
1863 spec->init_verbs[0] = cxt5051_init_verbs;
1864 spec->spdif_route = 0;
1865 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1866 spec->channel_mode = cxt5051_modes;
1867 spec->cur_adc = 0;
1868 spec->cur_adc_idx = 0;
1869
1870 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1871 cxt5051_models,
1872 cxt5051_cfg_tbl);
1873 switch (board_config) {
1874 case CXT5051_HP:
1875 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1876 spec->mixers[0] = cxt5051_hp_mixers;
1877 break;
1878 default:
1879 case CXT5051_LAPTOP:
1880 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1881 break;
1882 }
1883
1884 return 0;
1885}
1886
1887
1888/*
1889 */
1890
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001891static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001892 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1893 .patch = patch_cxt5045 },
1894 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1895 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01001896 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1897 .patch = patch_cxt5051 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001898 {} /* terminator */
1899};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001900
1901MODULE_ALIAS("snd-hda-codec-id:14f15045");
1902MODULE_ALIAS("snd-hda-codec-id:14f15047");
1903MODULE_ALIAS("snd-hda-codec-id:14f15051");
1904
1905MODULE_LICENSE("GPL");
1906MODULE_DESCRIPTION("Conexant HD-audio codec");
1907
1908static struct hda_codec_preset_list conexant_list = {
1909 .preset = snd_hda_preset_conexant,
1910 .owner = THIS_MODULE,
1911};
1912
1913static int __init patch_conexant_init(void)
1914{
1915 return snd_hda_add_codec_preset(&conexant_list);
1916}
1917
1918static void __exit patch_conexant_exit(void)
1919{
1920 snd_hda_delete_codec_preset(&conexant_list);
1921}
1922
1923module_init(patch_conexant_init)
1924module_exit(patch_conexant_exit)