blob: b8de73ecfdeb5c09e7a88ce420972f612dc9c5c6 [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[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001005 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001006 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1007 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001008 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001009 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001010 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1011 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001012 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1013 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001014 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1015 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1016 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001017 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1018 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001019 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001020 {}
1021};
1022
1023static int patch_cxt5045(struct hda_codec *codec)
1024{
1025 struct conexant_spec *spec;
1026 int board_config;
1027
1028 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1029 if (!spec)
1030 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001031 codec->spec = spec;
1032
1033 spec->multiout.max_channels = 2;
1034 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1035 spec->multiout.dac_nids = cxt5045_dac_nids;
1036 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1037 spec->num_adc_nids = 1;
1038 spec->adc_nids = cxt5045_adc_nids;
1039 spec->capsrc_nids = cxt5045_capsrc_nids;
1040 spec->input_mux = &cxt5045_capture_source;
1041 spec->num_mixers = 1;
1042 spec->mixers[0] = cxt5045_mixers;
1043 spec->num_init_verbs = 1;
1044 spec->init_verbs[0] = cxt5045_init_verbs;
1045 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001046 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1047 spec->channel_mode = cxt5045_modes,
1048
Tobin Davisc9b443d2006-11-14 12:13:39 +01001049
1050 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001051
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001052 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1053 cxt5045_models,
1054 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001055 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001056 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001057 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001058 spec->input_mux = &cxt5045_capture_source;
1059 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001060 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1061 spec->mixers[0] = cxt5045_mixers;
1062 codec->patch_ops.init = cxt5045_init;
1063 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001064 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001065 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001066 spec->input_mux = &cxt5045_capture_source;
1067 spec->num_init_verbs = 2;
1068 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001069 spec->mixers[0] = cxt5045_mixers;
1070 codec->patch_ops.init = cxt5045_init;
1071 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001072 default:
1073 case CXT5045_LAPTOP_HPMICSENSE:
1074 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1075 spec->input_mux = &cxt5045_capture_source;
1076 spec->num_init_verbs = 3;
1077 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1078 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1079 spec->mixers[0] = cxt5045_mixers;
1080 codec->patch_ops.init = cxt5045_init;
1081 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001082 case CXT5045_BENQ:
1083 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1084 spec->input_mux = &cxt5045_capture_source_benq;
1085 spec->num_init_verbs = 1;
1086 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1087 spec->mixers[0] = cxt5045_mixers;
1088 spec->mixers[1] = cxt5045_benq_mixers;
1089 spec->num_mixers = 2;
1090 codec->patch_ops.init = cxt5045_init;
1091 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001092 case CXT5045_LAPTOP_HP530:
1093 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1094 spec->input_mux = &cxt5045_capture_source_hp530;
1095 spec->num_init_verbs = 2;
1096 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1097 spec->mixers[0] = cxt5045_mixers_hp530;
1098 codec->patch_ops.init = cxt5045_init;
1099 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001100#ifdef CONFIG_SND_DEBUG
1101 case CXT5045_TEST:
1102 spec->input_mux = &cxt5045_test_capture_source;
1103 spec->mixers[0] = cxt5045_test_mixer;
1104 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001105 break;
1106
Tobin Davisc9b443d2006-11-14 12:13:39 +01001107#endif
1108 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001109
Takashi Iwai031005f2008-06-26 14:49:58 +02001110 switch (codec->subsystem_id >> 16) {
1111 case 0x103c:
1112 /* HP laptop has a really bad sound over 0dB on NID 0x17.
1113 * Fix max PCM level to 0 dB
1114 * (originall it has 0x2b steps with 0dB offset 0x14)
1115 */
1116 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1117 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1118 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1119 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1120 (1 << AC_AMPCAP_MUTE_SHIFT));
1121 break;
1122 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001123
Tobin Davisc9b443d2006-11-14 12:13:39 +01001124 return 0;
1125}
1126
1127
1128/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001129#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001130
Tobin Davis82f30042007-02-13 12:45:44 +01001131static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001132static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1133static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001134
Tobin Davis5cd57522006-11-20 17:42:09 +01001135static struct hda_channel_mode cxt5047_modes[1] = {
1136 { 2, NULL },
1137};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001138
1139static struct hda_input_mux cxt5047_capture_source = {
Tobin Davis7f296732007-03-12 11:39:01 +01001140 .num_items = 1,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001141 .items = {
Tobin Davis7f296732007-03-12 11:39:01 +01001142 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001143 }
1144};
1145
1146static struct hda_input_mux cxt5047_hp_capture_source = {
1147 .num_items = 1,
1148 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001149 { "ExtMic", 0x2 },
1150 }
1151};
1152
1153static struct hda_input_mux cxt5047_toshiba_capture_source = {
1154 .num_items = 2,
1155 .items = {
1156 { "ExtMic", 0x2 },
1157 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001158 }
1159};
1160
1161/* turn on/off EAPD (+ mute HP) as a master switch */
1162static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1163 struct snd_ctl_elem_value *ucontrol)
1164{
1165 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1166 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001167 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001168
Tobin Davis82f30042007-02-13 12:45:44 +01001169 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001170 return 0;
1171
Tobin Davis82f30042007-02-13 12:45:44 +01001172 /* toggle internal speakers mute depending of presence of
1173 * the headphone jack
1174 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001175 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1176 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1177 HDA_AMP_MUTE, bits);
1178 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1179 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1180 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001181 return 1;
1182}
1183
Tobin Davis82f30042007-02-13 12:45:44 +01001184/* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001185static struct hda_bind_ctls cxt5047_bind_master_vol = {
1186 .ops = &snd_hda_bind_vol,
1187 .values = {
1188 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1189 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1190 0
1191 },
1192};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001193
1194/* mute internal speaker if HP is plugged */
1195static void cxt5047_hp_automute(struct hda_codec *codec)
1196{
Tobin Davis82f30042007-02-13 12:45:44 +01001197 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001198 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001199
Tobin Davis82f30042007-02-13 12:45:44 +01001200 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001201 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +01001202
Takashi Iwai47fd8302007-08-10 17:11:07 +02001203 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1204 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1205 HDA_AMP_MUTE, bits);
Tobin Davis82f30042007-02-13 12:45:44 +01001206 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001207 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1208 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001209}
1210
Tobin Davisfb3409e2007-05-17 09:40:47 +02001211/* mute internal speaker if HP is plugged */
1212static void cxt5047_hp2_automute(struct hda_codec *codec)
1213{
1214 struct conexant_spec *spec = codec->spec;
1215 unsigned int bits;
1216
1217 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1218 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1219
Takashi Iwai47fd8302007-08-10 17:11:07 +02001220 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1221 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1222 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001223 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001224 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1225 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001226}
1227
Tobin Davisc9b443d2006-11-14 12:13:39 +01001228/* toggle input of built-in and mic jack appropriately */
1229static void cxt5047_hp_automic(struct hda_codec *codec)
1230{
1231 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001232 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1233 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001234 {}
1235 };
1236 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001237 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1238 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001239 {}
1240 };
1241 unsigned int present;
1242
Tobin Davis7f296732007-03-12 11:39:01 +01001243 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001244 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1245 if (present)
1246 snd_hda_sequence_write(codec, mic_jack_on);
1247 else
1248 snd_hda_sequence_write(codec, mic_jack_off);
1249}
1250
1251/* unsolicited event for HP jack sensing */
1252static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1253 unsigned int res)
1254{
Marc Boucher9f113e02008-01-22 15:18:08 +01001255 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001256 case CONEXANT_HP_EVENT:
1257 cxt5047_hp_automute(codec);
1258 break;
1259 case CONEXANT_MIC_EVENT:
1260 cxt5047_hp_automic(codec);
1261 break;
1262 }
1263}
1264
Tobin Davisfb3409e2007-05-17 09:40:47 +02001265/* unsolicited event for HP jack sensing - non-EAPD systems */
1266static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1267 unsigned int res)
1268{
1269 res >>= 26;
1270 switch (res) {
1271 case CONEXANT_HP_EVENT:
1272 cxt5047_hp2_automute(codec);
1273 break;
1274 case CONEXANT_MIC_EVENT:
1275 cxt5047_hp_automic(codec);
1276 break;
1277 }
1278}
1279
Tobin Davisc9b443d2006-11-14 12:13:39 +01001280static struct snd_kcontrol_new cxt5047_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001281 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1282 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001283 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1284 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001285 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1286 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1287 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1288 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001289 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1290 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
Tobin Davisb7589ce2007-04-24 17:56:55 +02001291 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1292 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1293 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1294 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001295
1296 {}
1297};
1298
1299static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1300 {
1301 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1302 .name = "Capture Source",
1303 .info = conexant_mux_enum_info,
1304 .get = conexant_mux_enum_get,
1305 .put = conexant_mux_enum_put
1306 },
1307 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1308 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1309 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1310 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1311 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1312 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +02001313 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
Tobin Davis82f30042007-02-13 12:45:44 +01001314 {
1315 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1316 .name = "Master Playback Switch",
1317 .info = cxt_eapd_info,
1318 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001319 .put = cxt5047_hp_master_sw_put,
1320 .private_value = 0x13,
1321 },
1322
1323 {}
1324};
1325
1326static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1327 {
1328 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1329 .name = "Capture Source",
1330 .info = conexant_mux_enum_info,
1331 .get = conexant_mux_enum_get,
1332 .put = conexant_mux_enum_put
1333 },
1334 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1335 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1336 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1337 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1338 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1339 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1340 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1341 {
1342 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1343 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001344 .info = cxt_eapd_info,
1345 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001346 .put = cxt5047_hp_master_sw_put,
1347 .private_value = 0x13,
1348 },
1349 { } /* end */
1350};
1351
1352static struct hda_verb cxt5047_init_verbs[] = {
1353 /* Line in, Mic, Built-in Mic */
1354 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1355 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1356 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001357 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001358 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1359 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis7f296732007-03-12 11:39:01 +01001360 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1361 /* Record selector: Mic */
1362 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1363 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1364 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1365 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001366 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1367 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1368 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1369 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001370 /* SPDIF route: PCM */
1371 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001372 /* Enable unsolicited events */
1373 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1374 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001375 { } /* end */
1376};
1377
1378/* configuration for Toshiba Laptops */
1379static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1380 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1381 /* pin sensing on HP and Mic jacks */
1382 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1383 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001384 /* Speaker routing */
1385 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001386 {}
1387};
1388
1389/* configuration for HP Laptops */
1390static struct hda_verb cxt5047_hp_init_verbs[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001391 /* pin sensing on HP jack */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001392 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaib84f08d2008-02-18 12:36:11 +01001393 /* 0x13 is actually shared by both HP and speaker;
1394 * setting the connection to 0 (=0x19) makes the master volume control
1395 * working mysteriouslly...
1396 */
1397 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
Tobin Davis82f30042007-02-13 12:45:44 +01001398 /* Record selector: Ext Mic */
1399 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
Tobin Davis82f30042007-02-13 12:45:44 +01001400 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1401 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1402 /* Speaker routing */
1403 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001404 {}
1405};
1406
1407/* Test configuration for debugging, modelled after the ALC260 test
1408 * configuration.
1409 */
1410#ifdef CONFIG_SND_DEBUG
1411static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001412 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001413 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001414 { "LINE1 pin", 0x0 },
1415 { "MIC1 pin", 0x1 },
1416 { "MIC2 pin", 0x2 },
1417 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001418 },
1419};
1420
1421static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1422
1423 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001424 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1425 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1426 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1427 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001428 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1429 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1430 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1431 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001432 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1433 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1434 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1435 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001436
1437 /* Modes for retasking pin widgets */
1438 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1439 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1440
Tobin Davis82f30042007-02-13 12:45:44 +01001441 /* EAPD Switch Control */
1442 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1443
Tobin Davisc9b443d2006-11-14 12:13:39 +01001444 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001445 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1446 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1447 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1448 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1449 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1450 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1451 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1452 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001453
Tobin Davis82f30042007-02-13 12:45:44 +01001454 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1455 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1456 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1457 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1458 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1459 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1460 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1461 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001462 {
1463 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1464 .name = "Input Source",
1465 .info = conexant_mux_enum_info,
1466 .get = conexant_mux_enum_get,
1467 .put = conexant_mux_enum_put,
1468 },
Marc Boucher9f113e02008-01-22 15:18:08 +01001469 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1470 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1471 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1472 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1473 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1474 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1475 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1476 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1477 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1478 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1479
Tobin Davisc9b443d2006-11-14 12:13:39 +01001480 { } /* end */
1481};
1482
1483static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001484 /* Enable retasking pins as output, initially without power amp */
1485 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1486 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1487 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1488
1489 /* Disable digital (SPDIF) pins initially, but users can enable
1490 * them via a mixer switch. In the case of SPDIF-out, this initverb
1491 * payload also sets the generation to 0, output to be in "consumer"
1492 * PCM format, copyright asserted, no pre-emphasis and no validity
1493 * control.
1494 */
1495 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1496
1497 /* Ensure mic1, mic2, line1 pin widgets take input from the
1498 * OUT1 sum bus when acting as an output.
1499 */
1500 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1501 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1502
1503 /* Start with output sum widgets muted and their output gains at min */
1504 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1505 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1506
1507 /* Unmute retasking pin widget output buffers since the default
1508 * state appears to be output. As the pin mode is changed by the
1509 * user the pin mode control will take care of enabling the pin's
1510 * input/output buffers as needed.
1511 */
1512 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1513 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1514 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1515
1516 /* Mute capture amp left and right */
1517 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1518
1519 /* Set ADC connection select to match default mixer setting (mic1
1520 * pin)
1521 */
1522 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1523
1524 /* Mute all inputs to mixer widget (even unconnected ones) */
1525 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1526 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1527 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1530 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1531 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1532 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1533
1534 { }
1535};
1536#endif
1537
1538
1539/* initialize jack-sensing, too */
1540static int cxt5047_hp_init(struct hda_codec *codec)
1541{
1542 conexant_init(codec);
1543 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001544 return 0;
1545}
1546
1547
1548enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001549 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1550 CXT5047_LAPTOP_HP, /* Some HP laptops */
1551 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001552#ifdef CONFIG_SND_DEBUG
1553 CXT5047_TEST,
1554#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001555 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001556};
1557
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001558static const char *cxt5047_models[CXT5047_MODELS] = {
1559 [CXT5047_LAPTOP] = "laptop",
1560 [CXT5047_LAPTOP_HP] = "laptop-hp",
1561 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001562#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001563 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001564#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001565};
1566
1567static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001568 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001569 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1570 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001571 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001572 {}
1573};
1574
1575static int patch_cxt5047(struct hda_codec *codec)
1576{
1577 struct conexant_spec *spec;
1578 int board_config;
1579
1580 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1581 if (!spec)
1582 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001583 codec->spec = spec;
1584
1585 spec->multiout.max_channels = 2;
1586 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1587 spec->multiout.dac_nids = cxt5047_dac_nids;
1588 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1589 spec->num_adc_nids = 1;
1590 spec->adc_nids = cxt5047_adc_nids;
1591 spec->capsrc_nids = cxt5047_capsrc_nids;
1592 spec->input_mux = &cxt5047_capture_source;
1593 spec->num_mixers = 1;
1594 spec->mixers[0] = cxt5047_mixers;
1595 spec->num_init_verbs = 1;
1596 spec->init_verbs[0] = cxt5047_init_verbs;
1597 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001598 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1599 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001600
1601 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001602
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001603 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1604 cxt5047_models,
1605 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001606 switch (board_config) {
1607 case CXT5047_LAPTOP:
Tobin Davisfb3409e2007-05-17 09:40:47 +02001608 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001609 break;
1610 case CXT5047_LAPTOP_HP:
1611 spec->input_mux = &cxt5047_hp_capture_source;
1612 spec->num_init_verbs = 2;
1613 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1614 spec->mixers[0] = cxt5047_hp_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001615 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001616 codec->patch_ops.init = cxt5047_hp_init;
1617 break;
1618 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001619 spec->input_mux = &cxt5047_toshiba_capture_source;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001620 spec->num_init_verbs = 2;
1621 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davis82f30042007-02-13 12:45:44 +01001622 spec->mixers[0] = cxt5047_toshiba_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 break;
1625#ifdef CONFIG_SND_DEBUG
1626 case CXT5047_TEST:
1627 spec->input_mux = &cxt5047_test_capture_source;
1628 spec->mixers[0] = cxt5047_test_mixer;
1629 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001630 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001631#endif
1632 }
1633 return 0;
1634}
1635
Takashi Iwai461e2c72008-01-25 11:35:17 +01001636/* Conexant 5051 specific */
1637static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1638static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001639
1640static struct hda_channel_mode cxt5051_modes[1] = {
1641 { 2, NULL },
1642};
1643
1644static void cxt5051_update_speaker(struct hda_codec *codec)
1645{
1646 struct conexant_spec *spec = codec->spec;
1647 unsigned int pinctl;
1648 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1649 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1650 pinctl);
1651}
1652
1653/* turn on/off EAPD (+ mute HP) as a master switch */
1654static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1655 struct snd_ctl_elem_value *ucontrol)
1656{
1657 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1658
1659 if (!cxt_eapd_put(kcontrol, ucontrol))
1660 return 0;
1661 cxt5051_update_speaker(codec);
1662 return 1;
1663}
1664
1665/* toggle input of built-in and mic jack appropriately */
1666static void cxt5051_portb_automic(struct hda_codec *codec)
1667{
1668 unsigned int present;
1669
1670 present = snd_hda_codec_read(codec, 0x17, 0,
1671 AC_VERB_GET_PIN_SENSE, 0) &
1672 AC_PINSENSE_PRESENCE;
1673 snd_hda_codec_write(codec, 0x14, 0,
1674 AC_VERB_SET_CONNECT_SEL,
1675 present ? 0x01 : 0x00);
1676}
1677
1678/* switch the current ADC according to the jack state */
1679static void cxt5051_portc_automic(struct hda_codec *codec)
1680{
1681 struct conexant_spec *spec = codec->spec;
1682 unsigned int present;
1683 hda_nid_t new_adc;
1684
1685 present = snd_hda_codec_read(codec, 0x18, 0,
1686 AC_VERB_GET_PIN_SENSE, 0) &
1687 AC_PINSENSE_PRESENCE;
1688 if (present)
1689 spec->cur_adc_idx = 1;
1690 else
1691 spec->cur_adc_idx = 0;
1692 new_adc = spec->adc_nids[spec->cur_adc_idx];
1693 if (spec->cur_adc && spec->cur_adc != new_adc) {
1694 /* stream is running, let's swap the current ADC */
Takashi Iwai888afa12008-03-18 09:57:50 +01001695 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001696 spec->cur_adc = new_adc;
1697 snd_hda_codec_setup_stream(codec, new_adc,
1698 spec->cur_adc_stream_tag, 0,
1699 spec->cur_adc_format);
1700 }
1701}
1702
1703/* mute internal speaker if HP is plugged */
1704static void cxt5051_hp_automute(struct hda_codec *codec)
1705{
1706 struct conexant_spec *spec = codec->spec;
1707
1708 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1709 AC_VERB_GET_PIN_SENSE, 0) &
1710 AC_PINSENSE_PRESENCE;
1711 cxt5051_update_speaker(codec);
1712}
1713
1714/* unsolicited event for HP jack sensing */
1715static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1716 unsigned int res)
1717{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001718 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001719 switch (res >> 26) {
1720 case CONEXANT_HP_EVENT:
1721 cxt5051_hp_automute(codec);
1722 break;
1723 case CXT5051_PORTB_EVENT:
1724 cxt5051_portb_automic(codec);
1725 break;
1726 case CXT5051_PORTC_EVENT:
1727 cxt5051_portc_automic(codec);
1728 break;
1729 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001730 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001731}
1732
1733static struct snd_kcontrol_new cxt5051_mixers[] = {
1734 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1735 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1736 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1737 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1738 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1739 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1740 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1741 {
1742 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1743 .name = "Master Playback Switch",
1744 .info = cxt_eapd_info,
1745 .get = cxt_eapd_get,
1746 .put = cxt5051_hp_master_sw_put,
1747 .private_value = 0x1a,
1748 },
1749
1750 {}
1751};
1752
1753static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1754 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1755 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1756 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1757 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1758 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1759 {
1760 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1761 .name = "Master Playback Switch",
1762 .info = cxt_eapd_info,
1763 .get = cxt_eapd_get,
1764 .put = cxt5051_hp_master_sw_put,
1765 .private_value = 0x1a,
1766 },
1767
1768 {}
1769};
1770
1771static struct hda_verb cxt5051_init_verbs[] = {
1772 /* Line in, Mic */
1773 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1774 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1775 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1776 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1777 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1778 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1779 /* SPK */
1780 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1781 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1782 /* HP, Amp */
1783 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1784 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1785 /* DAC1 */
1786 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1787 /* Record selector: Int mic */
1788 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1789 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1790 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1791 /* SPDIF route: PCM */
1792 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1793 /* EAPD */
1794 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1795 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1796 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1797 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1798 { } /* end */
1799};
1800
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001801static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1802 /* Line in, Mic */
1803 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1804 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1805 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1806 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1807 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1808 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1809 /* SPK */
1810 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1811 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1812 /* HP, Amp */
1813 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1814 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1815 /* Docking HP */
1816 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1817 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1818 /* DAC1 */
1819 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1820 /* Record selector: Int mic */
1821 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1822 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1823 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1824 /* SPDIF route: PCM */
1825 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1826 /* EAPD */
1827 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1828 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1829 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1830 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1831 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1832 { } /* end */
1833};
1834
Takashi Iwai461e2c72008-01-25 11:35:17 +01001835/* initialize jack-sensing, too */
1836static int cxt5051_init(struct hda_codec *codec)
1837{
1838 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001839 conexant_init_jacks(codec);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001840 if (codec->patch_ops.unsol_event) {
1841 cxt5051_hp_automute(codec);
1842 cxt5051_portb_automic(codec);
1843 cxt5051_portc_automic(codec);
1844 }
1845 return 0;
1846}
1847
1848
1849enum {
1850 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1851 CXT5051_HP, /* no docking */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001852 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001853 CXT5051_MODELS
1854};
1855
1856static const char *cxt5051_models[CXT5051_MODELS] = {
1857 [CXT5051_LAPTOP] = "laptop",
1858 [CXT5051_HP] = "hp",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001859 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001860};
1861
1862static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1863 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1864 CXT5051_LAPTOP),
1865 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001866 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001867 {}
1868};
1869
1870static int patch_cxt5051(struct hda_codec *codec)
1871{
1872 struct conexant_spec *spec;
1873 int board_config;
1874
1875 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1876 if (!spec)
1877 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001878 codec->spec = spec;
1879
1880 codec->patch_ops = conexant_patch_ops;
1881 codec->patch_ops.init = cxt5051_init;
1882
1883 spec->multiout.max_channels = 2;
1884 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1885 spec->multiout.dac_nids = cxt5051_dac_nids;
1886 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1887 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1888 spec->adc_nids = cxt5051_adc_nids;
1889 spec->num_mixers = 1;
1890 spec->mixers[0] = cxt5051_mixers;
1891 spec->num_init_verbs = 1;
1892 spec->init_verbs[0] = cxt5051_init_verbs;
1893 spec->spdif_route = 0;
1894 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1895 spec->channel_mode = cxt5051_modes;
1896 spec->cur_adc = 0;
1897 spec->cur_adc_idx = 0;
1898
1899 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1900 cxt5051_models,
1901 cxt5051_cfg_tbl);
1902 switch (board_config) {
1903 case CXT5051_HP:
1904 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1905 spec->mixers[0] = cxt5051_hp_mixers;
1906 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001907 case CXT5051_LENOVO_X200:
1908 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
1909 /* fallthru */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001910 default:
1911 case CXT5051_LAPTOP:
1912 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1913 break;
1914 }
1915
1916 return 0;
1917}
1918
1919
1920/*
1921 */
1922
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001923static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001924 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1925 .patch = patch_cxt5045 },
1926 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1927 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01001928 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1929 .patch = patch_cxt5051 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001930 {} /* terminator */
1931};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001932
1933MODULE_ALIAS("snd-hda-codec-id:14f15045");
1934MODULE_ALIAS("snd-hda-codec-id:14f15047");
1935MODULE_ALIAS("snd-hda-codec-id:14f15051");
1936
1937MODULE_LICENSE("GPL");
1938MODULE_DESCRIPTION("Conexant HD-audio codec");
1939
1940static struct hda_codec_preset_list conexant_list = {
1941 .preset = snd_hda_preset_conexant,
1942 .owner = THIS_MODULE,
1943};
1944
1945static int __init patch_conexant_init(void)
1946{
1947 return snd_hda_add_codec_preset(&conexant_list);
1948}
1949
1950static void __exit patch_conexant_exit(void)
1951{
1952 snd_hda_delete_codec_preset(&conexant_list);
1953}
1954
1955module_init(patch_conexant_init)
1956module_exit(patch_conexant_exit)