blob: 26034315197fc1b2bf15caf174e3b5daa916b6d3 [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
23#include <sound/driver.h>
24#include <linux/init.h>
25#include <linux/delay.h>
26#include <linux/slab.h>
27#include <linux/pci.h>
28#include <sound/core.h>
29#include "hda_codec.h"
30#include "hda_local.h"
31
32#define CXT_PIN_DIR_IN 0x00
33#define CXT_PIN_DIR_OUT 0x01
34#define CXT_PIN_DIR_INOUT 0x02
35#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
36#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
37
38#define CONEXANT_HP_EVENT 0x37
39#define CONEXANT_MIC_EVENT 0x38
40
41
42
43struct conexant_spec {
44
45 struct snd_kcontrol_new *mixers[5];
46 int num_mixers;
47
48 const struct hda_verb *init_verbs[5]; /* initialization verbs
49 * don't forget NULL
50 * termination!
51 */
52 unsigned int num_init_verbs;
53
54 /* playback */
55 struct hda_multi_out multiout; /* playback set-up
56 * max_channels, dacs must be set
57 * dig_out_nid and hp_nid are optional
58 */
59 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010060 unsigned int hp_present;
Tobin Davisc9b443d2006-11-14 12:13:39 +010061 unsigned int need_dac_fix;
62
63 /* capture */
64 unsigned int num_adc_nids;
65 hda_nid_t *adc_nids;
66 hda_nid_t dig_in_nid; /* digital-in NID; optional */
67
68 /* capture source */
69 const struct hda_input_mux *input_mux;
70 hda_nid_t *capsrc_nids;
71 unsigned int cur_mux[3];
72
73 /* channel model */
74 const struct hda_channel_mode *channel_mode;
75 int num_channel_mode;
76
77 /* PCM information */
78 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
79
80 struct mutex amp_mutex; /* PCM volume/mute control mutex */
81 unsigned int spdif_route;
82
83 /* dynamic controls, init_verbs and input_mux */
84 struct auto_pin_cfg autocfg;
85 unsigned int num_kctl_alloc, num_kctl_used;
86 struct snd_kcontrol_new *kctl_alloc;
87 struct hda_input_mux private_imux;
88 hda_nid_t private_dac_nids[4];
89
90};
91
92static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
93 struct hda_codec *codec,
94 struct snd_pcm_substream *substream)
95{
96 struct conexant_spec *spec = codec->spec;
97 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
98}
99
100static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
101 struct hda_codec *codec,
102 unsigned int stream_tag,
103 unsigned int format,
104 struct snd_pcm_substream *substream)
105{
106 struct conexant_spec *spec = codec->spec;
107 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
108 stream_tag,
109 format, substream);
110}
111
112static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
113 struct hda_codec *codec,
114 struct snd_pcm_substream *substream)
115{
116 struct conexant_spec *spec = codec->spec;
117 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
118}
119
120/*
121 * Digital out
122 */
123static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
124 struct hda_codec *codec,
125 struct snd_pcm_substream *substream)
126{
127 struct conexant_spec *spec = codec->spec;
128 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
129}
130
131static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
132 struct hda_codec *codec,
133 struct snd_pcm_substream *substream)
134{
135 struct conexant_spec *spec = codec->spec;
136 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
137}
138
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200139static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
140 struct hda_codec *codec,
141 unsigned int stream_tag,
142 unsigned int format,
143 struct snd_pcm_substream *substream)
144{
145 struct conexant_spec *spec = codec->spec;
146 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
147 stream_tag,
148 format, substream);
149}
150
Tobin Davisc9b443d2006-11-14 12:13:39 +0100151/*
152 * Analog capture
153 */
154static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
155 struct hda_codec *codec,
156 unsigned int stream_tag,
157 unsigned int format,
158 struct snd_pcm_substream *substream)
159{
160 struct conexant_spec *spec = codec->spec;
161 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
162 stream_tag, 0, format);
163 return 0;
164}
165
166static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
167 struct hda_codec *codec,
168 struct snd_pcm_substream *substream)
169{
170 struct conexant_spec *spec = codec->spec;
171 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
172 0, 0, 0);
173 return 0;
174}
175
176
177
178static struct hda_pcm_stream conexant_pcm_analog_playback = {
179 .substreams = 1,
180 .channels_min = 2,
181 .channels_max = 2,
182 .nid = 0, /* fill later */
183 .ops = {
184 .open = conexant_playback_pcm_open,
185 .prepare = conexant_playback_pcm_prepare,
186 .cleanup = conexant_playback_pcm_cleanup
187 },
188};
189
190static struct hda_pcm_stream conexant_pcm_analog_capture = {
191 .substreams = 1,
192 .channels_min = 2,
193 .channels_max = 2,
194 .nid = 0, /* fill later */
195 .ops = {
196 .prepare = conexant_capture_pcm_prepare,
197 .cleanup = conexant_capture_pcm_cleanup
198 },
199};
200
201
202static struct hda_pcm_stream conexant_pcm_digital_playback = {
203 .substreams = 1,
204 .channels_min = 2,
205 .channels_max = 2,
206 .nid = 0, /* fill later */
207 .ops = {
208 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200209 .close = conexant_dig_playback_pcm_close,
210 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100211 },
212};
213
214static struct hda_pcm_stream conexant_pcm_digital_capture = {
215 .substreams = 1,
216 .channels_min = 2,
217 .channels_max = 2,
218 /* NID is set in alc_build_pcms */
219};
220
221static int conexant_build_pcms(struct hda_codec *codec)
222{
223 struct conexant_spec *spec = codec->spec;
224 struct hda_pcm *info = spec->pcm_rec;
225
226 codec->num_pcms = 1;
227 codec->pcm_info = info;
228
229 info->name = "CONEXANT Analog";
230 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
231 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
232 spec->multiout.max_channels;
233 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
234 spec->multiout.dac_nids[0];
235 info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_analog_capture;
236 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
237 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
238
239 if (spec->multiout.dig_out_nid) {
240 info++;
241 codec->num_pcms++;
242 info->name = "Conexant Digital";
243 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
244 conexant_pcm_digital_playback;
245 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
246 spec->multiout.dig_out_nid;
247 if (spec->dig_in_nid) {
248 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
249 conexant_pcm_digital_capture;
250 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
251 spec->dig_in_nid;
252 }
253 }
254
255 return 0;
256}
257
258static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
259 struct snd_ctl_elem_info *uinfo)
260{
261 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
262 struct conexant_spec *spec = codec->spec;
263
264 return snd_hda_input_mux_info(spec->input_mux, uinfo);
265}
266
267static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
268 struct snd_ctl_elem_value *ucontrol)
269{
270 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
271 struct conexant_spec *spec = codec->spec;
272 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
273
274 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
275 return 0;
276}
277
278static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
279 struct snd_ctl_elem_value *ucontrol)
280{
281 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
282 struct conexant_spec *spec = codec->spec;
283 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
284
285 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
286 spec->capsrc_nids[adc_idx],
287 &spec->cur_mux[adc_idx]);
288}
289
290static int conexant_init(struct hda_codec *codec)
291{
292 struct conexant_spec *spec = codec->spec;
293 int i;
294
295 for (i = 0; i < spec->num_init_verbs; i++)
296 snd_hda_sequence_write(codec, spec->init_verbs[i]);
297 return 0;
298}
299
300static void conexant_free(struct hda_codec *codec)
301{
302 struct conexant_spec *spec = codec->spec;
303 unsigned int i;
304
305 if (spec->kctl_alloc) {
306 for (i = 0; i < spec->num_kctl_used; i++)
307 kfree(spec->kctl_alloc[i].name);
308 kfree(spec->kctl_alloc);
309 }
310
311 kfree(codec->spec);
312}
313
314#ifdef CONFIG_PM
315static int conexant_resume(struct hda_codec *codec)
316{
317 struct conexant_spec *spec = codec->spec;
318 int i;
319
320 codec->patch_ops.init(codec);
321 for (i = 0; i < spec->num_mixers; i++)
322 snd_hda_resume_ctls(codec, spec->mixers[i]);
323 if (spec->multiout.dig_out_nid)
324 snd_hda_resume_spdif_out(codec);
325 if (spec->dig_in_nid)
326 snd_hda_resume_spdif_in(codec);
327 return 0;
328}
329#endif
330
331static int conexant_build_controls(struct hda_codec *codec)
332{
333 struct conexant_spec *spec = codec->spec;
334 unsigned int i;
335 int err;
336
337 for (i = 0; i < spec->num_mixers; i++) {
338 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
339 if (err < 0)
340 return err;
341 }
342 if (spec->multiout.dig_out_nid) {
343 err = snd_hda_create_spdif_out_ctls(codec,
344 spec->multiout.dig_out_nid);
345 if (err < 0)
346 return err;
347 }
348 if (spec->dig_in_nid) {
349 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
350 if (err < 0)
351 return err;
352 }
353 return 0;
354}
355
356static struct hda_codec_ops conexant_patch_ops = {
357 .build_controls = conexant_build_controls,
358 .build_pcms = conexant_build_pcms,
359 .init = conexant_init,
360 .free = conexant_free,
361#ifdef CONFIG_PM
362 .resume = conexant_resume,
363#endif
364};
365
366/*
367 * EAPD control
368 * the private value = nid | (invert << 8)
369 */
370
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200371#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100372
Tobin Davis82f30042007-02-13 12:45:44 +0100373static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100374 struct snd_ctl_elem_value *ucontrol)
375{
376 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
377 struct conexant_spec *spec = codec->spec;
378 int invert = (kcontrol->private_value >> 8) & 1;
379 if (invert)
380 ucontrol->value.integer.value[0] = !spec->cur_eapd;
381 else
382 ucontrol->value.integer.value[0] = spec->cur_eapd;
383 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100384
Tobin Davisc9b443d2006-11-14 12:13:39 +0100385}
386
Tobin Davis82f30042007-02-13 12:45:44 +0100387static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100388 struct snd_ctl_elem_value *ucontrol)
389{
390 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
391 struct conexant_spec *spec = codec->spec;
392 int invert = (kcontrol->private_value >> 8) & 1;
393 hda_nid_t nid = kcontrol->private_value & 0xff;
394 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100395
Tobin Davisc9b443d2006-11-14 12:13:39 +0100396 eapd = ucontrol->value.integer.value[0];
397 if (invert)
398 eapd = !eapd;
399 if (eapd == spec->cur_eapd && !codec->in_resume)
400 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100401
Tobin Davisc9b443d2006-11-14 12:13:39 +0100402 spec->cur_eapd = eapd;
403 snd_hda_codec_write(codec, nid,
404 0, AC_VERB_SET_EAPD_BTLENABLE,
405 eapd ? 0x02 : 0x00);
406 return 1;
407}
408
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100409/* controls for test mode */
410#ifdef CONFIG_SND_DEBUG
411
Tobin Davis82f30042007-02-13 12:45:44 +0100412#define CXT_EAPD_SWITCH(xname, nid, mask) \
413 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
414 .info = cxt_eapd_info, \
415 .get = cxt_eapd_get, \
416 .put = cxt_eapd_put, \
417 .private_value = nid | (mask<<16) }
418
419
420
Tobin Davisc9b443d2006-11-14 12:13:39 +0100421static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
422 struct snd_ctl_elem_info *uinfo)
423{
424 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
425 struct conexant_spec *spec = codec->spec;
426 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
427 spec->num_channel_mode);
428}
429
430static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
431 struct snd_ctl_elem_value *ucontrol)
432{
433 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
434 struct conexant_spec *spec = codec->spec;
435 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
436 spec->num_channel_mode,
437 spec->multiout.max_channels);
438}
439
440static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
441 struct snd_ctl_elem_value *ucontrol)
442{
443 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
444 struct conexant_spec *spec = codec->spec;
445 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
446 spec->num_channel_mode,
447 &spec->multiout.max_channels);
448 if (err >= 0 && spec->need_dac_fix)
449 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
450 return err;
451}
452
453#define CXT_PIN_MODE(xname, nid, dir) \
454 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
455 .info = conexant_ch_mode_info, \
456 .get = conexant_ch_mode_get, \
457 .put = conexant_ch_mode_put, \
458 .private_value = nid | (dir<<16) }
459
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100460#endif /* CONFIG_SND_DEBUG */
461
Tobin Davisc9b443d2006-11-14 12:13:39 +0100462/* Conexant 5045 specific */
463
464static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
465static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
466static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
467#define CXT5045_SPDIF_OUT 0x13
468
Tobin Davis5cd57522006-11-20 17:42:09 +0100469static struct hda_channel_mode cxt5045_modes[1] = {
470 { 2, NULL },
471};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100472
473static struct hda_input_mux cxt5045_capture_source = {
474 .num_items = 2,
475 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100476 { "IntMic", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100477 { "LineIn", 0x2 },
478 }
479};
480
481/* turn on/off EAPD (+ mute HP) as a master switch */
482static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
483 struct snd_ctl_elem_value *ucontrol)
484{
485 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
486 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100487 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100488
Tobin Davis82f30042007-02-13 12:45:44 +0100489 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100490 return 0;
491
Tobin Davis82f30042007-02-13 12:45:44 +0100492 /* toggle internal speakers mute depending of presence of
493 * the headphone jack
494 */
495 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : 0x80;
496 snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0, 0x80, bits);
497 snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0, 0x80, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100498
Tobin Davis82f30042007-02-13 12:45:44 +0100499 bits = spec->cur_eapd ? 0 : 0x80;
500 snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0, 0x80, bits);
501 snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0, 0x80, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100502 return 1;
503}
504
505/* bind volumes of both NID 0x10 and 0x11 */
506static int cxt5045_hp_master_vol_put(struct snd_kcontrol *kcontrol,
507 struct snd_ctl_elem_value *ucontrol)
508{
509 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
510 long *valp = ucontrol->value.integer.value;
511 int change;
512
513 change = snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0,
514 0x7f, valp[0] & 0x7f);
515 change |= snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0,
516 0x7f, valp[1] & 0x7f);
517 snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0,
518 0x7f, valp[0] & 0x7f);
519 snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0,
520 0x7f, valp[1] & 0x7f);
521 return change;
522}
523
Tobin Davis7f296732007-03-12 11:39:01 +0100524/* toggle input of built-in and mic jack appropriately */
525static void cxt5045_hp_automic(struct hda_codec *codec)
526{
527 static struct hda_verb mic_jack_on[] = {
528 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
529 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
530 {}
531 };
532 static struct hda_verb mic_jack_off[] = {
533 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
534 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
535 {}
536 };
537 unsigned int present;
538
539 present = snd_hda_codec_read(codec, 0x12, 0,
540 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
541 if (present)
542 snd_hda_sequence_write(codec, mic_jack_on);
543 else
544 snd_hda_sequence_write(codec, mic_jack_off);
545}
546
Tobin Davisc9b443d2006-11-14 12:13:39 +0100547
548/* mute internal speaker if HP is plugged */
549static void cxt5045_hp_automute(struct hda_codec *codec)
550{
Tobin Davis82f30042007-02-13 12:45:44 +0100551 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100552 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100553
Tobin Davis82f30042007-02-13 12:45:44 +0100554 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100555 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100556
Tobin Davis7f296732007-03-12 11:39:01 +0100557 bits = (spec->hp_present || !spec->cur_eapd) ? 0x80 : 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100558 snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0, 0x80, bits);
559 snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0, 0x80, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100560}
561
562/* unsolicited event for HP jack sensing */
563static void cxt5045_hp_unsol_event(struct hda_codec *codec,
564 unsigned int res)
565{
566 res >>= 26;
567 switch (res) {
568 case CONEXANT_HP_EVENT:
569 cxt5045_hp_automute(codec);
570 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100571 case CONEXANT_MIC_EVENT:
572 cxt5045_hp_automic(codec);
573 break;
574
Tobin Davisc9b443d2006-11-14 12:13:39 +0100575 }
576}
577
578static struct snd_kcontrol_new cxt5045_mixers[] = {
579 {
580 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
581 .name = "Capture Source",
582 .info = conexant_mux_enum_info,
583 .get = conexant_mux_enum_get,
584 .put = conexant_mux_enum_put
585 },
Tobin Davis7f296732007-03-12 11:39:01 +0100586 HDA_CODEC_VOLUME("Int Mic Volume", 0x1a, 0x01, HDA_INPUT),
587 HDA_CODEC_MUTE("Int Mic Switch", 0x1a, 0x01, HDA_INPUT),
588 HDA_CODEC_VOLUME("Ext Mic Volume", 0x1a, 0x02, HDA_INPUT),
589 HDA_CODEC_MUTE("Ext Mic Switch", 0x1a, 0x02, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100590 {
591 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
592 .name = "Master Playback Volume",
593 .info = snd_hda_mixer_amp_volume_info,
594 .get = snd_hda_mixer_amp_volume_get,
595 .put = cxt5045_hp_master_vol_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100596 .private_value = HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100597 },
598 {
599 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
600 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100601 .info = cxt_eapd_info,
602 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100603 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100604 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100605 },
606
607 {}
608};
609
610static struct hda_verb cxt5045_init_verbs[] = {
611 /* Line in, Mic */
612 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
Tobin Davis7f296732007-03-12 11:39:01 +0100613 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100614 /* HP, Amp */
Tobin Davis82f30042007-02-13 12:45:44 +0100615 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
616 {0x17, AC_VERB_SET_CONNECT_SEL,0x01},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100617 {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davis82f30042007-02-13 12:45:44 +0100618 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x01},
619 {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
620 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x02},
621 {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
622 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
623 {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
624 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x04},
625 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100626 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100627 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100628 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
629 /* SPDIF route: PCM */
630 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100631 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100632 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100633 { } /* end */
634};
635
Tobin Davis7f296732007-03-12 11:39:01 +0100636
637static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
638 /* pin sensing on HP jack */
639 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200640 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100641};
642
643static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
644 /* pin sensing on HP jack */
645 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200646 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100647};
648
Tobin Davisc9b443d2006-11-14 12:13:39 +0100649#ifdef CONFIG_SND_DEBUG
650/* Test configuration for debugging, modelled after the ALC260 test
651 * configuration.
652 */
653static struct hda_input_mux cxt5045_test_capture_source = {
654 .num_items = 5,
655 .items = {
656 { "MIXER", 0x0 },
657 { "MIC1 pin", 0x1 },
658 { "LINE1 pin", 0x2 },
659 { "HP-OUT pin", 0x3 },
660 { "CD pin", 0x4 },
661 },
662};
663
664static struct snd_kcontrol_new cxt5045_test_mixer[] = {
665
666 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100667 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
668 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100669 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
670 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
671 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
672 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100673
674 /* Modes for retasking pin widgets */
675 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
676 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
677
Tobin Davis82f30042007-02-13 12:45:44 +0100678 /* EAPD Switch Control */
679 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
680
Tobin Davisc9b443d2006-11-14 12:13:39 +0100681 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100682
Tobin Davis7f296732007-03-12 11:39:01 +0100683 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
684 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
685 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
686 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
687 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
688 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
689 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
690 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
691 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
692 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100693 {
694 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
695 .name = "Input Source",
696 .info = conexant_mux_enum_info,
697 .get = conexant_mux_enum_get,
698 .put = conexant_mux_enum_put,
699 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200700 /* Audio input controls */
701 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
702 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
703 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
704 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
705 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
706 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
707 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
708 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
709 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
710 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100711 { } /* end */
712};
713
714static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100715 /* Set connections */
716 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
717 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
718 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100719 /* Enable retasking pins as output, initially without power amp */
720 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100721 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100722
723 /* Disable digital (SPDIF) pins initially, but users can enable
724 * them via a mixer switch. In the case of SPDIF-out, this initverb
725 * payload also sets the generation to 0, output to be in "consumer"
726 * PCM format, copyright asserted, no pre-emphasis and no validity
727 * control.
728 */
729 {0x13, AC_VERB_SET_DIGI_CONVERT_1, 0},
730
731 /* Start with output sum widgets muted and their output gains at min */
732 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
733 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
734
735 /* Unmute retasking pin widget output buffers since the default
736 * state appears to be output. As the pin mode is changed by the
737 * user the pin mode control will take care of enabling the pin's
738 * input/output buffers as needed.
739 */
740 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
741 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
742
743 /* Mute capture amp left and right */
744 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
745
746 /* Set ADC connection select to match default mixer setting (mic1
747 * pin)
748 */
749 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +0100750 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100751
752 /* Mute all inputs to mixer widget (even unconnected ones) */
753 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
754 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
755 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
756 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
757 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
758
759 { }
760};
761#endif
762
763
764/* initialize jack-sensing, too */
765static int cxt5045_init(struct hda_codec *codec)
766{
767 conexant_init(codec);
768 cxt5045_hp_automute(codec);
769 return 0;
770}
771
772
773enum {
Tobin Davis7f296732007-03-12 11:39:01 +0100774 CXT5045_LAPTOP, /* Laptops w/ EAPD support */
775 CXT5045_FUJITSU, /* Laptops w/ EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100776#ifdef CONFIG_SND_DEBUG
777 CXT5045_TEST,
778#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100779 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100780};
781
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100782static const char *cxt5045_models[CXT5045_MODELS] = {
783 [CXT5045_LAPTOP] = "laptop",
Tobin Davis7f296732007-03-12 11:39:01 +0100784 [CXT5045_FUJITSU] = "fujitsu",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100785#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100786 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100787#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100788};
789
790static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
791 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP),
Tobin Davis82f30042007-02-13 12:45:44 +0100792 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP),
Tobin Davis4d69d752007-05-03 12:17:11 +0200793 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP),
794 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP),
795 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP),
Claudio Matsuoka8481da52007-07-03 20:05:19 +0200796 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP),
Tobin Davis7f296732007-03-12 11:39:01 +0100797 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_FUJITSU),
Tobin Davisf8f794a2007-06-25 12:14:25 +0200798 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP),
Tobin Davis7f296732007-03-12 11:39:01 +0100799 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100800 {}
801};
802
803static int patch_cxt5045(struct hda_codec *codec)
804{
805 struct conexant_spec *spec;
806 int board_config;
807
808 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
809 if (!spec)
810 return -ENOMEM;
811 mutex_init(&spec->amp_mutex);
812 codec->spec = spec;
813
814 spec->multiout.max_channels = 2;
815 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
816 spec->multiout.dac_nids = cxt5045_dac_nids;
817 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
818 spec->num_adc_nids = 1;
819 spec->adc_nids = cxt5045_adc_nids;
820 spec->capsrc_nids = cxt5045_capsrc_nids;
821 spec->input_mux = &cxt5045_capture_source;
822 spec->num_mixers = 1;
823 spec->mixers[0] = cxt5045_mixers;
824 spec->num_init_verbs = 1;
825 spec->init_verbs[0] = cxt5045_init_verbs;
826 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +0100827 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
828 spec->channel_mode = cxt5045_modes,
829
Tobin Davisc9b443d2006-11-14 12:13:39 +0100830
831 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100832
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100833 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
834 cxt5045_models,
835 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100836 switch (board_config) {
837 case CXT5045_LAPTOP:
Tobin Davis7f296732007-03-12 11:39:01 +0100838 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100839 spec->input_mux = &cxt5045_capture_source;
840 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +0100841 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
842 spec->mixers[0] = cxt5045_mixers;
843 codec->patch_ops.init = cxt5045_init;
844 break;
845 case CXT5045_FUJITSU:
846 spec->input_mux = &cxt5045_capture_source;
847 spec->num_init_verbs = 2;
848 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100849 spec->mixers[0] = cxt5045_mixers;
850 codec->patch_ops.init = cxt5045_init;
851 break;
852#ifdef CONFIG_SND_DEBUG
853 case CXT5045_TEST:
854 spec->input_mux = &cxt5045_test_capture_source;
855 spec->mixers[0] = cxt5045_test_mixer;
856 spec->init_verbs[0] = cxt5045_test_init_verbs;
857#endif
858 }
859 return 0;
860}
861
862
863/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +0100864#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +0100865
Tobin Davis82f30042007-02-13 12:45:44 +0100866static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100867static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
868static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100869
Tobin Davis5cd57522006-11-20 17:42:09 +0100870static struct hda_channel_mode cxt5047_modes[1] = {
871 { 2, NULL },
872};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100873
874static struct hda_input_mux cxt5047_capture_source = {
Tobin Davis7f296732007-03-12 11:39:01 +0100875 .num_items = 1,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100876 .items = {
Tobin Davis7f296732007-03-12 11:39:01 +0100877 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100878 }
879};
880
881static struct hda_input_mux cxt5047_hp_capture_source = {
882 .num_items = 1,
883 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100884 { "ExtMic", 0x2 },
885 }
886};
887
888static struct hda_input_mux cxt5047_toshiba_capture_source = {
889 .num_items = 2,
890 .items = {
891 { "ExtMic", 0x2 },
892 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100893 }
894};
895
896/* turn on/off EAPD (+ mute HP) as a master switch */
897static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
898 struct snd_ctl_elem_value *ucontrol)
899{
900 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
901 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100902 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100903
Tobin Davis82f30042007-02-13 12:45:44 +0100904 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100905 return 0;
906
Tobin Davis82f30042007-02-13 12:45:44 +0100907 /* toggle internal speakers mute depending of presence of
908 * the headphone jack
909 */
910 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : 0x80;
911 snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0, 0x80, bits);
912 snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0, 0x80, bits);
913 bits = spec->cur_eapd ? 0 : 0x80;
914 snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0, 0x80, bits);
915 snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0, 0x80, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100916 return 1;
917}
918
Tobin Davis82f30042007-02-13 12:45:44 +0100919/* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100920static int cxt5047_hp_master_vol_put(struct snd_kcontrol *kcontrol,
921 struct snd_ctl_elem_value *ucontrol)
922{
923 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
924 long *valp = ucontrol->value.integer.value;
925 int change;
926
Tobin Davis82f30042007-02-13 12:45:44 +0100927 change = snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100928 0x7f, valp[0] & 0x7f);
Tobin Davis82f30042007-02-13 12:45:44 +0100929 change |= snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100930 0x7f, valp[1] & 0x7f);
931 snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0,
932 0x7f, valp[0] & 0x7f);
933 snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0,
934 0x7f, valp[1] & 0x7f);
935 return change;
936}
Tobin Davisc9b443d2006-11-14 12:13:39 +0100937
938/* mute internal speaker if HP is plugged */
939static void cxt5047_hp_automute(struct hda_codec *codec)
940{
Tobin Davis82f30042007-02-13 12:45:44 +0100941 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100942 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100943
Tobin Davis82f30042007-02-13 12:45:44 +0100944 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100945 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100946
947 bits = (spec->hp_present || !spec->cur_eapd) ? 0x80 : 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100948 snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0, 0x80, bits);
949 snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0, 0x80, bits);
950 /* Mute/Unmute PCM 2 for good measure - some systems need this */
951 snd_hda_codec_amp_update(codec, 0x1c, 0, HDA_OUTPUT, 0, 0x80, bits);
952 snd_hda_codec_amp_update(codec, 0x1c, 1, HDA_OUTPUT, 0, 0x80, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100953}
954
Tobin Davisfb3409e2007-05-17 09:40:47 +0200955/* mute internal speaker if HP is plugged */
956static void cxt5047_hp2_automute(struct hda_codec *codec)
957{
958 struct conexant_spec *spec = codec->spec;
959 unsigned int bits;
960
961 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
962 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
963
964 bits = spec->hp_present ? 0x80 : 0;
965 snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0, 0x80, bits);
966 snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0, 0x80, bits);
967 /* Mute/Unmute PCM 2 for good measure - some systems need this */
968 snd_hda_codec_amp_update(codec, 0x1c, 0, HDA_OUTPUT, 0, 0x80, bits);
969 snd_hda_codec_amp_update(codec, 0x1c, 1, HDA_OUTPUT, 0, 0x80, bits);
970}
971
Tobin Davisc9b443d2006-11-14 12:13:39 +0100972/* toggle input of built-in and mic jack appropriately */
973static void cxt5047_hp_automic(struct hda_codec *codec)
974{
975 static struct hda_verb mic_jack_on[] = {
976 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
977 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
978 {}
979 };
980 static struct hda_verb mic_jack_off[] = {
981 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
982 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
983 {}
984 };
985 unsigned int present;
986
Tobin Davis7f296732007-03-12 11:39:01 +0100987 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100988 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
989 if (present)
990 snd_hda_sequence_write(codec, mic_jack_on);
991 else
992 snd_hda_sequence_write(codec, mic_jack_off);
993}
994
995/* unsolicited event for HP jack sensing */
996static void cxt5047_hp_unsol_event(struct hda_codec *codec,
997 unsigned int res)
998{
999 res >>= 26;
1000 switch (res) {
1001 case CONEXANT_HP_EVENT:
1002 cxt5047_hp_automute(codec);
1003 break;
1004 case CONEXANT_MIC_EVENT:
1005 cxt5047_hp_automic(codec);
1006 break;
1007 }
1008}
1009
Tobin Davisfb3409e2007-05-17 09:40:47 +02001010/* unsolicited event for HP jack sensing - non-EAPD systems */
1011static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1012 unsigned int res)
1013{
1014 res >>= 26;
1015 switch (res) {
1016 case CONEXANT_HP_EVENT:
1017 cxt5047_hp2_automute(codec);
1018 break;
1019 case CONEXANT_MIC_EVENT:
1020 cxt5047_hp_automic(codec);
1021 break;
1022 }
1023}
1024
Tobin Davisc9b443d2006-11-14 12:13:39 +01001025static struct snd_kcontrol_new cxt5047_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001026 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1027 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001028 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1029 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001030 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1031 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1032 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1033 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001034 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1035 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
Tobin Davisb7589ce2007-04-24 17:56:55 +02001036 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1037 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1038 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1039 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001040
1041 {}
1042};
1043
1044static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1045 {
1046 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1047 .name = "Capture Source",
1048 .info = conexant_mux_enum_info,
1049 .get = conexant_mux_enum_get,
1050 .put = conexant_mux_enum_put
1051 },
1052 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1053 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1054 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1055 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1056 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1057 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1058 {
1059 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1060 .name = "Master Playback Volume",
1061 .info = snd_hda_mixer_amp_volume_info,
1062 .get = snd_hda_mixer_amp_volume_get,
1063 .put = cxt5047_hp_master_vol_put,
1064 .private_value = HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1065 },
1066 {
1067 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1068 .name = "Master Playback Switch",
1069 .info = cxt_eapd_info,
1070 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001071 .put = cxt5047_hp_master_sw_put,
1072 .private_value = 0x13,
1073 },
1074
1075 {}
1076};
1077
1078static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1079 {
1080 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1081 .name = "Capture Source",
1082 .info = conexant_mux_enum_info,
1083 .get = conexant_mux_enum_get,
1084 .put = conexant_mux_enum_put
1085 },
1086 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1087 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1088 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1089 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1090 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1091 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1092 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1093 {
1094 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1095 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001096 .info = cxt_eapd_info,
1097 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001098 .put = cxt5047_hp_master_sw_put,
1099 .private_value = 0x13,
1100 },
1101 { } /* end */
1102};
1103
1104static struct hda_verb cxt5047_init_verbs[] = {
1105 /* Line in, Mic, Built-in Mic */
1106 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1107 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1108 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001109 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001110 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1111 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis7f296732007-03-12 11:39:01 +01001112 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1113 /* Record selector: Mic */
1114 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1115 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1116 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1117 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001118 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1119 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1120 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1121 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001122 /* SPDIF route: PCM */
1123 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001124 /* Enable unsolicited events */
1125 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1126 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001127 { } /* end */
1128};
1129
1130/* configuration for Toshiba Laptops */
1131static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1132 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1133 /* pin sensing on HP and Mic jacks */
1134 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1135 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001136 /* Speaker routing */
1137 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001138 {}
1139};
1140
1141/* configuration for HP Laptops */
1142static struct hda_verb cxt5047_hp_init_verbs[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001143 /* pin sensing on HP jack */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001144 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001145 /* Record selector: Ext Mic */
1146 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
Tobin Davis82f30042007-02-13 12:45:44 +01001147 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1148 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1149 /* Speaker routing */
1150 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001151 {}
1152};
1153
1154/* Test configuration for debugging, modelled after the ALC260 test
1155 * configuration.
1156 */
1157#ifdef CONFIG_SND_DEBUG
1158static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001159 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001160 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001161 { "LINE1 pin", 0x0 },
1162 { "MIC1 pin", 0x1 },
1163 { "MIC2 pin", 0x2 },
1164 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001165 },
1166};
1167
1168static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1169
1170 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001171 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1172 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1173 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1174 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001175 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1176 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1177 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1178 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001179 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1180 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1181 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1182 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001183
1184 /* Modes for retasking pin widgets */
1185 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1186 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1187
Tobin Davis82f30042007-02-13 12:45:44 +01001188 /* EAPD Switch Control */
1189 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1190
Tobin Davisc9b443d2006-11-14 12:13:39 +01001191 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001192 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1193 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1194 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1195 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1196 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1197 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1198 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1199 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001200
Tobin Davis82f30042007-02-13 12:45:44 +01001201 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1202 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1203 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1204 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1205 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1206 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1207 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1208 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001209 {
1210 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1211 .name = "Input Source",
1212 .info = conexant_mux_enum_info,
1213 .get = conexant_mux_enum_get,
1214 .put = conexant_mux_enum_put,
1215 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001216 { } /* end */
1217};
1218
1219static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001220 /* Enable retasking pins as output, initially without power amp */
1221 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1222 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1223 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1224
1225 /* Disable digital (SPDIF) pins initially, but users can enable
1226 * them via a mixer switch. In the case of SPDIF-out, this initverb
1227 * payload also sets the generation to 0, output to be in "consumer"
1228 * PCM format, copyright asserted, no pre-emphasis and no validity
1229 * control.
1230 */
1231 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1232
1233 /* Ensure mic1, mic2, line1 pin widgets take input from the
1234 * OUT1 sum bus when acting as an output.
1235 */
1236 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1237 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1238
1239 /* Start with output sum widgets muted and their output gains at min */
1240 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1241 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1242
1243 /* Unmute retasking pin widget output buffers since the default
1244 * state appears to be output. As the pin mode is changed by the
1245 * user the pin mode control will take care of enabling the pin's
1246 * input/output buffers as needed.
1247 */
1248 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1249 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1250 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1251
1252 /* Mute capture amp left and right */
1253 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1254
1255 /* Set ADC connection select to match default mixer setting (mic1
1256 * pin)
1257 */
1258 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1259
1260 /* Mute all inputs to mixer widget (even unconnected ones) */
1261 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1262 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1263 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1264 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1265 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1266 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1267 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1268 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1269
1270 { }
1271};
1272#endif
1273
1274
1275/* initialize jack-sensing, too */
1276static int cxt5047_hp_init(struct hda_codec *codec)
1277{
1278 conexant_init(codec);
1279 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001280 return 0;
1281}
1282
1283
1284enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001285 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1286 CXT5047_LAPTOP_HP, /* Some HP laptops */
1287 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001288#ifdef CONFIG_SND_DEBUG
1289 CXT5047_TEST,
1290#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001291 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001292};
1293
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001294static const char *cxt5047_models[CXT5047_MODELS] = {
1295 [CXT5047_LAPTOP] = "laptop",
1296 [CXT5047_LAPTOP_HP] = "laptop-hp",
1297 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001298#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001299 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001300#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001301};
1302
1303static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1304 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
1305 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
Tobin Davis82f30042007-02-13 12:45:44 +01001306 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001307 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1308 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001309 {}
1310};
1311
1312static int patch_cxt5047(struct hda_codec *codec)
1313{
1314 struct conexant_spec *spec;
1315 int board_config;
1316
1317 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1318 if (!spec)
1319 return -ENOMEM;
1320 mutex_init(&spec->amp_mutex);
1321 codec->spec = spec;
1322
1323 spec->multiout.max_channels = 2;
1324 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1325 spec->multiout.dac_nids = cxt5047_dac_nids;
1326 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1327 spec->num_adc_nids = 1;
1328 spec->adc_nids = cxt5047_adc_nids;
1329 spec->capsrc_nids = cxt5047_capsrc_nids;
1330 spec->input_mux = &cxt5047_capture_source;
1331 spec->num_mixers = 1;
1332 spec->mixers[0] = cxt5047_mixers;
1333 spec->num_init_verbs = 1;
1334 spec->init_verbs[0] = cxt5047_init_verbs;
1335 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001336 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1337 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001338
1339 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001340
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001341 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1342 cxt5047_models,
1343 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001344 switch (board_config) {
1345 case CXT5047_LAPTOP:
Tobin Davisfb3409e2007-05-17 09:40:47 +02001346 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001347 break;
1348 case CXT5047_LAPTOP_HP:
1349 spec->input_mux = &cxt5047_hp_capture_source;
1350 spec->num_init_verbs = 2;
1351 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1352 spec->mixers[0] = cxt5047_hp_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001353 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001354 codec->patch_ops.init = cxt5047_hp_init;
1355 break;
1356 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001357 spec->input_mux = &cxt5047_toshiba_capture_source;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001358 spec->num_init_verbs = 2;
1359 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davis82f30042007-02-13 12:45:44 +01001360 spec->mixers[0] = cxt5047_toshiba_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001361 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001362 break;
1363#ifdef CONFIG_SND_DEBUG
1364 case CXT5047_TEST:
1365 spec->input_mux = &cxt5047_test_capture_source;
1366 spec->mixers[0] = cxt5047_test_mixer;
1367 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001368 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001369#endif
1370 }
1371 return 0;
1372}
1373
1374struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001375 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1376 .patch = patch_cxt5045 },
1377 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1378 .patch = patch_cxt5047 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001379 {} /* terminator */
1380};