blob: 75de40aaab0af5d5c558788468132bad574523f4 [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
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100350static int conexant_add_jack(struct hda_codec *codec,
351 hda_nid_t nid, int type)
352{
353 struct conexant_spec *spec;
354 struct conexant_jack *jack;
355 const char *name;
356
357 spec = codec->spec;
358 snd_array_init(&spec->jacks, sizeof(*jack), 32);
359 jack = snd_array_new(&spec->jacks);
360 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
361
362 if (!jack)
363 return -ENOMEM;
364
365 jack->nid = nid;
366 jack->type = type;
367
368 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
369}
370
371static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
372{
373 struct conexant_spec *spec = codec->spec;
374 struct conexant_jack *jacks = spec->jacks.list;
375
376 if (jacks) {
377 int i;
378 for (i = 0; i < spec->jacks.used; i++) {
379 if (jacks->nid == nid) {
380 unsigned int present;
381 present = snd_hda_codec_read(codec, nid, 0,
382 AC_VERB_GET_PIN_SENSE, 0) &
383 AC_PINSENSE_PRESENCE;
384
385 present = (present) ? jacks->type : 0 ;
386
387 snd_jack_report(jacks->jack,
388 present);
389 }
390 jacks++;
391 }
392 }
393}
394
395static int conexant_init_jacks(struct hda_codec *codec)
396{
397#ifdef CONFIG_SND_JACK
398 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 }
425#endif
426 return 0;
427
428}
429
Tobin Davisc9b443d2006-11-14 12:13:39 +0100430static int conexant_init(struct hda_codec *codec)
431{
432 struct conexant_spec *spec = codec->spec;
433 int i;
434
435 for (i = 0; i < spec->num_init_verbs; i++)
436 snd_hda_sequence_write(codec, spec->init_verbs[i]);
437 return 0;
438}
439
440static void conexant_free(struct hda_codec *codec)
441{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100442#ifdef CONFIG_SND_JACK
443 struct conexant_spec *spec = codec->spec;
444 if (spec->jacks.list) {
445 struct conexant_jack *jacks = spec->jacks.list;
446 int i;
447 for (i = 0; i < spec->jacks.used; i++)
448 snd_device_free(codec->bus->card, &jacks[i].jack);
449 snd_array_free(&spec->jacks);
450 }
451#endif
Tobin Davisc9b443d2006-11-14 12:13:39 +0100452 kfree(codec->spec);
453}
454
Tobin Davisc9b443d2006-11-14 12:13:39 +0100455static int conexant_build_controls(struct hda_codec *codec)
456{
457 struct conexant_spec *spec = codec->spec;
458 unsigned int i;
459 int err;
460
461 for (i = 0; i < spec->num_mixers; i++) {
462 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
463 if (err < 0)
464 return err;
465 }
466 if (spec->multiout.dig_out_nid) {
467 err = snd_hda_create_spdif_out_ctls(codec,
468 spec->multiout.dig_out_nid);
469 if (err < 0)
470 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100471 err = snd_hda_create_spdif_share_sw(codec,
472 &spec->multiout);
473 if (err < 0)
474 return err;
475 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100476 }
477 if (spec->dig_in_nid) {
478 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
479 if (err < 0)
480 return err;
481 }
482 return 0;
483}
484
485static struct hda_codec_ops conexant_patch_ops = {
486 .build_controls = conexant_build_controls,
487 .build_pcms = conexant_build_pcms,
488 .init = conexant_init,
489 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100490};
491
492/*
493 * EAPD control
494 * the private value = nid | (invert << 8)
495 */
496
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200497#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100498
Tobin Davis82f30042007-02-13 12:45:44 +0100499static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100500 struct snd_ctl_elem_value *ucontrol)
501{
502 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
503 struct conexant_spec *spec = codec->spec;
504 int invert = (kcontrol->private_value >> 8) & 1;
505 if (invert)
506 ucontrol->value.integer.value[0] = !spec->cur_eapd;
507 else
508 ucontrol->value.integer.value[0] = spec->cur_eapd;
509 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100510
Tobin Davisc9b443d2006-11-14 12:13:39 +0100511}
512
Tobin Davis82f30042007-02-13 12:45:44 +0100513static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100514 struct snd_ctl_elem_value *ucontrol)
515{
516 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
517 struct conexant_spec *spec = codec->spec;
518 int invert = (kcontrol->private_value >> 8) & 1;
519 hda_nid_t nid = kcontrol->private_value & 0xff;
520 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100521
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100522 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100523 if (invert)
524 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200525 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100526 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100527
Tobin Davisc9b443d2006-11-14 12:13:39 +0100528 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200529 snd_hda_codec_write_cache(codec, nid,
530 0, AC_VERB_SET_EAPD_BTLENABLE,
531 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100532 return 1;
533}
534
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100535/* controls for test mode */
536#ifdef CONFIG_SND_DEBUG
537
Tobin Davis82f30042007-02-13 12:45:44 +0100538#define CXT_EAPD_SWITCH(xname, nid, mask) \
539 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
540 .info = cxt_eapd_info, \
541 .get = cxt_eapd_get, \
542 .put = cxt_eapd_put, \
543 .private_value = nid | (mask<<16) }
544
545
546
Tobin Davisc9b443d2006-11-14 12:13:39 +0100547static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
548 struct snd_ctl_elem_info *uinfo)
549{
550 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
551 struct conexant_spec *spec = codec->spec;
552 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
553 spec->num_channel_mode);
554}
555
556static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
557 struct snd_ctl_elem_value *ucontrol)
558{
559 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
560 struct conexant_spec *spec = codec->spec;
561 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
562 spec->num_channel_mode,
563 spec->multiout.max_channels);
564}
565
566static int conexant_ch_mode_put(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 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
572 spec->num_channel_mode,
573 &spec->multiout.max_channels);
574 if (err >= 0 && spec->need_dac_fix)
575 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
576 return err;
577}
578
579#define CXT_PIN_MODE(xname, nid, dir) \
580 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
581 .info = conexant_ch_mode_info, \
582 .get = conexant_ch_mode_get, \
583 .put = conexant_ch_mode_put, \
584 .private_value = nid | (dir<<16) }
585
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100586#endif /* CONFIG_SND_DEBUG */
587
Tobin Davisc9b443d2006-11-14 12:13:39 +0100588/* Conexant 5045 specific */
589
590static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
591static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
592static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100593#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100594
Tobin Davis5cd57522006-11-20 17:42:09 +0100595static struct hda_channel_mode cxt5045_modes[1] = {
596 { 2, NULL },
597};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100598
599static struct hda_input_mux cxt5045_capture_source = {
600 .num_items = 2,
601 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100602 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100603 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100604 }
605};
606
Jiang Zhe5218c892008-01-17 11:18:41 +0100607static struct hda_input_mux cxt5045_capture_source_benq = {
608 .num_items = 3,
609 .items = {
610 { "IntMic", 0x1 },
611 { "ExtMic", 0x2 },
612 { "LineIn", 0x3 },
613 }
614};
615
Jiang zhe2de3c232008-03-06 11:09:09 +0100616static struct hda_input_mux cxt5045_capture_source_hp530 = {
617 .num_items = 2,
618 .items = {
619 { "ExtMic", 0x1 },
620 { "IntMic", 0x2 },
621 }
622};
623
Tobin Davisc9b443d2006-11-14 12:13:39 +0100624/* turn on/off EAPD (+ mute HP) as a master switch */
625static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
626 struct snd_ctl_elem_value *ucontrol)
627{
628 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
629 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100630 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100631
Tobin Davis82f30042007-02-13 12:45:44 +0100632 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100633 return 0;
634
Tobin Davis82f30042007-02-13 12:45:44 +0100635 /* toggle internal speakers mute depending of presence of
636 * the headphone jack
637 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200638 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
639 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
640 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100641
Takashi Iwai47fd8302007-08-10 17:11:07 +0200642 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
643 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
644 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100645 return 1;
646}
647
648/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200649static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
650 .ops = &snd_hda_bind_vol,
651 .values = {
652 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
653 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
654 0
655 },
656};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100657
Tobin Davis7f296732007-03-12 11:39:01 +0100658/* toggle input of built-in and mic jack appropriately */
659static void cxt5045_hp_automic(struct hda_codec *codec)
660{
661 static struct hda_verb mic_jack_on[] = {
662 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
663 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
664 {}
665 };
666 static struct hda_verb mic_jack_off[] = {
667 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
668 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
669 {}
670 };
671 unsigned int present;
672
673 present = snd_hda_codec_read(codec, 0x12, 0,
674 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
675 if (present)
676 snd_hda_sequence_write(codec, mic_jack_on);
677 else
678 snd_hda_sequence_write(codec, mic_jack_off);
679}
680
Tobin Davisc9b443d2006-11-14 12:13:39 +0100681
682/* mute internal speaker if HP is plugged */
683static void cxt5045_hp_automute(struct hda_codec *codec)
684{
Tobin Davis82f30042007-02-13 12:45:44 +0100685 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100686 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100687
Tobin Davis82f30042007-02-13 12:45:44 +0100688 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100689 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100690
Takashi Iwai47fd8302007-08-10 17:11:07 +0200691 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
692 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
693 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100694}
695
696/* unsolicited event for HP jack sensing */
697static void cxt5045_hp_unsol_event(struct hda_codec *codec,
698 unsigned int res)
699{
700 res >>= 26;
701 switch (res) {
702 case CONEXANT_HP_EVENT:
703 cxt5045_hp_automute(codec);
704 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100705 case CONEXANT_MIC_EVENT:
706 cxt5045_hp_automic(codec);
707 break;
708
Tobin Davisc9b443d2006-11-14 12:13:39 +0100709 }
710}
711
712static struct snd_kcontrol_new cxt5045_mixers[] = {
713 {
714 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
715 .name = "Capture Source",
716 .info = conexant_mux_enum_info,
717 .get = conexant_mux_enum_get,
718 .put = conexant_mux_enum_put
719 },
Takashi Iwaic8229c32007-10-19 08:06:21 +0200720 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
721 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
722 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
723 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
724 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
725 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
726 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
727 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
728 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
729 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200730 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100731 {
732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
733 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100734 .info = cxt_eapd_info,
735 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100736 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100737 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100738 },
739
740 {}
741};
742
Jiang Zhe5218c892008-01-17 11:18:41 +0100743static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
744 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
745 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
746 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
747 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
748
749 {}
750};
751
Jiang zhe2de3c232008-03-06 11:09:09 +0100752static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
753 {
754 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
755 .name = "Capture Source",
756 .info = conexant_mux_enum_info,
757 .get = conexant_mux_enum_get,
758 .put = conexant_mux_enum_put
759 },
760 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
761 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
762 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
763 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
764 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
765 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
766 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
767 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
768 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
769 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
770 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
771 {
772 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
773 .name = "Master Playback Switch",
774 .info = cxt_eapd_info,
775 .get = cxt_eapd_get,
776 .put = cxt5045_hp_master_sw_put,
777 .private_value = 0x10,
778 },
779
780 {}
781};
782
Tobin Davisc9b443d2006-11-14 12:13:39 +0100783static struct hda_verb cxt5045_init_verbs[] = {
784 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200785 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100786 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100787 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200788 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
789 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
790 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
791 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
792 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
793 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
794 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
795 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
796 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100797 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100798 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100799 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100800 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
801 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100802 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100803 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100804 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100805 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100806 { } /* end */
807};
808
Jiang Zhe5218c892008-01-17 11:18:41 +0100809static struct hda_verb cxt5045_benq_init_verbs[] = {
810 /* Int Mic, Mic */
811 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
812 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
813 /* Line In,HP, Amp */
814 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
815 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
816 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
817 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
818 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
819 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
820 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
821 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
822 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
823 /* Record selector: Int mic */
824 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
825 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
826 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
827 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100828 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100829 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
830 /* EAPD */
831 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
832 { } /* end */
833};
Tobin Davis7f296732007-03-12 11:39:01 +0100834
835static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
836 /* pin sensing on HP jack */
837 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200838 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100839};
840
841static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
842 /* pin sensing on HP jack */
843 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200844 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100845};
846
Tobin Davisc9b443d2006-11-14 12:13:39 +0100847#ifdef CONFIG_SND_DEBUG
848/* Test configuration for debugging, modelled after the ALC260 test
849 * configuration.
850 */
851static struct hda_input_mux cxt5045_test_capture_source = {
852 .num_items = 5,
853 .items = {
854 { "MIXER", 0x0 },
855 { "MIC1 pin", 0x1 },
856 { "LINE1 pin", 0x2 },
857 { "HP-OUT pin", 0x3 },
858 { "CD pin", 0x4 },
859 },
860};
861
862static struct snd_kcontrol_new cxt5045_test_mixer[] = {
863
864 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100865 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
866 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100867 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
868 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
869 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
870 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100871
872 /* Modes for retasking pin widgets */
873 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
874 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
875
Tobin Davis82f30042007-02-13 12:45:44 +0100876 /* EAPD Switch Control */
877 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
878
Tobin Davisc9b443d2006-11-14 12:13:39 +0100879 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100880
Tobin Davis7f296732007-03-12 11:39:01 +0100881 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
882 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
883 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
884 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
885 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
886 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
887 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
888 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
889 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
890 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100891 {
892 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
893 .name = "Input Source",
894 .info = conexant_mux_enum_info,
895 .get = conexant_mux_enum_get,
896 .put = conexant_mux_enum_put,
897 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200898 /* Audio input controls */
899 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
900 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
901 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
902 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
903 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
904 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
905 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
906 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
907 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
908 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100909 { } /* end */
910};
911
912static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100913 /* Set connections */
914 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
915 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
916 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100917 /* Enable retasking pins as output, initially without power amp */
918 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100919 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100920
921 /* Disable digital (SPDIF) pins initially, but users can enable
922 * them via a mixer switch. In the case of SPDIF-out, this initverb
923 * payload also sets the generation to 0, output to be in "consumer"
924 * PCM format, copyright asserted, no pre-emphasis and no validity
925 * control.
926 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100927 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
928 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100929
930 /* Start with output sum widgets muted and their output gains at min */
931 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
932 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
933
934 /* Unmute retasking pin widget output buffers since the default
935 * state appears to be output. As the pin mode is changed by the
936 * user the pin mode control will take care of enabling the pin's
937 * input/output buffers as needed.
938 */
939 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
940 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
941
942 /* Mute capture amp left and right */
943 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
944
945 /* Set ADC connection select to match default mixer setting (mic1
946 * pin)
947 */
948 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +0100949 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100950
951 /* Mute all inputs to mixer widget (even unconnected ones) */
952 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
953 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
954 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
955 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
956 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
957
958 { }
959};
960#endif
961
962
963/* initialize jack-sensing, too */
964static int cxt5045_init(struct hda_codec *codec)
965{
966 conexant_init(codec);
967 cxt5045_hp_automute(codec);
968 return 0;
969}
970
971
972enum {
Marc Boucher15908c32008-01-22 15:15:59 +0100973 CXT5045_LAPTOP_HPSENSE,
974 CXT5045_LAPTOP_MICSENSE,
975 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +0100976 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +0100977 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100978#ifdef CONFIG_SND_DEBUG
979 CXT5045_TEST,
980#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100981 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100982};
983
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100984static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +0100985 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
986 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
987 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
988 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +0100989 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100990#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100991 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100992#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100993};
994
995static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Marc Boucher15908c32008-01-22 15:15:59 +0100996 SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
997 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
998 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
999 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
1000 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
1001 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
Takashi Iwai0f6a5152008-01-29 13:26:04 +01001002 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
Jiang zhe2de3c232008-03-06 11:09:09 +01001003 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Marc Boucher15908c32008-01-22 15:15:59 +01001004 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001005 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001006 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001007 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1008 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001009 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1010 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001011 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1012 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1013 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1014 SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
1015 SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
1016 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001017 {}
1018};
1019
1020static int patch_cxt5045(struct hda_codec *codec)
1021{
1022 struct conexant_spec *spec;
1023 int board_config;
1024
1025 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1026 if (!spec)
1027 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001028 codec->spec = spec;
1029
1030 spec->multiout.max_channels = 2;
1031 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1032 spec->multiout.dac_nids = cxt5045_dac_nids;
1033 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1034 spec->num_adc_nids = 1;
1035 spec->adc_nids = cxt5045_adc_nids;
1036 spec->capsrc_nids = cxt5045_capsrc_nids;
1037 spec->input_mux = &cxt5045_capture_source;
1038 spec->num_mixers = 1;
1039 spec->mixers[0] = cxt5045_mixers;
1040 spec->num_init_verbs = 1;
1041 spec->init_verbs[0] = cxt5045_init_verbs;
1042 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001043 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1044 spec->channel_mode = cxt5045_modes,
1045
Tobin Davisc9b443d2006-11-14 12:13:39 +01001046
1047 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001048
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001049 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1050 cxt5045_models,
1051 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001052 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001053 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001054 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001055 spec->input_mux = &cxt5045_capture_source;
1056 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001057 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1058 spec->mixers[0] = cxt5045_mixers;
1059 codec->patch_ops.init = cxt5045_init;
1060 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001061 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001062 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001063 spec->input_mux = &cxt5045_capture_source;
1064 spec->num_init_verbs = 2;
1065 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001066 spec->mixers[0] = cxt5045_mixers;
1067 codec->patch_ops.init = cxt5045_init;
1068 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001069 default:
1070 case CXT5045_LAPTOP_HPMICSENSE:
1071 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1072 spec->input_mux = &cxt5045_capture_source;
1073 spec->num_init_verbs = 3;
1074 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1075 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1076 spec->mixers[0] = cxt5045_mixers;
1077 codec->patch_ops.init = cxt5045_init;
1078 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001079 case CXT5045_BENQ:
1080 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1081 spec->input_mux = &cxt5045_capture_source_benq;
1082 spec->num_init_verbs = 1;
1083 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1084 spec->mixers[0] = cxt5045_mixers;
1085 spec->mixers[1] = cxt5045_benq_mixers;
1086 spec->num_mixers = 2;
1087 codec->patch_ops.init = cxt5045_init;
1088 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001089 case CXT5045_LAPTOP_HP530:
1090 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1091 spec->input_mux = &cxt5045_capture_source_hp530;
1092 spec->num_init_verbs = 2;
1093 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1094 spec->mixers[0] = cxt5045_mixers_hp530;
1095 codec->patch_ops.init = cxt5045_init;
1096 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001097#ifdef CONFIG_SND_DEBUG
1098 case CXT5045_TEST:
1099 spec->input_mux = &cxt5045_test_capture_source;
1100 spec->mixers[0] = cxt5045_test_mixer;
1101 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001102 break;
1103
Tobin Davisc9b443d2006-11-14 12:13:39 +01001104#endif
1105 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001106
Takashi Iwai031005f2008-06-26 14:49:58 +02001107 switch (codec->subsystem_id >> 16) {
1108 case 0x103c:
1109 /* HP laptop has a really bad sound over 0dB on NID 0x17.
1110 * Fix max PCM level to 0 dB
1111 * (originall it has 0x2b steps with 0dB offset 0x14)
1112 */
1113 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1114 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1115 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1116 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1117 (1 << AC_AMPCAP_MUTE_SHIFT));
1118 break;
1119 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001120
Tobin Davisc9b443d2006-11-14 12:13:39 +01001121 return 0;
1122}
1123
1124
1125/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001126#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001127
Tobin Davis82f30042007-02-13 12:45:44 +01001128static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001129static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1130static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001131
Tobin Davis5cd57522006-11-20 17:42:09 +01001132static struct hda_channel_mode cxt5047_modes[1] = {
1133 { 2, NULL },
1134};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001135
1136static struct hda_input_mux cxt5047_capture_source = {
Tobin Davis7f296732007-03-12 11:39:01 +01001137 .num_items = 1,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001138 .items = {
Tobin Davis7f296732007-03-12 11:39:01 +01001139 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001140 }
1141};
1142
1143static struct hda_input_mux cxt5047_hp_capture_source = {
1144 .num_items = 1,
1145 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001146 { "ExtMic", 0x2 },
1147 }
1148};
1149
1150static struct hda_input_mux cxt5047_toshiba_capture_source = {
1151 .num_items = 2,
1152 .items = {
1153 { "ExtMic", 0x2 },
1154 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001155 }
1156};
1157
1158/* turn on/off EAPD (+ mute HP) as a master switch */
1159static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1160 struct snd_ctl_elem_value *ucontrol)
1161{
1162 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1163 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001164 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001165
Tobin Davis82f30042007-02-13 12:45:44 +01001166 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001167 return 0;
1168
Tobin Davis82f30042007-02-13 12:45:44 +01001169 /* toggle internal speakers mute depending of presence of
1170 * the headphone jack
1171 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001172 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1173 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1174 HDA_AMP_MUTE, bits);
1175 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1176 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1177 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001178 return 1;
1179}
1180
Tobin Davis82f30042007-02-13 12:45:44 +01001181/* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001182static struct hda_bind_ctls cxt5047_bind_master_vol = {
1183 .ops = &snd_hda_bind_vol,
1184 .values = {
1185 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1186 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1187 0
1188 },
1189};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001190
1191/* mute internal speaker if HP is plugged */
1192static void cxt5047_hp_automute(struct hda_codec *codec)
1193{
Tobin Davis82f30042007-02-13 12:45:44 +01001194 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001195 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001196
Tobin Davis82f30042007-02-13 12:45:44 +01001197 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001198 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +01001199
Takashi Iwai47fd8302007-08-10 17:11:07 +02001200 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1201 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1202 HDA_AMP_MUTE, bits);
Tobin Davis82f30042007-02-13 12:45:44 +01001203 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001204 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1205 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001206}
1207
Tobin Davisfb3409e2007-05-17 09:40:47 +02001208/* mute internal speaker if HP is plugged */
1209static void cxt5047_hp2_automute(struct hda_codec *codec)
1210{
1211 struct conexant_spec *spec = codec->spec;
1212 unsigned int bits;
1213
1214 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1215 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1216
Takashi Iwai47fd8302007-08-10 17:11:07 +02001217 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1218 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1219 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001220 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001221 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1222 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001223}
1224
Tobin Davisc9b443d2006-11-14 12:13:39 +01001225/* toggle input of built-in and mic jack appropriately */
1226static void cxt5047_hp_automic(struct hda_codec *codec)
1227{
1228 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001229 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1230 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001231 {}
1232 };
1233 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001234 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1235 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001236 {}
1237 };
1238 unsigned int present;
1239
Tobin Davis7f296732007-03-12 11:39:01 +01001240 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001241 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1242 if (present)
1243 snd_hda_sequence_write(codec, mic_jack_on);
1244 else
1245 snd_hda_sequence_write(codec, mic_jack_off);
1246}
1247
1248/* unsolicited event for HP jack sensing */
1249static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1250 unsigned int res)
1251{
Marc Boucher9f113e02008-01-22 15:18:08 +01001252 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001253 case CONEXANT_HP_EVENT:
1254 cxt5047_hp_automute(codec);
1255 break;
1256 case CONEXANT_MIC_EVENT:
1257 cxt5047_hp_automic(codec);
1258 break;
1259 }
1260}
1261
Tobin Davisfb3409e2007-05-17 09:40:47 +02001262/* unsolicited event for HP jack sensing - non-EAPD systems */
1263static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1264 unsigned int res)
1265{
1266 res >>= 26;
1267 switch (res) {
1268 case CONEXANT_HP_EVENT:
1269 cxt5047_hp2_automute(codec);
1270 break;
1271 case CONEXANT_MIC_EVENT:
1272 cxt5047_hp_automic(codec);
1273 break;
1274 }
1275}
1276
Tobin Davisc9b443d2006-11-14 12:13:39 +01001277static struct snd_kcontrol_new cxt5047_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001278 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1279 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001280 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1281 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001282 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1283 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1284 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1285 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001286 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1287 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
Tobin Davisb7589ce2007-04-24 17:56:55 +02001288 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1289 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1290 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1291 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001292
1293 {}
1294};
1295
1296static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1297 {
1298 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1299 .name = "Capture Source",
1300 .info = conexant_mux_enum_info,
1301 .get = conexant_mux_enum_get,
1302 .put = conexant_mux_enum_put
1303 },
1304 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1305 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1306 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1307 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1308 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1309 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +02001310 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
Tobin Davis82f30042007-02-13 12:45:44 +01001311 {
1312 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1313 .name = "Master Playback Switch",
1314 .info = cxt_eapd_info,
1315 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001316 .put = cxt5047_hp_master_sw_put,
1317 .private_value = 0x13,
1318 },
1319
1320 {}
1321};
1322
1323static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1324 {
1325 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1326 .name = "Capture Source",
1327 .info = conexant_mux_enum_info,
1328 .get = conexant_mux_enum_get,
1329 .put = conexant_mux_enum_put
1330 },
1331 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1332 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1333 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1334 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1335 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1336 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1337 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1338 {
1339 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1340 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001341 .info = cxt_eapd_info,
1342 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001343 .put = cxt5047_hp_master_sw_put,
1344 .private_value = 0x13,
1345 },
1346 { } /* end */
1347};
1348
1349static struct hda_verb cxt5047_init_verbs[] = {
1350 /* Line in, Mic, Built-in Mic */
1351 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1352 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1353 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001354 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001355 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1356 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis7f296732007-03-12 11:39:01 +01001357 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1358 /* Record selector: Mic */
1359 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1360 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1361 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1362 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001363 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1364 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1365 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1366 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001367 /* SPDIF route: PCM */
1368 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001369 /* Enable unsolicited events */
1370 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1371 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001372 { } /* end */
1373};
1374
1375/* configuration for Toshiba Laptops */
1376static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1377 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1378 /* pin sensing on HP and Mic jacks */
1379 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1380 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001381 /* Speaker routing */
1382 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001383 {}
1384};
1385
1386/* configuration for HP Laptops */
1387static struct hda_verb cxt5047_hp_init_verbs[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001388 /* pin sensing on HP jack */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001389 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaib84f08d2008-02-18 12:36:11 +01001390 /* 0x13 is actually shared by both HP and speaker;
1391 * setting the connection to 0 (=0x19) makes the master volume control
1392 * working mysteriouslly...
1393 */
1394 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
Tobin Davis82f30042007-02-13 12:45:44 +01001395 /* Record selector: Ext Mic */
1396 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
Tobin Davis82f30042007-02-13 12:45:44 +01001397 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1398 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1399 /* Speaker routing */
1400 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001401 {}
1402};
1403
1404/* Test configuration for debugging, modelled after the ALC260 test
1405 * configuration.
1406 */
1407#ifdef CONFIG_SND_DEBUG
1408static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001409 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001410 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001411 { "LINE1 pin", 0x0 },
1412 { "MIC1 pin", 0x1 },
1413 { "MIC2 pin", 0x2 },
1414 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001415 },
1416};
1417
1418static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1419
1420 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001421 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1422 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1423 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1424 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001425 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1426 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1427 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1428 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001429 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1430 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1431 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1432 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001433
1434 /* Modes for retasking pin widgets */
1435 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1436 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1437
Tobin Davis82f30042007-02-13 12:45:44 +01001438 /* EAPD Switch Control */
1439 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1440
Tobin Davisc9b443d2006-11-14 12:13:39 +01001441 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001442 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1443 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1444 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1445 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1446 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1447 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1448 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1449 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001450
Tobin Davis82f30042007-02-13 12:45:44 +01001451 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1452 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1453 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1454 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1455 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1456 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1457 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1458 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001459 {
1460 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1461 .name = "Input Source",
1462 .info = conexant_mux_enum_info,
1463 .get = conexant_mux_enum_get,
1464 .put = conexant_mux_enum_put,
1465 },
Marc Boucher9f113e02008-01-22 15:18:08 +01001466 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1467 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1468 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1469 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1470 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1471 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1472 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1473 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1474 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1475 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1476
Tobin Davisc9b443d2006-11-14 12:13:39 +01001477 { } /* end */
1478};
1479
1480static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001481 /* Enable retasking pins as output, initially without power amp */
1482 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1483 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1484 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1485
1486 /* Disable digital (SPDIF) pins initially, but users can enable
1487 * them via a mixer switch. In the case of SPDIF-out, this initverb
1488 * payload also sets the generation to 0, output to be in "consumer"
1489 * PCM format, copyright asserted, no pre-emphasis and no validity
1490 * control.
1491 */
1492 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1493
1494 /* Ensure mic1, mic2, line1 pin widgets take input from the
1495 * OUT1 sum bus when acting as an output.
1496 */
1497 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1498 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1499
1500 /* Start with output sum widgets muted and their output gains at min */
1501 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1502 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1503
1504 /* Unmute retasking pin widget output buffers since the default
1505 * state appears to be output. As the pin mode is changed by the
1506 * user the pin mode control will take care of enabling the pin's
1507 * input/output buffers as needed.
1508 */
1509 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1510 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1511 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1512
1513 /* Mute capture amp left and right */
1514 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1515
1516 /* Set ADC connection select to match default mixer setting (mic1
1517 * pin)
1518 */
1519 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1520
1521 /* Mute all inputs to mixer widget (even unconnected ones) */
1522 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1523 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1524 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1525 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1526 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1527 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1530
1531 { }
1532};
1533#endif
1534
1535
1536/* initialize jack-sensing, too */
1537static int cxt5047_hp_init(struct hda_codec *codec)
1538{
1539 conexant_init(codec);
1540 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001541 return 0;
1542}
1543
1544
1545enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001546 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1547 CXT5047_LAPTOP_HP, /* Some HP laptops */
1548 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001549#ifdef CONFIG_SND_DEBUG
1550 CXT5047_TEST,
1551#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001552 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001553};
1554
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001555static const char *cxt5047_models[CXT5047_MODELS] = {
1556 [CXT5047_LAPTOP] = "laptop",
1557 [CXT5047_LAPTOP_HP] = "laptop-hp",
1558 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001559#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001560 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001561#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001562};
1563
1564static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1565 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001566 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001567 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
Tobin Davis82f30042007-02-13 12:45:44 +01001568 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001569 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001570 {}
1571};
1572
1573static int patch_cxt5047(struct hda_codec *codec)
1574{
1575 struct conexant_spec *spec;
1576 int board_config;
1577
1578 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1579 if (!spec)
1580 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001581 codec->spec = spec;
1582
1583 spec->multiout.max_channels = 2;
1584 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1585 spec->multiout.dac_nids = cxt5047_dac_nids;
1586 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1587 spec->num_adc_nids = 1;
1588 spec->adc_nids = cxt5047_adc_nids;
1589 spec->capsrc_nids = cxt5047_capsrc_nids;
1590 spec->input_mux = &cxt5047_capture_source;
1591 spec->num_mixers = 1;
1592 spec->mixers[0] = cxt5047_mixers;
1593 spec->num_init_verbs = 1;
1594 spec->init_verbs[0] = cxt5047_init_verbs;
1595 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001596 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1597 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001598
1599 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001600
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001601 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1602 cxt5047_models,
1603 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001604 switch (board_config) {
1605 case CXT5047_LAPTOP:
Tobin Davisfb3409e2007-05-17 09:40:47 +02001606 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001607 break;
1608 case CXT5047_LAPTOP_HP:
1609 spec->input_mux = &cxt5047_hp_capture_source;
1610 spec->num_init_verbs = 2;
1611 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1612 spec->mixers[0] = cxt5047_hp_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001613 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001614 codec->patch_ops.init = cxt5047_hp_init;
1615 break;
1616 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001617 spec->input_mux = &cxt5047_toshiba_capture_source;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001618 spec->num_init_verbs = 2;
1619 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davis82f30042007-02-13 12:45:44 +01001620 spec->mixers[0] = cxt5047_toshiba_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001621 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001622 break;
1623#ifdef CONFIG_SND_DEBUG
1624 case CXT5047_TEST:
1625 spec->input_mux = &cxt5047_test_capture_source;
1626 spec->mixers[0] = cxt5047_test_mixer;
1627 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001628 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001629#endif
1630 }
1631 return 0;
1632}
1633
Takashi Iwai461e2c72008-01-25 11:35:17 +01001634/* Conexant 5051 specific */
1635static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1636static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001637
1638static struct hda_channel_mode cxt5051_modes[1] = {
1639 { 2, NULL },
1640};
1641
1642static void cxt5051_update_speaker(struct hda_codec *codec)
1643{
1644 struct conexant_spec *spec = codec->spec;
1645 unsigned int pinctl;
1646 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1647 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1648 pinctl);
1649}
1650
1651/* turn on/off EAPD (+ mute HP) as a master switch */
1652static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1653 struct snd_ctl_elem_value *ucontrol)
1654{
1655 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1656
1657 if (!cxt_eapd_put(kcontrol, ucontrol))
1658 return 0;
1659 cxt5051_update_speaker(codec);
1660 return 1;
1661}
1662
1663/* toggle input of built-in and mic jack appropriately */
1664static void cxt5051_portb_automic(struct hda_codec *codec)
1665{
1666 unsigned int present;
1667
1668 present = snd_hda_codec_read(codec, 0x17, 0,
1669 AC_VERB_GET_PIN_SENSE, 0) &
1670 AC_PINSENSE_PRESENCE;
1671 snd_hda_codec_write(codec, 0x14, 0,
1672 AC_VERB_SET_CONNECT_SEL,
1673 present ? 0x01 : 0x00);
1674}
1675
1676/* switch the current ADC according to the jack state */
1677static void cxt5051_portc_automic(struct hda_codec *codec)
1678{
1679 struct conexant_spec *spec = codec->spec;
1680 unsigned int present;
1681 hda_nid_t new_adc;
1682
1683 present = snd_hda_codec_read(codec, 0x18, 0,
1684 AC_VERB_GET_PIN_SENSE, 0) &
1685 AC_PINSENSE_PRESENCE;
1686 if (present)
1687 spec->cur_adc_idx = 1;
1688 else
1689 spec->cur_adc_idx = 0;
1690 new_adc = spec->adc_nids[spec->cur_adc_idx];
1691 if (spec->cur_adc && spec->cur_adc != new_adc) {
1692 /* stream is running, let's swap the current ADC */
Takashi Iwai888afa12008-03-18 09:57:50 +01001693 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001694 spec->cur_adc = new_adc;
1695 snd_hda_codec_setup_stream(codec, new_adc,
1696 spec->cur_adc_stream_tag, 0,
1697 spec->cur_adc_format);
1698 }
1699}
1700
1701/* mute internal speaker if HP is plugged */
1702static void cxt5051_hp_automute(struct hda_codec *codec)
1703{
1704 struct conexant_spec *spec = codec->spec;
1705
1706 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1707 AC_VERB_GET_PIN_SENSE, 0) &
1708 AC_PINSENSE_PRESENCE;
1709 cxt5051_update_speaker(codec);
1710}
1711
1712/* unsolicited event for HP jack sensing */
1713static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1714 unsigned int res)
1715{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001716 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001717 switch (res >> 26) {
1718 case CONEXANT_HP_EVENT:
1719 cxt5051_hp_automute(codec);
1720 break;
1721 case CXT5051_PORTB_EVENT:
1722 cxt5051_portb_automic(codec);
1723 break;
1724 case CXT5051_PORTC_EVENT:
1725 cxt5051_portc_automic(codec);
1726 break;
1727 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001728 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001729}
1730
1731static struct snd_kcontrol_new cxt5051_mixers[] = {
1732 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1733 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1734 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1735 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1736 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1737 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1738 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1739 {
1740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1741 .name = "Master Playback Switch",
1742 .info = cxt_eapd_info,
1743 .get = cxt_eapd_get,
1744 .put = cxt5051_hp_master_sw_put,
1745 .private_value = 0x1a,
1746 },
1747
1748 {}
1749};
1750
1751static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1752 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1753 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1754 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1755 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1756 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1757 {
1758 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1759 .name = "Master Playback Switch",
1760 .info = cxt_eapd_info,
1761 .get = cxt_eapd_get,
1762 .put = cxt5051_hp_master_sw_put,
1763 .private_value = 0x1a,
1764 },
1765
1766 {}
1767};
1768
1769static struct hda_verb cxt5051_init_verbs[] = {
1770 /* Line in, Mic */
1771 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1772 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1773 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1774 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1775 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1776 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1777 /* SPK */
1778 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1779 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1780 /* HP, Amp */
1781 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1782 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1783 /* DAC1 */
1784 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1785 /* Record selector: Int mic */
1786 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1787 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1788 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1789 /* SPDIF route: PCM */
1790 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1791 /* EAPD */
1792 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1793 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1794 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1795 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1796 { } /* end */
1797};
1798
1799/* initialize jack-sensing, too */
1800static int cxt5051_init(struct hda_codec *codec)
1801{
1802 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001803 conexant_init_jacks(codec);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001804 if (codec->patch_ops.unsol_event) {
1805 cxt5051_hp_automute(codec);
1806 cxt5051_portb_automic(codec);
1807 cxt5051_portc_automic(codec);
1808 }
1809 return 0;
1810}
1811
1812
1813enum {
1814 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1815 CXT5051_HP, /* no docking */
1816 CXT5051_MODELS
1817};
1818
1819static const char *cxt5051_models[CXT5051_MODELS] = {
1820 [CXT5051_LAPTOP] = "laptop",
1821 [CXT5051_HP] = "hp",
1822};
1823
1824static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1825 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1826 CXT5051_LAPTOP),
1827 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1828 {}
1829};
1830
1831static int patch_cxt5051(struct hda_codec *codec)
1832{
1833 struct conexant_spec *spec;
1834 int board_config;
1835
1836 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1837 if (!spec)
1838 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001839 codec->spec = spec;
1840
1841 codec->patch_ops = conexant_patch_ops;
1842 codec->patch_ops.init = cxt5051_init;
1843
1844 spec->multiout.max_channels = 2;
1845 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1846 spec->multiout.dac_nids = cxt5051_dac_nids;
1847 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1848 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1849 spec->adc_nids = cxt5051_adc_nids;
1850 spec->num_mixers = 1;
1851 spec->mixers[0] = cxt5051_mixers;
1852 spec->num_init_verbs = 1;
1853 spec->init_verbs[0] = cxt5051_init_verbs;
1854 spec->spdif_route = 0;
1855 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1856 spec->channel_mode = cxt5051_modes;
1857 spec->cur_adc = 0;
1858 spec->cur_adc_idx = 0;
1859
1860 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1861 cxt5051_models,
1862 cxt5051_cfg_tbl);
1863 switch (board_config) {
1864 case CXT5051_HP:
1865 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1866 spec->mixers[0] = cxt5051_hp_mixers;
1867 break;
1868 default:
1869 case CXT5051_LAPTOP:
1870 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1871 break;
1872 }
1873
1874 return 0;
1875}
1876
1877
1878/*
1879 */
1880
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001881static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001882 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1883 .patch = patch_cxt5045 },
1884 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1885 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01001886 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1887 .patch = patch_cxt5051 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001888 {} /* terminator */
1889};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001890
1891MODULE_ALIAS("snd-hda-codec-id:14f15045");
1892MODULE_ALIAS("snd-hda-codec-id:14f15047");
1893MODULE_ALIAS("snd-hda-codec-id:14f15051");
1894
1895MODULE_LICENSE("GPL");
1896MODULE_DESCRIPTION("Conexant HD-audio codec");
1897
1898static struct hda_codec_preset_list conexant_list = {
1899 .preset = snd_hda_preset_conexant,
1900 .owner = THIS_MODULE,
1901};
1902
1903static int __init patch_conexant_init(void)
1904{
1905 return snd_hda_add_codec_preset(&conexant_list);
1906}
1907
1908static void __exit patch_conexant_exit(void)
1909{
1910 snd_hda_delete_codec_preset(&conexant_list);
1911}
1912
1913module_init(patch_conexant_init)
1914module_exit(patch_conexant_exit)