blob: 1938e92e1f036c5219dfceed347e86f64888964b [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;
Takashi Iwai79d7d532009-03-04 09:03:50 +010075 unsigned int no_auto_mic;
Tobin Davisc9b443d2006-11-14 12:13:39 +010076 unsigned int need_dac_fix;
77
78 /* capture */
79 unsigned int num_adc_nids;
80 hda_nid_t *adc_nids;
81 hda_nid_t dig_in_nid; /* digital-in NID; optional */
82
Takashi Iwai461e2c72008-01-25 11:35:17 +010083 unsigned int cur_adc_idx;
84 hda_nid_t cur_adc;
85 unsigned int cur_adc_stream_tag;
86 unsigned int cur_adc_format;
87
Tobin Davisc9b443d2006-11-14 12:13:39 +010088 /* capture source */
89 const struct hda_input_mux *input_mux;
90 hda_nid_t *capsrc_nids;
91 unsigned int cur_mux[3];
92
93 /* channel model */
94 const struct hda_channel_mode *channel_mode;
95 int num_channel_mode;
96
97 /* PCM information */
98 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
99
Tobin Davisc9b443d2006-11-14 12:13:39 +0100100 unsigned int spdif_route;
101
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100102 /* jack detection */
103 struct snd_array jacks;
104
Tobin Davisc9b443d2006-11-14 12:13:39 +0100105 /* dynamic controls, init_verbs and input_mux */
106 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100107 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +0200108 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100109
110};
111
112static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
113 struct hda_codec *codec,
114 struct snd_pcm_substream *substream)
115{
116 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100117 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
118 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100119}
120
121static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
122 struct hda_codec *codec,
123 unsigned int stream_tag,
124 unsigned int format,
125 struct snd_pcm_substream *substream)
126{
127 struct conexant_spec *spec = codec->spec;
128 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
129 stream_tag,
130 format, substream);
131}
132
133static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
134 struct hda_codec *codec,
135 struct snd_pcm_substream *substream)
136{
137 struct conexant_spec *spec = codec->spec;
138 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
139}
140
141/*
142 * Digital out
143 */
144static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
145 struct hda_codec *codec,
146 struct snd_pcm_substream *substream)
147{
148 struct conexant_spec *spec = codec->spec;
149 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
150}
151
152static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
153 struct hda_codec *codec,
154 struct snd_pcm_substream *substream)
155{
156 struct conexant_spec *spec = codec->spec;
157 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
158}
159
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200160static int conexant_dig_playback_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 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
168 stream_tag,
169 format, substream);
170}
171
Tobin Davisc9b443d2006-11-14 12:13:39 +0100172/*
173 * Analog capture
174 */
175static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
176 struct hda_codec *codec,
177 unsigned int stream_tag,
178 unsigned int format,
179 struct snd_pcm_substream *substream)
180{
181 struct conexant_spec *spec = codec->spec;
182 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
183 stream_tag, 0, format);
184 return 0;
185}
186
187static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
188 struct hda_codec *codec,
189 struct snd_pcm_substream *substream)
190{
191 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100192 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100193 return 0;
194}
195
196
197
198static struct hda_pcm_stream conexant_pcm_analog_playback = {
199 .substreams = 1,
200 .channels_min = 2,
201 .channels_max = 2,
202 .nid = 0, /* fill later */
203 .ops = {
204 .open = conexant_playback_pcm_open,
205 .prepare = conexant_playback_pcm_prepare,
206 .cleanup = conexant_playback_pcm_cleanup
207 },
208};
209
210static struct hda_pcm_stream conexant_pcm_analog_capture = {
211 .substreams = 1,
212 .channels_min = 2,
213 .channels_max = 2,
214 .nid = 0, /* fill later */
215 .ops = {
216 .prepare = conexant_capture_pcm_prepare,
217 .cleanup = conexant_capture_pcm_cleanup
218 },
219};
220
221
222static struct hda_pcm_stream conexant_pcm_digital_playback = {
223 .substreams = 1,
224 .channels_min = 2,
225 .channels_max = 2,
226 .nid = 0, /* fill later */
227 .ops = {
228 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200229 .close = conexant_dig_playback_pcm_close,
230 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100231 },
232};
233
234static struct hda_pcm_stream conexant_pcm_digital_capture = {
235 .substreams = 1,
236 .channels_min = 2,
237 .channels_max = 2,
238 /* NID is set in alc_build_pcms */
239};
240
Takashi Iwai461e2c72008-01-25 11:35:17 +0100241static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
242 struct hda_codec *codec,
243 unsigned int stream_tag,
244 unsigned int format,
245 struct snd_pcm_substream *substream)
246{
247 struct conexant_spec *spec = codec->spec;
248 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
249 spec->cur_adc_stream_tag = stream_tag;
250 spec->cur_adc_format = format;
251 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
252 return 0;
253}
254
255static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
256 struct hda_codec *codec,
257 struct snd_pcm_substream *substream)
258{
259 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100260 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100261 spec->cur_adc = 0;
262 return 0;
263}
264
265static struct hda_pcm_stream cx5051_pcm_analog_capture = {
266 .substreams = 1,
267 .channels_min = 2,
268 .channels_max = 2,
269 .nid = 0, /* fill later */
270 .ops = {
271 .prepare = cx5051_capture_pcm_prepare,
272 .cleanup = cx5051_capture_pcm_cleanup
273 },
274};
275
Tobin Davisc9b443d2006-11-14 12:13:39 +0100276static int conexant_build_pcms(struct hda_codec *codec)
277{
278 struct conexant_spec *spec = codec->spec;
279 struct hda_pcm *info = spec->pcm_rec;
280
281 codec->num_pcms = 1;
282 codec->pcm_info = info;
283
284 info->name = "CONEXANT Analog";
285 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
286 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
287 spec->multiout.max_channels;
288 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
289 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100290 if (codec->vendor_id == 0x14f15051)
291 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
292 cx5051_pcm_analog_capture;
293 else
294 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
295 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100296 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
297 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
298
299 if (spec->multiout.dig_out_nid) {
300 info++;
301 codec->num_pcms++;
302 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100303 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100304 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
305 conexant_pcm_digital_playback;
306 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
307 spec->multiout.dig_out_nid;
308 if (spec->dig_in_nid) {
309 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
310 conexant_pcm_digital_capture;
311 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
312 spec->dig_in_nid;
313 }
314 }
315
316 return 0;
317}
318
319static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
320 struct snd_ctl_elem_info *uinfo)
321{
322 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
323 struct conexant_spec *spec = codec->spec;
324
325 return snd_hda_input_mux_info(spec->input_mux, uinfo);
326}
327
328static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
329 struct snd_ctl_elem_value *ucontrol)
330{
331 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
332 struct conexant_spec *spec = codec->spec;
333 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
334
335 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
336 return 0;
337}
338
339static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
340 struct snd_ctl_elem_value *ucontrol)
341{
342 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
343 struct conexant_spec *spec = codec->spec;
344 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
345
346 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
347 spec->capsrc_nids[adc_idx],
348 &spec->cur_mux[adc_idx]);
349}
350
Takashi Iwai5801f992009-01-27 12:53:22 +0100351#ifdef CONFIG_SND_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100352static int conexant_add_jack(struct hda_codec *codec,
353 hda_nid_t nid, int type)
354{
355 struct conexant_spec *spec;
356 struct conexant_jack *jack;
357 const char *name;
358
359 spec = codec->spec;
360 snd_array_init(&spec->jacks, sizeof(*jack), 32);
361 jack = snd_array_new(&spec->jacks);
362 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
363
364 if (!jack)
365 return -ENOMEM;
366
367 jack->nid = nid;
368 jack->type = type;
369
370 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
371}
372
373static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
374{
375 struct conexant_spec *spec = codec->spec;
376 struct conexant_jack *jacks = spec->jacks.list;
377
378 if (jacks) {
379 int i;
380 for (i = 0; i < spec->jacks.used; i++) {
381 if (jacks->nid == nid) {
382 unsigned int present;
383 present = snd_hda_codec_read(codec, nid, 0,
384 AC_VERB_GET_PIN_SENSE, 0) &
385 AC_PINSENSE_PRESENCE;
386
387 present = (present) ? jacks->type : 0 ;
388
389 snd_jack_report(jacks->jack,
390 present);
391 }
392 jacks++;
393 }
394 }
395}
396
397static int conexant_init_jacks(struct hda_codec *codec)
398{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100399 struct conexant_spec *spec = codec->spec;
400 int i;
401
402 for (i = 0; i < spec->num_init_verbs; i++) {
403 const struct hda_verb *hv;
404
405 hv = spec->init_verbs[i];
406 while (hv->nid) {
407 int err = 0;
408 switch (hv->param ^ AC_USRSP_EN) {
409 case CONEXANT_HP_EVENT:
410 err = conexant_add_jack(codec, hv->nid,
411 SND_JACK_HEADPHONE);
412 conexant_report_jack(codec, hv->nid);
413 break;
414 case CXT5051_PORTC_EVENT:
415 case CONEXANT_MIC_EVENT:
416 err = conexant_add_jack(codec, hv->nid,
417 SND_JACK_MICROPHONE);
418 conexant_report_jack(codec, hv->nid);
419 break;
420 }
421 if (err < 0)
422 return err;
423 ++hv;
424 }
425 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100426 return 0;
427
428}
Takashi Iwai5801f992009-01-27 12:53:22 +0100429#else
430static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
431{
432}
433
434static inline int conexant_init_jacks(struct hda_codec *codec)
435{
436 return 0;
437}
438#endif
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100439
Tobin Davisc9b443d2006-11-14 12:13:39 +0100440static int conexant_init(struct hda_codec *codec)
441{
442 struct conexant_spec *spec = codec->spec;
443 int i;
444
445 for (i = 0; i < spec->num_init_verbs; i++)
446 snd_hda_sequence_write(codec, spec->init_verbs[i]);
447 return 0;
448}
449
450static void conexant_free(struct hda_codec *codec)
451{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100452#ifdef CONFIG_SND_JACK
453 struct conexant_spec *spec = codec->spec;
454 if (spec->jacks.list) {
455 struct conexant_jack *jacks = spec->jacks.list;
456 int i;
457 for (i = 0; i < spec->jacks.used; i++)
458 snd_device_free(codec->bus->card, &jacks[i].jack);
459 snd_array_free(&spec->jacks);
460 }
461#endif
Tobin Davisc9b443d2006-11-14 12:13:39 +0100462 kfree(codec->spec);
463}
464
Tobin Davisc9b443d2006-11-14 12:13:39 +0100465static int conexant_build_controls(struct hda_codec *codec)
466{
467 struct conexant_spec *spec = codec->spec;
468 unsigned int i;
469 int err;
470
471 for (i = 0; i < spec->num_mixers; i++) {
472 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
473 if (err < 0)
474 return err;
475 }
476 if (spec->multiout.dig_out_nid) {
477 err = snd_hda_create_spdif_out_ctls(codec,
478 spec->multiout.dig_out_nid);
479 if (err < 0)
480 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100481 err = snd_hda_create_spdif_share_sw(codec,
482 &spec->multiout);
483 if (err < 0)
484 return err;
485 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100486 }
487 if (spec->dig_in_nid) {
488 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
489 if (err < 0)
490 return err;
491 }
492 return 0;
493}
494
495static struct hda_codec_ops conexant_patch_ops = {
496 .build_controls = conexant_build_controls,
497 .build_pcms = conexant_build_pcms,
498 .init = conexant_init,
499 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100500};
501
502/*
503 * EAPD control
504 * the private value = nid | (invert << 8)
505 */
506
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200507#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100508
Tobin Davis82f30042007-02-13 12:45:44 +0100509static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100510 struct snd_ctl_elem_value *ucontrol)
511{
512 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
513 struct conexant_spec *spec = codec->spec;
514 int invert = (kcontrol->private_value >> 8) & 1;
515 if (invert)
516 ucontrol->value.integer.value[0] = !spec->cur_eapd;
517 else
518 ucontrol->value.integer.value[0] = spec->cur_eapd;
519 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100520
Tobin Davisc9b443d2006-11-14 12:13:39 +0100521}
522
Tobin Davis82f30042007-02-13 12:45:44 +0100523static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100524 struct snd_ctl_elem_value *ucontrol)
525{
526 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
527 struct conexant_spec *spec = codec->spec;
528 int invert = (kcontrol->private_value >> 8) & 1;
529 hda_nid_t nid = kcontrol->private_value & 0xff;
530 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100531
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100532 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100533 if (invert)
534 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200535 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100536 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100537
Tobin Davisc9b443d2006-11-14 12:13:39 +0100538 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200539 snd_hda_codec_write_cache(codec, nid,
540 0, AC_VERB_SET_EAPD_BTLENABLE,
541 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100542 return 1;
543}
544
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100545/* controls for test mode */
546#ifdef CONFIG_SND_DEBUG
547
Tobin Davis82f30042007-02-13 12:45:44 +0100548#define CXT_EAPD_SWITCH(xname, nid, mask) \
549 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
550 .info = cxt_eapd_info, \
551 .get = cxt_eapd_get, \
552 .put = cxt_eapd_put, \
553 .private_value = nid | (mask<<16) }
554
555
556
Tobin Davisc9b443d2006-11-14 12:13:39 +0100557static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
558 struct snd_ctl_elem_info *uinfo)
559{
560 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
561 struct conexant_spec *spec = codec->spec;
562 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
563 spec->num_channel_mode);
564}
565
566static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
567 struct snd_ctl_elem_value *ucontrol)
568{
569 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
570 struct conexant_spec *spec = codec->spec;
571 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
572 spec->num_channel_mode,
573 spec->multiout.max_channels);
574}
575
576static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
577 struct snd_ctl_elem_value *ucontrol)
578{
579 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
580 struct conexant_spec *spec = codec->spec;
581 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
582 spec->num_channel_mode,
583 &spec->multiout.max_channels);
584 if (err >= 0 && spec->need_dac_fix)
585 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
586 return err;
587}
588
589#define CXT_PIN_MODE(xname, nid, dir) \
590 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
591 .info = conexant_ch_mode_info, \
592 .get = conexant_ch_mode_get, \
593 .put = conexant_ch_mode_put, \
594 .private_value = nid | (dir<<16) }
595
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100596#endif /* CONFIG_SND_DEBUG */
597
Tobin Davisc9b443d2006-11-14 12:13:39 +0100598/* Conexant 5045 specific */
599
600static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
601static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
602static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100603#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100604
Tobin Davis5cd57522006-11-20 17:42:09 +0100605static struct hda_channel_mode cxt5045_modes[1] = {
606 { 2, NULL },
607};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100608
609static struct hda_input_mux cxt5045_capture_source = {
610 .num_items = 2,
611 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100612 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100613 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100614 }
615};
616
Jiang Zhe5218c892008-01-17 11:18:41 +0100617static struct hda_input_mux cxt5045_capture_source_benq = {
618 .num_items = 3,
619 .items = {
620 { "IntMic", 0x1 },
621 { "ExtMic", 0x2 },
622 { "LineIn", 0x3 },
623 }
624};
625
Jiang zhe2de3c232008-03-06 11:09:09 +0100626static struct hda_input_mux cxt5045_capture_source_hp530 = {
627 .num_items = 2,
628 .items = {
629 { "ExtMic", 0x1 },
630 { "IntMic", 0x2 },
631 }
632};
633
Tobin Davisc9b443d2006-11-14 12:13:39 +0100634/* turn on/off EAPD (+ mute HP) as a master switch */
635static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
636 struct snd_ctl_elem_value *ucontrol)
637{
638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100640 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100641
Tobin Davis82f30042007-02-13 12:45:44 +0100642 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100643 return 0;
644
Tobin Davis82f30042007-02-13 12:45:44 +0100645 /* toggle internal speakers mute depending of presence of
646 * the headphone jack
647 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200648 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
649 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
650 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100651
Takashi Iwai47fd8302007-08-10 17:11:07 +0200652 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
653 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
654 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100655 return 1;
656}
657
658/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200659static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
660 .ops = &snd_hda_bind_vol,
661 .values = {
662 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
663 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
664 0
665 },
666};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100667
Tobin Davis7f296732007-03-12 11:39:01 +0100668/* toggle input of built-in and mic jack appropriately */
669static void cxt5045_hp_automic(struct hda_codec *codec)
670{
671 static struct hda_verb mic_jack_on[] = {
672 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
673 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
674 {}
675 };
676 static struct hda_verb mic_jack_off[] = {
677 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
678 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
679 {}
680 };
681 unsigned int present;
682
683 present = snd_hda_codec_read(codec, 0x12, 0,
684 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
685 if (present)
686 snd_hda_sequence_write(codec, mic_jack_on);
687 else
688 snd_hda_sequence_write(codec, mic_jack_off);
689}
690
Tobin Davisc9b443d2006-11-14 12:13:39 +0100691
692/* mute internal speaker if HP is plugged */
693static void cxt5045_hp_automute(struct hda_codec *codec)
694{
Tobin Davis82f30042007-02-13 12:45:44 +0100695 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100696 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100697
Tobin Davis82f30042007-02-13 12:45:44 +0100698 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100699 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100700
Takashi Iwai47fd8302007-08-10 17:11:07 +0200701 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
702 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
703 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100704}
705
706/* unsolicited event for HP jack sensing */
707static void cxt5045_hp_unsol_event(struct hda_codec *codec,
708 unsigned int res)
709{
710 res >>= 26;
711 switch (res) {
712 case CONEXANT_HP_EVENT:
713 cxt5045_hp_automute(codec);
714 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100715 case CONEXANT_MIC_EVENT:
716 cxt5045_hp_automic(codec);
717 break;
718
Tobin Davisc9b443d2006-11-14 12:13:39 +0100719 }
720}
721
722static struct snd_kcontrol_new cxt5045_mixers[] = {
723 {
724 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
725 .name = "Capture Source",
726 .info = conexant_mux_enum_info,
727 .get = conexant_mux_enum_get,
728 .put = conexant_mux_enum_put
729 },
Takashi Iwaic8229c32007-10-19 08:06:21 +0200730 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
731 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
732 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
733 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
734 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
735 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
736 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
737 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
738 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
739 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200740 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100741 {
742 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
743 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100744 .info = cxt_eapd_info,
745 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100746 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100747 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100748 },
749
750 {}
751};
752
Jiang Zhe5218c892008-01-17 11:18:41 +0100753static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
754 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
755 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
756 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
757 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
758
759 {}
760};
761
Jiang zhe2de3c232008-03-06 11:09:09 +0100762static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
763 {
764 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
765 .name = "Capture Source",
766 .info = conexant_mux_enum_info,
767 .get = conexant_mux_enum_get,
768 .put = conexant_mux_enum_put
769 },
770 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
771 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
772 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
773 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
774 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
775 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
776 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
777 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
778 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
779 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
780 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
781 {
782 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
783 .name = "Master Playback Switch",
784 .info = cxt_eapd_info,
785 .get = cxt_eapd_get,
786 .put = cxt5045_hp_master_sw_put,
787 .private_value = 0x10,
788 },
789
790 {}
791};
792
Tobin Davisc9b443d2006-11-14 12:13:39 +0100793static struct hda_verb cxt5045_init_verbs[] = {
794 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200795 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100796 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100797 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200798 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
799 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
800 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
801 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
802 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
803 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
804 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
805 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
806 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100807 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100808 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100809 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100810 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
811 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100812 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100813 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100814 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100815 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100816 { } /* end */
817};
818
Jiang Zhe5218c892008-01-17 11:18:41 +0100819static struct hda_verb cxt5045_benq_init_verbs[] = {
820 /* Int Mic, Mic */
821 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
822 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
823 /* Line In,HP, Amp */
824 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
825 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
826 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
827 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
828 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
829 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
830 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
831 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
832 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
833 /* Record selector: Int mic */
834 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
835 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
836 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
837 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100838 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100839 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
840 /* EAPD */
841 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
842 { } /* end */
843};
Tobin Davis7f296732007-03-12 11:39:01 +0100844
845static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
846 /* pin sensing on HP jack */
847 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200848 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100849};
850
851static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
852 /* pin sensing on HP jack */
853 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200854 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100855};
856
Tobin Davisc9b443d2006-11-14 12:13:39 +0100857#ifdef CONFIG_SND_DEBUG
858/* Test configuration for debugging, modelled after the ALC260 test
859 * configuration.
860 */
861static struct hda_input_mux cxt5045_test_capture_source = {
862 .num_items = 5,
863 .items = {
864 { "MIXER", 0x0 },
865 { "MIC1 pin", 0x1 },
866 { "LINE1 pin", 0x2 },
867 { "HP-OUT pin", 0x3 },
868 { "CD pin", 0x4 },
869 },
870};
871
872static struct snd_kcontrol_new cxt5045_test_mixer[] = {
873
874 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100875 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
876 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100877 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
878 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
879 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
880 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100881
882 /* Modes for retasking pin widgets */
883 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
884 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
885
Tobin Davis82f30042007-02-13 12:45:44 +0100886 /* EAPD Switch Control */
887 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
888
Tobin Davisc9b443d2006-11-14 12:13:39 +0100889 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100890
Tobin Davis7f296732007-03-12 11:39:01 +0100891 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
892 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
893 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
894 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
895 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
896 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
897 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
898 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
899 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
900 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100901 {
902 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
903 .name = "Input Source",
904 .info = conexant_mux_enum_info,
905 .get = conexant_mux_enum_get,
906 .put = conexant_mux_enum_put,
907 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200908 /* Audio input controls */
909 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
910 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
911 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
912 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
913 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
914 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
915 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
916 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
917 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
918 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100919 { } /* end */
920};
921
922static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100923 /* Set connections */
924 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
925 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
926 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100927 /* Enable retasking pins as output, initially without power amp */
928 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100929 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100930
931 /* Disable digital (SPDIF) pins initially, but users can enable
932 * them via a mixer switch. In the case of SPDIF-out, this initverb
933 * payload also sets the generation to 0, output to be in "consumer"
934 * PCM format, copyright asserted, no pre-emphasis and no validity
935 * control.
936 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100937 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
938 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100939
940 /* Start with output sum widgets muted and their output gains at min */
941 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
942 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
943
944 /* Unmute retasking pin widget output buffers since the default
945 * state appears to be output. As the pin mode is changed by the
946 * user the pin mode control will take care of enabling the pin's
947 * input/output buffers as needed.
948 */
949 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
950 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
951
952 /* Mute capture amp left and right */
953 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
954
955 /* Set ADC connection select to match default mixer setting (mic1
956 * pin)
957 */
958 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +0100959 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100960
961 /* Mute all inputs to mixer widget (even unconnected ones) */
962 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
963 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
964 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
965 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
966 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
967
968 { }
969};
970#endif
971
972
973/* initialize jack-sensing, too */
974static int cxt5045_init(struct hda_codec *codec)
975{
976 conexant_init(codec);
977 cxt5045_hp_automute(codec);
978 return 0;
979}
980
981
982enum {
Marc Boucher15908c32008-01-22 15:15:59 +0100983 CXT5045_LAPTOP_HPSENSE,
984 CXT5045_LAPTOP_MICSENSE,
985 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +0100986 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +0100987 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100988#ifdef CONFIG_SND_DEBUG
989 CXT5045_TEST,
990#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100991 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100992};
993
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100994static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +0100995 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
996 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
997 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
998 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +0100999 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001000#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001001 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001002#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001003};
1004
1005static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001006 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001007 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1008 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001009 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001010 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001011 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1012 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001013 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1014 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001015 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1016 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1017 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001018 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1019 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001020 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001021 {}
1022};
1023
1024static int patch_cxt5045(struct hda_codec *codec)
1025{
1026 struct conexant_spec *spec;
1027 int board_config;
1028
1029 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1030 if (!spec)
1031 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001032 codec->spec = spec;
1033
1034 spec->multiout.max_channels = 2;
1035 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1036 spec->multiout.dac_nids = cxt5045_dac_nids;
1037 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1038 spec->num_adc_nids = 1;
1039 spec->adc_nids = cxt5045_adc_nids;
1040 spec->capsrc_nids = cxt5045_capsrc_nids;
1041 spec->input_mux = &cxt5045_capture_source;
1042 spec->num_mixers = 1;
1043 spec->mixers[0] = cxt5045_mixers;
1044 spec->num_init_verbs = 1;
1045 spec->init_verbs[0] = cxt5045_init_verbs;
1046 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001047 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1048 spec->channel_mode = cxt5045_modes,
1049
Tobin Davisc9b443d2006-11-14 12:13:39 +01001050
1051 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001052
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001053 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1054 cxt5045_models,
1055 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001056 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001057 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001058 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001059 spec->input_mux = &cxt5045_capture_source;
1060 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001061 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1062 spec->mixers[0] = cxt5045_mixers;
1063 codec->patch_ops.init = cxt5045_init;
1064 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001065 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001066 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001067 spec->input_mux = &cxt5045_capture_source;
1068 spec->num_init_verbs = 2;
1069 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001070 spec->mixers[0] = cxt5045_mixers;
1071 codec->patch_ops.init = cxt5045_init;
1072 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001073 default:
1074 case CXT5045_LAPTOP_HPMICSENSE:
1075 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1076 spec->input_mux = &cxt5045_capture_source;
1077 spec->num_init_verbs = 3;
1078 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1079 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1080 spec->mixers[0] = cxt5045_mixers;
1081 codec->patch_ops.init = cxt5045_init;
1082 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001083 case CXT5045_BENQ:
1084 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1085 spec->input_mux = &cxt5045_capture_source_benq;
1086 spec->num_init_verbs = 1;
1087 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1088 spec->mixers[0] = cxt5045_mixers;
1089 spec->mixers[1] = cxt5045_benq_mixers;
1090 spec->num_mixers = 2;
1091 codec->patch_ops.init = cxt5045_init;
1092 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001093 case CXT5045_LAPTOP_HP530:
1094 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1095 spec->input_mux = &cxt5045_capture_source_hp530;
1096 spec->num_init_verbs = 2;
1097 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1098 spec->mixers[0] = cxt5045_mixers_hp530;
1099 codec->patch_ops.init = cxt5045_init;
1100 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001101#ifdef CONFIG_SND_DEBUG
1102 case CXT5045_TEST:
1103 spec->input_mux = &cxt5045_test_capture_source;
1104 spec->mixers[0] = cxt5045_test_mixer;
1105 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001106 break;
1107
Tobin Davisc9b443d2006-11-14 12:13:39 +01001108#endif
1109 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001110
Takashi Iwai031005f2008-06-26 14:49:58 +02001111 switch (codec->subsystem_id >> 16) {
1112 case 0x103c:
1113 /* HP laptop has a really bad sound over 0dB on NID 0x17.
1114 * Fix max PCM level to 0 dB
1115 * (originall it has 0x2b steps with 0dB offset 0x14)
1116 */
1117 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1118 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1119 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1120 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1121 (1 << AC_AMPCAP_MUTE_SHIFT));
1122 break;
1123 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001124
Tobin Davisc9b443d2006-11-14 12:13:39 +01001125 return 0;
1126}
1127
1128
1129/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001130#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001131
Tobin Davis82f30042007-02-13 12:45:44 +01001132static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001133static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1134static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001135
Tobin Davis5cd57522006-11-20 17:42:09 +01001136static struct hda_channel_mode cxt5047_modes[1] = {
1137 { 2, NULL },
1138};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001139
1140static struct hda_input_mux cxt5047_capture_source = {
Tobin Davis7f296732007-03-12 11:39:01 +01001141 .num_items = 1,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001142 .items = {
Tobin Davis7f296732007-03-12 11:39:01 +01001143 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001144 }
1145};
1146
1147static struct hda_input_mux cxt5047_hp_capture_source = {
1148 .num_items = 1,
1149 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001150 { "ExtMic", 0x2 },
1151 }
1152};
1153
1154static struct hda_input_mux cxt5047_toshiba_capture_source = {
1155 .num_items = 2,
1156 .items = {
1157 { "ExtMic", 0x2 },
1158 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001159 }
1160};
1161
1162/* turn on/off EAPD (+ mute HP) as a master switch */
1163static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1164 struct snd_ctl_elem_value *ucontrol)
1165{
1166 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1167 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001168 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001169
Tobin Davis82f30042007-02-13 12:45:44 +01001170 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001171 return 0;
1172
Tobin Davis82f30042007-02-13 12:45:44 +01001173 /* toggle internal speakers mute depending of presence of
1174 * the headphone jack
1175 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001176 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1177 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1178 HDA_AMP_MUTE, bits);
1179 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1180 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1181 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001182 return 1;
1183}
1184
Tobin Davis82f30042007-02-13 12:45:44 +01001185/* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001186static struct hda_bind_ctls cxt5047_bind_master_vol = {
1187 .ops = &snd_hda_bind_vol,
1188 .values = {
1189 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1190 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1191 0
1192 },
1193};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001194
1195/* mute internal speaker if HP is plugged */
1196static void cxt5047_hp_automute(struct hda_codec *codec)
1197{
Tobin Davis82f30042007-02-13 12:45:44 +01001198 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001199 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001200
Tobin Davis82f30042007-02-13 12:45:44 +01001201 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001202 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +01001203
Takashi Iwai47fd8302007-08-10 17:11:07 +02001204 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1205 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1206 HDA_AMP_MUTE, bits);
Tobin Davis82f30042007-02-13 12:45:44 +01001207 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001208 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1209 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001210}
1211
Tobin Davisfb3409e2007-05-17 09:40:47 +02001212/* mute internal speaker if HP is plugged */
1213static void cxt5047_hp2_automute(struct hda_codec *codec)
1214{
1215 struct conexant_spec *spec = codec->spec;
1216 unsigned int bits;
1217
1218 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1219 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1220
Takashi Iwai47fd8302007-08-10 17:11:07 +02001221 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1222 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1223 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001224 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001225 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1226 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001227}
1228
Tobin Davisc9b443d2006-11-14 12:13:39 +01001229/* toggle input of built-in and mic jack appropriately */
1230static void cxt5047_hp_automic(struct hda_codec *codec)
1231{
1232 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001233 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1234 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001235 {}
1236 };
1237 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001238 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1239 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001240 {}
1241 };
1242 unsigned int present;
1243
Tobin Davis7f296732007-03-12 11:39:01 +01001244 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001245 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1246 if (present)
1247 snd_hda_sequence_write(codec, mic_jack_on);
1248 else
1249 snd_hda_sequence_write(codec, mic_jack_off);
1250}
1251
1252/* unsolicited event for HP jack sensing */
1253static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1254 unsigned int res)
1255{
Marc Boucher9f113e02008-01-22 15:18:08 +01001256 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001257 case CONEXANT_HP_EVENT:
1258 cxt5047_hp_automute(codec);
1259 break;
1260 case CONEXANT_MIC_EVENT:
1261 cxt5047_hp_automic(codec);
1262 break;
1263 }
1264}
1265
Tobin Davisfb3409e2007-05-17 09:40:47 +02001266/* unsolicited event for HP jack sensing - non-EAPD systems */
1267static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1268 unsigned int res)
1269{
1270 res >>= 26;
1271 switch (res) {
1272 case CONEXANT_HP_EVENT:
1273 cxt5047_hp2_automute(codec);
1274 break;
1275 case CONEXANT_MIC_EVENT:
1276 cxt5047_hp_automic(codec);
1277 break;
1278 }
1279}
1280
Tobin Davisc9b443d2006-11-14 12:13:39 +01001281static struct snd_kcontrol_new cxt5047_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001282 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1283 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001284 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1285 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001286 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1287 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1288 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1289 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001290 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1291 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
Tobin Davisb7589ce2007-04-24 17:56:55 +02001292 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1293 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1294 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1295 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001296
1297 {}
1298};
1299
1300static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1301 {
1302 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1303 .name = "Capture Source",
1304 .info = conexant_mux_enum_info,
1305 .get = conexant_mux_enum_get,
1306 .put = conexant_mux_enum_put
1307 },
1308 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1309 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1310 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1311 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1312 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1313 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +02001314 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
Tobin Davis82f30042007-02-13 12:45:44 +01001315 {
1316 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1317 .name = "Master Playback Switch",
1318 .info = cxt_eapd_info,
1319 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001320 .put = cxt5047_hp_master_sw_put,
1321 .private_value = 0x13,
1322 },
1323
1324 {}
1325};
1326
1327static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1328 {
1329 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1330 .name = "Capture Source",
1331 .info = conexant_mux_enum_info,
1332 .get = conexant_mux_enum_get,
1333 .put = conexant_mux_enum_put
1334 },
1335 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1336 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1337 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1338 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1339 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1340 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1341 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1342 {
1343 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1344 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001345 .info = cxt_eapd_info,
1346 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001347 .put = cxt5047_hp_master_sw_put,
1348 .private_value = 0x13,
1349 },
1350 { } /* end */
1351};
1352
1353static struct hda_verb cxt5047_init_verbs[] = {
1354 /* Line in, Mic, Built-in Mic */
1355 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1356 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1357 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001358 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001359 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1360 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis7f296732007-03-12 11:39:01 +01001361 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1362 /* Record selector: Mic */
1363 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1364 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1365 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1366 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001367 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1368 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1369 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1370 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001371 /* SPDIF route: PCM */
1372 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001373 /* Enable unsolicited events */
1374 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1375 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001376 { } /* end */
1377};
1378
1379/* configuration for Toshiba Laptops */
1380static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1381 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1382 /* pin sensing on HP and Mic jacks */
1383 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1384 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001385 /* Speaker routing */
1386 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001387 {}
1388};
1389
1390/* configuration for HP Laptops */
1391static struct hda_verb cxt5047_hp_init_verbs[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001392 /* pin sensing on HP jack */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001393 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaib84f08d2008-02-18 12:36:11 +01001394 /* 0x13 is actually shared by both HP and speaker;
1395 * setting the connection to 0 (=0x19) makes the master volume control
1396 * working mysteriouslly...
1397 */
1398 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
Tobin Davis82f30042007-02-13 12:45:44 +01001399 /* Record selector: Ext Mic */
1400 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
Tobin Davis82f30042007-02-13 12:45:44 +01001401 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1402 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1403 /* Speaker routing */
1404 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001405 {}
1406};
1407
1408/* Test configuration for debugging, modelled after the ALC260 test
1409 * configuration.
1410 */
1411#ifdef CONFIG_SND_DEBUG
1412static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001413 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001414 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001415 { "LINE1 pin", 0x0 },
1416 { "MIC1 pin", 0x1 },
1417 { "MIC2 pin", 0x2 },
1418 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001419 },
1420};
1421
1422static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1423
1424 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001425 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1426 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1427 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1428 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001429 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1430 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1431 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1432 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001433 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1434 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1435 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1436 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001437
1438 /* Modes for retasking pin widgets */
1439 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1440 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1441
Tobin Davis82f30042007-02-13 12:45:44 +01001442 /* EAPD Switch Control */
1443 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1444
Tobin Davisc9b443d2006-11-14 12:13:39 +01001445 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001446 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1447 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1448 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1449 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1450 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1451 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1452 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1453 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001454
Tobin Davis82f30042007-02-13 12:45:44 +01001455 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1456 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1457 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1458 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1459 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1460 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1461 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1462 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001463 {
1464 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1465 .name = "Input Source",
1466 .info = conexant_mux_enum_info,
1467 .get = conexant_mux_enum_get,
1468 .put = conexant_mux_enum_put,
1469 },
Marc Boucher9f113e02008-01-22 15:18:08 +01001470 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1471 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1472 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1473 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1474 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1475 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1476 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1477 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1478 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1479 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1480
Tobin Davisc9b443d2006-11-14 12:13:39 +01001481 { } /* end */
1482};
1483
1484static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001485 /* Enable retasking pins as output, initially without power amp */
1486 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1487 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1488 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1489
1490 /* Disable digital (SPDIF) pins initially, but users can enable
1491 * them via a mixer switch. In the case of SPDIF-out, this initverb
1492 * payload also sets the generation to 0, output to be in "consumer"
1493 * PCM format, copyright asserted, no pre-emphasis and no validity
1494 * control.
1495 */
1496 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1497
1498 /* Ensure mic1, mic2, line1 pin widgets take input from the
1499 * OUT1 sum bus when acting as an output.
1500 */
1501 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1502 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1503
1504 /* Start with output sum widgets muted and their output gains at min */
1505 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1506 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1507
1508 /* Unmute retasking pin widget output buffers since the default
1509 * state appears to be output. As the pin mode is changed by the
1510 * user the pin mode control will take care of enabling the pin's
1511 * input/output buffers as needed.
1512 */
1513 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1514 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1515 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1516
1517 /* Mute capture amp left and right */
1518 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1519
1520 /* Set ADC connection select to match default mixer setting (mic1
1521 * pin)
1522 */
1523 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1524
1525 /* Mute all inputs to mixer widget (even unconnected ones) */
1526 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1527 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1530 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1531 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1532 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1533 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1534
1535 { }
1536};
1537#endif
1538
1539
1540/* initialize jack-sensing, too */
1541static int cxt5047_hp_init(struct hda_codec *codec)
1542{
1543 conexant_init(codec);
1544 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001545 return 0;
1546}
1547
1548
1549enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001550 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1551 CXT5047_LAPTOP_HP, /* Some HP laptops */
1552 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001553#ifdef CONFIG_SND_DEBUG
1554 CXT5047_TEST,
1555#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001556 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001557};
1558
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001559static const char *cxt5047_models[CXT5047_MODELS] = {
1560 [CXT5047_LAPTOP] = "laptop",
1561 [CXT5047_LAPTOP_HP] = "laptop-hp",
1562 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001563#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001564 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001565#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001566};
1567
1568static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001569 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001570 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1571 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001572 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001573 {}
1574};
1575
1576static int patch_cxt5047(struct hda_codec *codec)
1577{
1578 struct conexant_spec *spec;
1579 int board_config;
1580
1581 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1582 if (!spec)
1583 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001584 codec->spec = spec;
1585
1586 spec->multiout.max_channels = 2;
1587 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1588 spec->multiout.dac_nids = cxt5047_dac_nids;
1589 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1590 spec->num_adc_nids = 1;
1591 spec->adc_nids = cxt5047_adc_nids;
1592 spec->capsrc_nids = cxt5047_capsrc_nids;
1593 spec->input_mux = &cxt5047_capture_source;
1594 spec->num_mixers = 1;
1595 spec->mixers[0] = cxt5047_mixers;
1596 spec->num_init_verbs = 1;
1597 spec->init_verbs[0] = cxt5047_init_verbs;
1598 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001599 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1600 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001601
1602 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001603
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001604 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1605 cxt5047_models,
1606 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001607 switch (board_config) {
1608 case CXT5047_LAPTOP:
Tobin Davisfb3409e2007-05-17 09:40:47 +02001609 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001610 break;
1611 case CXT5047_LAPTOP_HP:
1612 spec->input_mux = &cxt5047_hp_capture_source;
1613 spec->num_init_verbs = 2;
1614 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1615 spec->mixers[0] = cxt5047_hp_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001616 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001617 codec->patch_ops.init = cxt5047_hp_init;
1618 break;
1619 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001620 spec->input_mux = &cxt5047_toshiba_capture_source;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001621 spec->num_init_verbs = 2;
1622 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davis82f30042007-02-13 12:45:44 +01001623 spec->mixers[0] = cxt5047_toshiba_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001624 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001625 break;
1626#ifdef CONFIG_SND_DEBUG
1627 case CXT5047_TEST:
1628 spec->input_mux = &cxt5047_test_capture_source;
1629 spec->mixers[0] = cxt5047_test_mixer;
1630 spec->init_verbs[0] = cxt5047_test_init_verbs;
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#endif
1633 }
1634 return 0;
1635}
1636
Takashi Iwai461e2c72008-01-25 11:35:17 +01001637/* Conexant 5051 specific */
1638static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1639static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001640
1641static struct hda_channel_mode cxt5051_modes[1] = {
1642 { 2, NULL },
1643};
1644
1645static void cxt5051_update_speaker(struct hda_codec *codec)
1646{
1647 struct conexant_spec *spec = codec->spec;
1648 unsigned int pinctl;
1649 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1650 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1651 pinctl);
1652}
1653
1654/* turn on/off EAPD (+ mute HP) as a master switch */
1655static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1656 struct snd_ctl_elem_value *ucontrol)
1657{
1658 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1659
1660 if (!cxt_eapd_put(kcontrol, ucontrol))
1661 return 0;
1662 cxt5051_update_speaker(codec);
1663 return 1;
1664}
1665
1666/* toggle input of built-in and mic jack appropriately */
1667static void cxt5051_portb_automic(struct hda_codec *codec)
1668{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001669 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001670 unsigned int present;
1671
Takashi Iwai79d7d532009-03-04 09:03:50 +01001672 if (spec->no_auto_mic)
1673 return;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001674 present = snd_hda_codec_read(codec, 0x17, 0,
1675 AC_VERB_GET_PIN_SENSE, 0) &
1676 AC_PINSENSE_PRESENCE;
1677 snd_hda_codec_write(codec, 0x14, 0,
1678 AC_VERB_SET_CONNECT_SEL,
1679 present ? 0x01 : 0x00);
1680}
1681
1682/* switch the current ADC according to the jack state */
1683static void cxt5051_portc_automic(struct hda_codec *codec)
1684{
1685 struct conexant_spec *spec = codec->spec;
1686 unsigned int present;
1687 hda_nid_t new_adc;
1688
Takashi Iwai79d7d532009-03-04 09:03:50 +01001689 if (spec->no_auto_mic)
1690 return;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001691 present = snd_hda_codec_read(codec, 0x18, 0,
1692 AC_VERB_GET_PIN_SENSE, 0) &
1693 AC_PINSENSE_PRESENCE;
1694 if (present)
1695 spec->cur_adc_idx = 1;
1696 else
1697 spec->cur_adc_idx = 0;
1698 new_adc = spec->adc_nids[spec->cur_adc_idx];
1699 if (spec->cur_adc && spec->cur_adc != new_adc) {
1700 /* stream is running, let's swap the current ADC */
Takashi Iwai888afa12008-03-18 09:57:50 +01001701 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001702 spec->cur_adc = new_adc;
1703 snd_hda_codec_setup_stream(codec, new_adc,
1704 spec->cur_adc_stream_tag, 0,
1705 spec->cur_adc_format);
1706 }
1707}
1708
1709/* mute internal speaker if HP is plugged */
1710static void cxt5051_hp_automute(struct hda_codec *codec)
1711{
1712 struct conexant_spec *spec = codec->spec;
1713
1714 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1715 AC_VERB_GET_PIN_SENSE, 0) &
1716 AC_PINSENSE_PRESENCE;
1717 cxt5051_update_speaker(codec);
1718}
1719
1720/* unsolicited event for HP jack sensing */
1721static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1722 unsigned int res)
1723{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001724 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001725 switch (res >> 26) {
1726 case CONEXANT_HP_EVENT:
1727 cxt5051_hp_automute(codec);
1728 break;
1729 case CXT5051_PORTB_EVENT:
1730 cxt5051_portb_automic(codec);
1731 break;
1732 case CXT5051_PORTC_EVENT:
1733 cxt5051_portc_automic(codec);
1734 break;
1735 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001736 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001737}
1738
1739static struct snd_kcontrol_new cxt5051_mixers[] = {
1740 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1741 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1742 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1743 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1744 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1745 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1746 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1747 {
1748 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1749 .name = "Master Playback Switch",
1750 .info = cxt_eapd_info,
1751 .get = cxt_eapd_get,
1752 .put = cxt5051_hp_master_sw_put,
1753 .private_value = 0x1a,
1754 },
1755
1756 {}
1757};
1758
1759static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1760 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1761 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1762 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1763 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1764 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1765 {
1766 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1767 .name = "Master Playback Switch",
1768 .info = cxt_eapd_info,
1769 .get = cxt_eapd_get,
1770 .put = cxt5051_hp_master_sw_put,
1771 .private_value = 0x1a,
1772 },
1773
1774 {}
1775};
1776
Takashi Iwai79d7d532009-03-04 09:03:50 +01001777static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1778 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
1779 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
1780 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1781 {
1782 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1783 .name = "Master Playback Switch",
1784 .info = cxt_eapd_info,
1785 .get = cxt_eapd_get,
1786 .put = cxt5051_hp_master_sw_put,
1787 .private_value = 0x1a,
1788 },
1789
1790 {}
1791};
1792
Takashi Iwai461e2c72008-01-25 11:35:17 +01001793static struct hda_verb cxt5051_init_verbs[] = {
1794 /* Line in, Mic */
1795 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1796 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1797 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1798 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1799 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1800 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1801 /* SPK */
1802 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1803 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1804 /* HP, Amp */
1805 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1806 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1807 /* DAC1 */
1808 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1809 /* Record selector: Int mic */
1810 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1811 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1812 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1813 /* SPDIF route: PCM */
1814 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1815 /* EAPD */
1816 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1817 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1818 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1819 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1820 { } /* end */
1821};
1822
Takashi Iwai79d7d532009-03-04 09:03:50 +01001823static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1824 /* Line in, Mic */
1825 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1826 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1827 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1828 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1829 /* SPK */
1830 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1831 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1832 /* HP, Amp */
1833 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1834 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1835 /* DAC1 */
1836 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1837 /* Record selector: Int mic */
1838 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1839 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1840 /* SPDIF route: PCM */
1841 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1842 /* EAPD */
1843 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1844 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1845 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1846 { } /* end */
1847};
1848
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001849static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1850 /* Line in, Mic */
1851 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1852 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1853 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1854 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1855 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1856 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1857 /* SPK */
1858 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1859 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1860 /* HP, Amp */
1861 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1862 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1863 /* Docking HP */
1864 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1865 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1866 /* DAC1 */
1867 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1868 /* Record selector: Int mic */
1869 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1870 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1871 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1872 /* SPDIF route: PCM */
1873 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1874 /* EAPD */
1875 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1876 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1877 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1878 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1879 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1880 { } /* end */
1881};
1882
Takashi Iwai461e2c72008-01-25 11:35:17 +01001883/* initialize jack-sensing, too */
1884static int cxt5051_init(struct hda_codec *codec)
1885{
1886 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001887 conexant_init_jacks(codec);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001888 if (codec->patch_ops.unsol_event) {
1889 cxt5051_hp_automute(codec);
1890 cxt5051_portb_automic(codec);
1891 cxt5051_portc_automic(codec);
1892 }
1893 return 0;
1894}
1895
1896
1897enum {
1898 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1899 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001900 CXT5051_HP_DV6736, /* HP without mic switch */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001901 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001902 CXT5051_MODELS
1903};
1904
1905static const char *cxt5051_models[CXT5051_MODELS] = {
1906 [CXT5051_LAPTOP] = "laptop",
1907 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001908 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001909 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001910};
1911
1912static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001913 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001914 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1915 CXT5051_LAPTOP),
1916 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001917 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001918 {}
1919};
1920
1921static int patch_cxt5051(struct hda_codec *codec)
1922{
1923 struct conexant_spec *spec;
1924 int board_config;
1925
1926 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1927 if (!spec)
1928 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001929 codec->spec = spec;
1930
1931 codec->patch_ops = conexant_patch_ops;
1932 codec->patch_ops.init = cxt5051_init;
1933
1934 spec->multiout.max_channels = 2;
1935 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1936 spec->multiout.dac_nids = cxt5051_dac_nids;
1937 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1938 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1939 spec->adc_nids = cxt5051_adc_nids;
1940 spec->num_mixers = 1;
1941 spec->mixers[0] = cxt5051_mixers;
1942 spec->num_init_verbs = 1;
1943 spec->init_verbs[0] = cxt5051_init_verbs;
1944 spec->spdif_route = 0;
1945 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1946 spec->channel_mode = cxt5051_modes;
1947 spec->cur_adc = 0;
1948 spec->cur_adc_idx = 0;
1949
Takashi Iwai79d7d532009-03-04 09:03:50 +01001950 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1951
Takashi Iwai461e2c72008-01-25 11:35:17 +01001952 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1953 cxt5051_models,
1954 cxt5051_cfg_tbl);
1955 switch (board_config) {
1956 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001957 spec->mixers[0] = cxt5051_hp_mixers;
1958 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001959 case CXT5051_HP_DV6736:
1960 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1961 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1962 spec->no_auto_mic = 1;
1963 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001964 case CXT5051_LENOVO_X200:
1965 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001966 break;
1967 }
1968
1969 return 0;
1970}
1971
1972
1973/*
1974 */
1975
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001976static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001977 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1978 .patch = patch_cxt5045 },
1979 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1980 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01001981 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1982 .patch = patch_cxt5051 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001983 {} /* terminator */
1984};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001985
1986MODULE_ALIAS("snd-hda-codec-id:14f15045");
1987MODULE_ALIAS("snd-hda-codec-id:14f15047");
1988MODULE_ALIAS("snd-hda-codec-id:14f15051");
1989
1990MODULE_LICENSE("GPL");
1991MODULE_DESCRIPTION("Conexant HD-audio codec");
1992
1993static struct hda_codec_preset_list conexant_list = {
1994 .preset = snd_hda_preset_conexant,
1995 .owner = THIS_MODULE,
1996};
1997
1998static int __init patch_conexant_init(void)
1999{
2000 return snd_hda_add_codec_preset(&conexant_list);
2001}
2002
2003static void __exit patch_conexant_exit(void)
2004{
2005 snd_hda_delete_codec_preset(&conexant_list);
2006}
2007
2008module_init(patch_conexant_init)
2009module_exit(patch_conexant_exit)