blob: 23a1c75085b58fcd742a0e015003005a43a72931 [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
139/*
140 * Analog capture
141 */
142static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
143 struct hda_codec *codec,
144 unsigned int stream_tag,
145 unsigned int format,
146 struct snd_pcm_substream *substream)
147{
148 struct conexant_spec *spec = codec->spec;
149 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
150 stream_tag, 0, format);
151 return 0;
152}
153
154static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
155 struct hda_codec *codec,
156 struct snd_pcm_substream *substream)
157{
158 struct conexant_spec *spec = codec->spec;
159 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
160 0, 0, 0);
161 return 0;
162}
163
164
165
166static struct hda_pcm_stream conexant_pcm_analog_playback = {
167 .substreams = 1,
168 .channels_min = 2,
169 .channels_max = 2,
170 .nid = 0, /* fill later */
171 .ops = {
172 .open = conexant_playback_pcm_open,
173 .prepare = conexant_playback_pcm_prepare,
174 .cleanup = conexant_playback_pcm_cleanup
175 },
176};
177
178static struct hda_pcm_stream conexant_pcm_analog_capture = {
179 .substreams = 1,
180 .channels_min = 2,
181 .channels_max = 2,
182 .nid = 0, /* fill later */
183 .ops = {
184 .prepare = conexant_capture_pcm_prepare,
185 .cleanup = conexant_capture_pcm_cleanup
186 },
187};
188
189
190static struct hda_pcm_stream conexant_pcm_digital_playback = {
191 .substreams = 1,
192 .channels_min = 2,
193 .channels_max = 2,
194 .nid = 0, /* fill later */
195 .ops = {
196 .open = conexant_dig_playback_pcm_open,
197 .close = conexant_dig_playback_pcm_close
198 },
199};
200
201static struct hda_pcm_stream conexant_pcm_digital_capture = {
202 .substreams = 1,
203 .channels_min = 2,
204 .channels_max = 2,
205 /* NID is set in alc_build_pcms */
206};
207
208static int conexant_build_pcms(struct hda_codec *codec)
209{
210 struct conexant_spec *spec = codec->spec;
211 struct hda_pcm *info = spec->pcm_rec;
212
213 codec->num_pcms = 1;
214 codec->pcm_info = info;
215
216 info->name = "CONEXANT Analog";
217 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
218 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
219 spec->multiout.max_channels;
220 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
221 spec->multiout.dac_nids[0];
222 info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_analog_capture;
223 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
224 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
225
226 if (spec->multiout.dig_out_nid) {
227 info++;
228 codec->num_pcms++;
229 info->name = "Conexant Digital";
230 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
231 conexant_pcm_digital_playback;
232 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
233 spec->multiout.dig_out_nid;
234 if (spec->dig_in_nid) {
235 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
236 conexant_pcm_digital_capture;
237 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
238 spec->dig_in_nid;
239 }
240 }
241
242 return 0;
243}
244
245static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
246 struct snd_ctl_elem_info *uinfo)
247{
248 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
249 struct conexant_spec *spec = codec->spec;
250
251 return snd_hda_input_mux_info(spec->input_mux, uinfo);
252}
253
254static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
255 struct snd_ctl_elem_value *ucontrol)
256{
257 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
258 struct conexant_spec *spec = codec->spec;
259 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
260
261 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
262 return 0;
263}
264
265static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
266 struct snd_ctl_elem_value *ucontrol)
267{
268 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
269 struct conexant_spec *spec = codec->spec;
270 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
271
272 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
273 spec->capsrc_nids[adc_idx],
274 &spec->cur_mux[adc_idx]);
275}
276
277static int conexant_init(struct hda_codec *codec)
278{
279 struct conexant_spec *spec = codec->spec;
280 int i;
281
282 for (i = 0; i < spec->num_init_verbs; i++)
283 snd_hda_sequence_write(codec, spec->init_verbs[i]);
284 return 0;
285}
286
287static void conexant_free(struct hda_codec *codec)
288{
289 struct conexant_spec *spec = codec->spec;
290 unsigned int i;
291
292 if (spec->kctl_alloc) {
293 for (i = 0; i < spec->num_kctl_used; i++)
294 kfree(spec->kctl_alloc[i].name);
295 kfree(spec->kctl_alloc);
296 }
297
298 kfree(codec->spec);
299}
300
301#ifdef CONFIG_PM
302static int conexant_resume(struct hda_codec *codec)
303{
304 struct conexant_spec *spec = codec->spec;
305 int i;
306
307 codec->patch_ops.init(codec);
308 for (i = 0; i < spec->num_mixers; i++)
309 snd_hda_resume_ctls(codec, spec->mixers[i]);
310 if (spec->multiout.dig_out_nid)
311 snd_hda_resume_spdif_out(codec);
312 if (spec->dig_in_nid)
313 snd_hda_resume_spdif_in(codec);
314 return 0;
315}
316#endif
317
318static int conexant_build_controls(struct hda_codec *codec)
319{
320 struct conexant_spec *spec = codec->spec;
321 unsigned int i;
322 int err;
323
324 for (i = 0; i < spec->num_mixers; i++) {
325 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
326 if (err < 0)
327 return err;
328 }
329 if (spec->multiout.dig_out_nid) {
330 err = snd_hda_create_spdif_out_ctls(codec,
331 spec->multiout.dig_out_nid);
332 if (err < 0)
333 return err;
334 }
335 if (spec->dig_in_nid) {
336 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
337 if (err < 0)
338 return err;
339 }
340 return 0;
341}
342
343static struct hda_codec_ops conexant_patch_ops = {
344 .build_controls = conexant_build_controls,
345 .build_pcms = conexant_build_pcms,
346 .init = conexant_init,
347 .free = conexant_free,
348#ifdef CONFIG_PM
349 .resume = conexant_resume,
350#endif
351};
352
353/*
354 * EAPD control
355 * the private value = nid | (invert << 8)
356 */
357
Tobin Davis82f30042007-02-13 12:45:44 +0100358static int cxt_eapd_info(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100359 struct snd_ctl_elem_info *uinfo)
360{
361 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
362 uinfo->count = 1;
363 uinfo->value.integer.min = 0;
364 uinfo->value.integer.max = 1;
365 return 0;
366}
367
Tobin Davis82f30042007-02-13 12:45:44 +0100368static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100369 struct snd_ctl_elem_value *ucontrol)
370{
371 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
372 struct conexant_spec *spec = codec->spec;
373 int invert = (kcontrol->private_value >> 8) & 1;
374 if (invert)
375 ucontrol->value.integer.value[0] = !spec->cur_eapd;
376 else
377 ucontrol->value.integer.value[0] = spec->cur_eapd;
378 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100379
Tobin Davisc9b443d2006-11-14 12:13:39 +0100380}
381
Tobin Davis82f30042007-02-13 12:45:44 +0100382static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100383 struct snd_ctl_elem_value *ucontrol)
384{
385 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
386 struct conexant_spec *spec = codec->spec;
387 int invert = (kcontrol->private_value >> 8) & 1;
388 hda_nid_t nid = kcontrol->private_value & 0xff;
389 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100390
Tobin Davisc9b443d2006-11-14 12:13:39 +0100391 eapd = ucontrol->value.integer.value[0];
392 if (invert)
393 eapd = !eapd;
394 if (eapd == spec->cur_eapd && !codec->in_resume)
395 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100396
Tobin Davisc9b443d2006-11-14 12:13:39 +0100397 spec->cur_eapd = eapd;
398 snd_hda_codec_write(codec, nid,
399 0, AC_VERB_SET_EAPD_BTLENABLE,
400 eapd ? 0x02 : 0x00);
401 return 1;
402}
403
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100404/* controls for test mode */
405#ifdef CONFIG_SND_DEBUG
406
Tobin Davis82f30042007-02-13 12:45:44 +0100407#define CXT_EAPD_SWITCH(xname, nid, mask) \
408 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
409 .info = cxt_eapd_info, \
410 .get = cxt_eapd_get, \
411 .put = cxt_eapd_put, \
412 .private_value = nid | (mask<<16) }
413
414
415
Tobin Davisc9b443d2006-11-14 12:13:39 +0100416static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
417 struct snd_ctl_elem_info *uinfo)
418{
419 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
420 struct conexant_spec *spec = codec->spec;
421 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
422 spec->num_channel_mode);
423}
424
425static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
426 struct snd_ctl_elem_value *ucontrol)
427{
428 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
429 struct conexant_spec *spec = codec->spec;
430 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
431 spec->num_channel_mode,
432 spec->multiout.max_channels);
433}
434
435static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
436 struct snd_ctl_elem_value *ucontrol)
437{
438 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
439 struct conexant_spec *spec = codec->spec;
440 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
441 spec->num_channel_mode,
442 &spec->multiout.max_channels);
443 if (err >= 0 && spec->need_dac_fix)
444 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
445 return err;
446}
447
448#define CXT_PIN_MODE(xname, nid, dir) \
449 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
450 .info = conexant_ch_mode_info, \
451 .get = conexant_ch_mode_get, \
452 .put = conexant_ch_mode_put, \
453 .private_value = nid | (dir<<16) }
454
455static int cxt_gpio_data_info(struct snd_kcontrol *kcontrol,
456 struct snd_ctl_elem_info *uinfo)
457{
458 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
459 uinfo->count = 1;
460 uinfo->value.integer.min = 0;
461 uinfo->value.integer.max = 1;
462 return 0;
463}
464
465static int cxt_gpio_data_get(struct snd_kcontrol *kcontrol,
466 struct snd_ctl_elem_value *ucontrol)
467{
468 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
469 hda_nid_t nid = kcontrol->private_value & 0xffff;
470 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
471 long *valp = ucontrol->value.integer.value;
472 unsigned int val = snd_hda_codec_read(codec, nid, 0,
473 AC_VERB_GET_GPIO_DATA, 0x00);
474
475 *valp = (val & mask) != 0;
476 return 0;
477}
478
479static int cxt_gpio_data_put(struct snd_kcontrol *kcontrol,
480 struct snd_ctl_elem_value *ucontrol)
481{
482 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
483 hda_nid_t nid = kcontrol->private_value & 0xffff;
484 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
485 long val = *ucontrol->value.integer.value;
486 unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
487 AC_VERB_GET_GPIO_DATA,
488 0x00);
489 unsigned int old_data = gpio_data;
490
491 /* Set/unset the masked GPIO bit(s) as needed */
492 if (val == 0)
493 gpio_data &= ~mask;
494 else
495 gpio_data |= mask;
496 if (gpio_data == old_data && !codec->in_resume)
497 return 0;
498 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_GPIO_DATA, gpio_data);
499 return 1;
500}
501
502#define CXT_GPIO_DATA_SWITCH(xname, nid, mask) \
503 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
504 .info = cxt_gpio_data_info, \
505 .get = cxt_gpio_data_get, \
506 .put = cxt_gpio_data_put, \
507 .private_value = nid | (mask<<16) }
Tobin Davis82f30042007-02-13 12:45:44 +0100508#if 0
Tobin Davisc9b443d2006-11-14 12:13:39 +0100509static int cxt_spdif_ctrl_info(struct snd_kcontrol *kcontrol,
510 struct snd_ctl_elem_info *uinfo)
511{
512 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
513 uinfo->count = 1;
514 uinfo->value.integer.min = 0;
515 uinfo->value.integer.max = 1;
516 return 0;
517}
518
519static int cxt_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
520 struct snd_ctl_elem_value *ucontrol)
521{
522 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
523 hda_nid_t nid = kcontrol->private_value & 0xffff;
524 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
525 long *valp = ucontrol->value.integer.value;
526 unsigned int val = snd_hda_codec_read(codec, nid, 0,
527 AC_VERB_GET_DIGI_CONVERT, 0x00);
528
529 *valp = (val & mask) != 0;
530 return 0;
531}
532
533static int cxt_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
534 struct snd_ctl_elem_value *ucontrol)
535{
536 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
537 hda_nid_t nid = kcontrol->private_value & 0xffff;
538 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
539 long val = *ucontrol->value.integer.value;
540 unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
541 AC_VERB_GET_DIGI_CONVERT,
542 0x00);
543 unsigned int old_data = ctrl_data;
544
545 /* Set/unset the masked control bit(s) as needed */
546 if (val == 0)
547 ctrl_data &= ~mask;
548 else
549 ctrl_data |= mask;
550 if (ctrl_data == old_data && !codec->in_resume)
551 return 0;
552 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
553 ctrl_data);
554 return 1;
555}
556
557#define CXT_SPDIF_CTRL_SWITCH(xname, nid, mask) \
558 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
559 .info = cxt_spdif_ctrl_info, \
560 .get = cxt_spdif_ctrl_get, \
561 .put = cxt_spdif_ctrl_put, \
562 .private_value = nid | (mask<<16) }
Tobin Davis82f30042007-02-13 12:45:44 +0100563#endif
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100564#endif /* CONFIG_SND_DEBUG */
565
Tobin Davisc9b443d2006-11-14 12:13:39 +0100566/* Conexant 5045 specific */
567
568static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
569static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
570static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
571#define CXT5045_SPDIF_OUT 0x13
572
Tobin Davis5cd57522006-11-20 17:42:09 +0100573static struct hda_channel_mode cxt5045_modes[1] = {
574 { 2, NULL },
575};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100576
577static struct hda_input_mux cxt5045_capture_source = {
578 .num_items = 2,
579 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100580 { "IntMic", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100581 { "LineIn", 0x2 },
582 }
583};
584
585/* turn on/off EAPD (+ mute HP) as a master switch */
586static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
587 struct snd_ctl_elem_value *ucontrol)
588{
589 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
590 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100591 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100592
Tobin Davis82f30042007-02-13 12:45:44 +0100593 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100594 return 0;
595
Tobin Davis82f30042007-02-13 12:45:44 +0100596 /* toggle internal speakers mute depending of presence of
597 * the headphone jack
598 */
599 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : 0x80;
600 snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0, 0x80, bits);
601 snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0, 0x80, bits);
602 bits = spec->cur_eapd ? 0 : 0x80;
603 snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0, 0x80, bits);
604 snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0, 0x80, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100605 return 1;
606}
607
608/* bind volumes of both NID 0x10 and 0x11 */
609static int cxt5045_hp_master_vol_put(struct snd_kcontrol *kcontrol,
610 struct snd_ctl_elem_value *ucontrol)
611{
612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
613 long *valp = ucontrol->value.integer.value;
614 int change;
615
616 change = snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0,
617 0x7f, valp[0] & 0x7f);
618 change |= snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0,
619 0x7f, valp[1] & 0x7f);
620 snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0,
621 0x7f, valp[0] & 0x7f);
622 snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0,
623 0x7f, valp[1] & 0x7f);
624 return change;
625}
626
627
628/* mute internal speaker if HP is plugged */
629static void cxt5045_hp_automute(struct hda_codec *codec)
630{
Tobin Davis82f30042007-02-13 12:45:44 +0100631 struct conexant_spec *spec = codec->spec;
632 unsigned int bits = (spec->hp_present || !spec->cur_eapd) ? 0x80 : 0;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100633
Tobin Davis82f30042007-02-13 12:45:44 +0100634 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100635 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davis82f30042007-02-13 12:45:44 +0100636 snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0, 0x80, bits);
637 snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0, 0x80, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100638}
639
640/* unsolicited event for HP jack sensing */
641static void cxt5045_hp_unsol_event(struct hda_codec *codec,
642 unsigned int res)
643{
644 res >>= 26;
645 switch (res) {
646 case CONEXANT_HP_EVENT:
647 cxt5045_hp_automute(codec);
648 break;
649 }
650}
651
652static struct snd_kcontrol_new cxt5045_mixers[] = {
653 {
654 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
655 .name = "Capture Source",
656 .info = conexant_mux_enum_info,
657 .get = conexant_mux_enum_get,
658 .put = conexant_mux_enum_put
659 },
Tobin Davis82f30042007-02-13 12:45:44 +0100660 HDA_CODEC_VOLUME("Int Mic Volume", 0x17, 0x01, HDA_INPUT),
661 HDA_CODEC_MUTE("Int Mic Switch", 0x17, 0x01, HDA_INPUT),
662 HDA_CODEC_VOLUME("Ext Mic Volume", 0x17, 0x02, HDA_INPUT),
663 HDA_CODEC_MUTE("Ext Mic Switch", 0x17, 0x02, HDA_INPUT),
664 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
665 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100666 {
667 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
668 .name = "Master Playback Volume",
669 .info = snd_hda_mixer_amp_volume_info,
670 .get = snd_hda_mixer_amp_volume_get,
671 .put = cxt5045_hp_master_vol_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100672 .private_value = HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100673 },
674 {
675 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
676 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100677 .info = cxt_eapd_info,
678 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100679 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100680 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100681 },
682
683 {}
684};
685
686static struct hda_verb cxt5045_init_verbs[] = {
687 /* Line in, Mic */
688 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
689 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
690 /* HP, Amp */
Tobin Davis82f30042007-02-13 12:45:44 +0100691 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
692 {0x17, AC_VERB_SET_CONNECT_SEL,0x01},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100693 {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davis82f30042007-02-13 12:45:44 +0100694 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x01},
695 {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
696 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x02},
697 {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
698 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
699 {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
700 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x04},
701 /* Record selector: Int mic */
702 {0x1a, AC_VERB_SET_CONNECT_SEL,0x0},
703 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100704 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
705 /* SPDIF route: PCM */
706 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
707 /* pin sensing on HP and Mic jacks */
708 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
709 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100710 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100711 { } /* end */
712};
713
714#ifdef CONFIG_SND_DEBUG
715/* Test configuration for debugging, modelled after the ALC260 test
716 * configuration.
717 */
718static struct hda_input_mux cxt5045_test_capture_source = {
719 .num_items = 5,
720 .items = {
721 { "MIXER", 0x0 },
722 { "MIC1 pin", 0x1 },
723 { "LINE1 pin", 0x2 },
724 { "HP-OUT pin", 0x3 },
725 { "CD pin", 0x4 },
726 },
727};
728
729static struct snd_kcontrol_new cxt5045_test_mixer[] = {
730
731 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100732 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
733 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
734
735 /* Modes for retasking pin widgets */
736 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
737 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
738
Tobin Davis82f30042007-02-13 12:45:44 +0100739 /* EAPD Switch Control */
740 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
741
Tobin Davisc9b443d2006-11-14 12:13:39 +0100742 /* Loopback mixer controls */
743 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x17, 0x01, HDA_INPUT),
744 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x17, 0x01, HDA_INPUT),
745 HDA_CODEC_VOLUME("LINE loopback Playback Volume", 0x17, 0x02, HDA_INPUT),
746 HDA_CODEC_MUTE("LINE loopback Playback Switch", 0x17, 0x02, HDA_INPUT),
747 HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x17, 0x03, HDA_INPUT),
748 HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x17, 0x03, HDA_INPUT),
749 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x04, HDA_INPUT),
750 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x04, HDA_INPUT),
751
Tobin Davis82f30042007-02-13 12:45:44 +0100752 HDA_CODEC_VOLUME("Capture-1 Volume", 0x17, 0x0, HDA_INPUT),
753 HDA_CODEC_MUTE("Capture-1 Switch", 0x17, 0x0, HDA_INPUT),
754 HDA_CODEC_VOLUME("Capture-2 Volume", 0x17, 0x1, HDA_INPUT),
755 HDA_CODEC_MUTE("Capture-2 Switch", 0x17, 0x1, HDA_INPUT),
756 HDA_CODEC_VOLUME("Capture-3 Volume", 0x17, 0x2, HDA_INPUT),
757 HDA_CODEC_MUTE("Capture-3 Switch", 0x17, 0x2, HDA_INPUT),
758 HDA_CODEC_VOLUME("Capture-4 Volume", 0x17, 0x3, HDA_INPUT),
759 HDA_CODEC_MUTE("Capture-4 Switch", 0x17, 0x3, HDA_INPUT),
760 HDA_CODEC_VOLUME("Capture-5 Volume", 0x17, 0x4, HDA_INPUT),
761 HDA_CODEC_MUTE("Capture-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100762 {
763 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
764 .name = "Input Source",
765 .info = conexant_mux_enum_info,
766 .get = conexant_mux_enum_get,
767 .put = conexant_mux_enum_put,
768 },
769
770 { } /* end */
771};
772
773static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100774 /* Enable retasking pins as output, initially without power amp */
775 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis82f30042007-02-13 12:45:44 +0100776 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100777
778 /* Disable digital (SPDIF) pins initially, but users can enable
779 * them via a mixer switch. In the case of SPDIF-out, this initverb
780 * payload also sets the generation to 0, output to be in "consumer"
781 * PCM format, copyright asserted, no pre-emphasis and no validity
782 * control.
783 */
784 {0x13, AC_VERB_SET_DIGI_CONVERT_1, 0},
785
786 /* Start with output sum widgets muted and their output gains at min */
787 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
788 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
789
790 /* Unmute retasking pin widget output buffers since the default
791 * state appears to be output. As the pin mode is changed by the
792 * user the pin mode control will take care of enabling the pin's
793 * input/output buffers as needed.
794 */
795 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
796 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
797
798 /* Mute capture amp left and right */
799 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
800
801 /* Set ADC connection select to match default mixer setting (mic1
802 * pin)
803 */
804 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
805
806 /* Mute all inputs to mixer widget (even unconnected ones) */
807 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
808 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
809 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
810 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
811 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
812
813 { }
814};
815#endif
816
817
818/* initialize jack-sensing, too */
819static int cxt5045_init(struct hda_codec *codec)
820{
821 conexant_init(codec);
822 cxt5045_hp_automute(codec);
823 return 0;
824}
825
826
827enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100828 CXT5045_LAPTOP, /* Laptops w/ EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100829#ifdef CONFIG_SND_DEBUG
830 CXT5045_TEST,
831#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100832 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100833};
834
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100835static const char *cxt5045_models[CXT5045_MODELS] = {
836 [CXT5045_LAPTOP] = "laptop",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100837#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100838 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100839#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100840};
841
842static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
843 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP),
Tobin Davis82f30042007-02-13 12:45:44 +0100844 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP),
845 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100846 {}
847};
848
849static int patch_cxt5045(struct hda_codec *codec)
850{
851 struct conexant_spec *spec;
852 int board_config;
853
854 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
855 if (!spec)
856 return -ENOMEM;
857 mutex_init(&spec->amp_mutex);
858 codec->spec = spec;
859
860 spec->multiout.max_channels = 2;
861 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
862 spec->multiout.dac_nids = cxt5045_dac_nids;
863 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
864 spec->num_adc_nids = 1;
865 spec->adc_nids = cxt5045_adc_nids;
866 spec->capsrc_nids = cxt5045_capsrc_nids;
867 spec->input_mux = &cxt5045_capture_source;
868 spec->num_mixers = 1;
869 spec->mixers[0] = cxt5045_mixers;
870 spec->num_init_verbs = 1;
871 spec->init_verbs[0] = cxt5045_init_verbs;
872 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +0100873 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
874 spec->channel_mode = cxt5045_modes,
875
Tobin Davisc9b443d2006-11-14 12:13:39 +0100876
877 codec->patch_ops = conexant_patch_ops;
878 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
879
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100880 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
881 cxt5045_models,
882 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100883 switch (board_config) {
884 case CXT5045_LAPTOP:
885 spec->input_mux = &cxt5045_capture_source;
886 spec->num_init_verbs = 2;
887 spec->init_verbs[1] = cxt5045_init_verbs;
888 spec->mixers[0] = cxt5045_mixers;
889 codec->patch_ops.init = cxt5045_init;
890 break;
891#ifdef CONFIG_SND_DEBUG
892 case CXT5045_TEST:
893 spec->input_mux = &cxt5045_test_capture_source;
894 spec->mixers[0] = cxt5045_test_mixer;
895 spec->init_verbs[0] = cxt5045_test_init_verbs;
896#endif
897 }
898 return 0;
899}
900
901
902/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +0100903#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +0100904
Tobin Davis82f30042007-02-13 12:45:44 +0100905static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100906static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
907static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100908
Tobin Davis5cd57522006-11-20 17:42:09 +0100909static struct hda_channel_mode cxt5047_modes[1] = {
910 { 2, NULL },
911};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100912
913static struct hda_input_mux cxt5047_capture_source = {
914 .num_items = 2,
915 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100916 { "ExtMic", 0x0 },
917 { "IntMic", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100918 }
919};
920
921static struct hda_input_mux cxt5047_hp_capture_source = {
922 .num_items = 1,
923 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100924 { "ExtMic", 0x2 },
925 }
926};
927
928static struct hda_input_mux cxt5047_toshiba_capture_source = {
929 .num_items = 2,
930 .items = {
931 { "ExtMic", 0x2 },
932 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100933 }
934};
935
936/* turn on/off EAPD (+ mute HP) as a master switch */
937static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
938 struct snd_ctl_elem_value *ucontrol)
939{
940 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
941 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100942 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100943
Tobin Davis82f30042007-02-13 12:45:44 +0100944 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100945 return 0;
946
Tobin Davis82f30042007-02-13 12:45:44 +0100947 /* toggle internal speakers mute depending of presence of
948 * the headphone jack
949 */
950 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : 0x80;
951 snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0, 0x80, bits);
952 snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0, 0x80, bits);
953 bits = spec->cur_eapd ? 0 : 0x80;
954 snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0, 0x80, bits);
955 snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0, 0x80, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100956 return 1;
957}
958
Tobin Davis82f30042007-02-13 12:45:44 +0100959/* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100960static int cxt5047_hp_master_vol_put(struct snd_kcontrol *kcontrol,
961 struct snd_ctl_elem_value *ucontrol)
962{
963 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
964 long *valp = ucontrol->value.integer.value;
965 int change;
966
Tobin Davis82f30042007-02-13 12:45:44 +0100967 change = snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100968 0x7f, valp[0] & 0x7f);
Tobin Davis82f30042007-02-13 12:45:44 +0100969 change |= snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100970 0x7f, valp[1] & 0x7f);
971 snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0,
972 0x7f, valp[0] & 0x7f);
973 snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0,
974 0x7f, valp[1] & 0x7f);
975 return change;
976}
Tobin Davisc9b443d2006-11-14 12:13:39 +0100977
978/* mute internal speaker if HP is plugged */
979static void cxt5047_hp_automute(struct hda_codec *codec)
980{
Tobin Davis82f30042007-02-13 12:45:44 +0100981 struct conexant_spec *spec = codec->spec;
982 unsigned int bits = spec->hp_present || !spec->cur_eapd ? 0x80 : 0;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100983
Tobin Davis82f30042007-02-13 12:45:44 +0100984 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100985 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davis82f30042007-02-13 12:45:44 +0100986 snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0, 0x80, bits);
987 snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0, 0x80, bits);
988 /* Mute/Unmute PCM 2 for good measure - some systems need this */
989 snd_hda_codec_amp_update(codec, 0x1c, 0, HDA_OUTPUT, 0, 0x80, bits);
990 snd_hda_codec_amp_update(codec, 0x1c, 1, HDA_OUTPUT, 0, 0x80, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100991}
992
993/* toggle input of built-in and mic jack appropriately */
994static void cxt5047_hp_automic(struct hda_codec *codec)
995{
996 static struct hda_verb mic_jack_on[] = {
997 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
998 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
999 {}
1000 };
1001 static struct hda_verb mic_jack_off[] = {
1002 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1003 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1004 {}
1005 };
1006 unsigned int present;
1007
1008 present = snd_hda_codec_read(codec, 0x08, 0,
1009 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1010 if (present)
1011 snd_hda_sequence_write(codec, mic_jack_on);
1012 else
1013 snd_hda_sequence_write(codec, mic_jack_off);
1014}
1015
1016/* unsolicited event for HP jack sensing */
1017static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1018 unsigned int res)
1019{
1020 res >>= 26;
1021 switch (res) {
1022 case CONEXANT_HP_EVENT:
1023 cxt5047_hp_automute(codec);
1024 break;
1025 case CONEXANT_MIC_EVENT:
1026 cxt5047_hp_automic(codec);
1027 break;
1028 }
1029}
1030
1031static struct snd_kcontrol_new cxt5047_mixers[] = {
1032 {
1033 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1034 .name = "Capture Source",
1035 .info = conexant_mux_enum_info,
1036 .get = conexant_mux_enum_get,
1037 .put = conexant_mux_enum_put
1038 },
1039 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1040 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1041 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1042 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1043 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1044 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001045 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1046 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
1047 {
1048 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1049 .name = "Master Playback Volume",
1050 .info = snd_hda_mixer_amp_volume_info,
1051 .get = snd_hda_mixer_amp_volume_get,
1052 .put = cxt5047_hp_master_vol_put,
1053 .private_value = HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1054 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001055 {
1056 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1057 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001058 .info = cxt_eapd_info,
1059 .get = cxt_eapd_get,
1060 .put = cxt5047_hp_master_sw_put,
1061 .private_value = 0x13,
1062 },
1063
1064 {}
1065};
1066
1067static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1068 {
1069 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1070 .name = "Capture Source",
1071 .info = conexant_mux_enum_info,
1072 .get = conexant_mux_enum_get,
1073 .put = conexant_mux_enum_put
1074 },
1075 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1076 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1077 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1078 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1079 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1080 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1081 {
1082 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1083 .name = "Master Playback Volume",
1084 .info = snd_hda_mixer_amp_volume_info,
1085 .get = snd_hda_mixer_amp_volume_get,
1086 .put = cxt5047_hp_master_vol_put,
1087 .private_value = HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1088 },
1089 {
1090 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1091 .name = "Master Playback Switch",
1092 .info = cxt_eapd_info,
1093 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001094 .put = cxt5047_hp_master_sw_put,
1095 .private_value = 0x13,
1096 },
1097
1098 {}
1099};
1100
1101static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1102 {
1103 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1104 .name = "Capture Source",
1105 .info = conexant_mux_enum_info,
1106 .get = conexant_mux_enum_get,
1107 .put = conexant_mux_enum_put
1108 },
1109 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1110 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1111 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1112 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1113 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1114 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1115 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1116 {
1117 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1118 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001119 .info = cxt_eapd_info,
1120 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001121 .put = cxt5047_hp_master_sw_put,
1122 .private_value = 0x13,
1123 },
1124 { } /* end */
1125};
1126
1127static struct hda_verb cxt5047_init_verbs[] = {
1128 /* Line in, Mic, Built-in Mic */
1129 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1130 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1131 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis82f30042007-02-13 12:45:44 +01001132 /* HP, Amp, Speaker */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001133 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Tobin Davis82f30042007-02-13 12:45:44 +01001134 {0x1A, AC_VERB_SET_CONNECT_SEL,0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001135 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1136 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1137 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1138 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davis82f30042007-02-13 12:45:44 +01001139 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001140 /* Record selector: Front mic */
1141 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1142 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1143 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1144 /* SPDIF route: PCM */
1145 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001146 /* Enable unsolicited events */
1147 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1148 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001149 { } /* end */
1150};
1151
1152/* configuration for Toshiba Laptops */
1153static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1154 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1155 /* pin sensing on HP and Mic jacks */
1156 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1157 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001158 /* Speaker routing */
1159 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1160 /* Change default to ExtMic for recording */
1161 {0x1a, AC_VERB_SET_CONNECT_SEL,0x2},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001162 {}
1163};
1164
1165/* configuration for HP Laptops */
1166static struct hda_verb cxt5047_hp_init_verbs[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001167 /* pin sensing on HP jack */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001168 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001169 /* Record selector: Ext Mic */
1170 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1171 {0x1a, AC_VERB_SET_CONNECT_SEL,0x02},
1172 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1173 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1174 /* Speaker routing */
1175 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001176 {}
1177};
1178
1179/* Test configuration for debugging, modelled after the ALC260 test
1180 * configuration.
1181 */
1182#ifdef CONFIG_SND_DEBUG
1183static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001184 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001185 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001186 { "LINE1 pin", 0x0 },
1187 { "MIC1 pin", 0x1 },
1188 { "MIC2 pin", 0x2 },
1189 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001190 },
1191};
1192
1193static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1194
1195 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001196 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1197 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1198 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1199 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001200 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1201 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1202 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1203 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001204 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1205 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1206 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1207 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001208
1209 /* Modes for retasking pin widgets */
1210 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1211 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1212
Tobin Davis82f30042007-02-13 12:45:44 +01001213 /* EAPD Switch Control */
1214 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1215
Tobin Davisc9b443d2006-11-14 12:13:39 +01001216 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001217 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1218 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1219 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1220 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1221 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1222 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1223 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1224 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001225
Tobin Davis82f30042007-02-13 12:45:44 +01001226 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1227 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1228 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1229 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1230 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1231 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1232 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1233 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001234 {
1235 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1236 .name = "Input Source",
1237 .info = conexant_mux_enum_info,
1238 .get = conexant_mux_enum_get,
1239 .put = conexant_mux_enum_put,
1240 },
Tobin Davis82f30042007-02-13 12:45:44 +01001241 /* Controls for GPIO pins, assuming they exist and are configured
1242 * as outputs
1243 */
1244 CXT_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
1245 CXT_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
1246 CXT_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
1247 CXT_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001248
1249 { } /* end */
1250};
1251
1252static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001253 /* Enable retasking pins as output, initially without power amp */
1254 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1255 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1256 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1257
1258 /* Disable digital (SPDIF) pins initially, but users can enable
1259 * them via a mixer switch. In the case of SPDIF-out, this initverb
1260 * payload also sets the generation to 0, output to be in "consumer"
1261 * PCM format, copyright asserted, no pre-emphasis and no validity
1262 * control.
1263 */
1264 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1265
1266 /* Ensure mic1, mic2, line1 pin widgets take input from the
1267 * OUT1 sum bus when acting as an output.
1268 */
1269 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1270 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1271
1272 /* Start with output sum widgets muted and their output gains at min */
1273 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1274 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1275
1276 /* Unmute retasking pin widget output buffers since the default
1277 * state appears to be output. As the pin mode is changed by the
1278 * user the pin mode control will take care of enabling the pin's
1279 * input/output buffers as needed.
1280 */
1281 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1282 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1283 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1284
1285 /* Mute capture amp left and right */
1286 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1287
1288 /* Set ADC connection select to match default mixer setting (mic1
1289 * pin)
1290 */
1291 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1292
1293 /* Mute all inputs to mixer widget (even unconnected ones) */
1294 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1295 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1296 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1297 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1298 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1299 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1300 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1301 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1302
1303 { }
1304};
1305#endif
1306
1307
1308/* initialize jack-sensing, too */
1309static int cxt5047_hp_init(struct hda_codec *codec)
1310{
1311 conexant_init(codec);
1312 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001313 return 0;
1314}
1315
1316
1317enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001318 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1319 CXT5047_LAPTOP_HP, /* Some HP laptops */
1320 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001321#ifdef CONFIG_SND_DEBUG
1322 CXT5047_TEST,
1323#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001324 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001325};
1326
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001327static const char *cxt5047_models[CXT5047_MODELS] = {
1328 [CXT5047_LAPTOP] = "laptop",
1329 [CXT5047_LAPTOP_HP] = "laptop-hp",
1330 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001331#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001332 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001333#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001334};
1335
1336static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1337 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
1338 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
Tobin Davis82f30042007-02-13 12:45:44 +01001339 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001340 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1341 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001342 {}
1343};
1344
1345static int patch_cxt5047(struct hda_codec *codec)
1346{
1347 struct conexant_spec *spec;
1348 int board_config;
1349
1350 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1351 if (!spec)
1352 return -ENOMEM;
1353 mutex_init(&spec->amp_mutex);
1354 codec->spec = spec;
1355
1356 spec->multiout.max_channels = 2;
1357 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1358 spec->multiout.dac_nids = cxt5047_dac_nids;
1359 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1360 spec->num_adc_nids = 1;
1361 spec->adc_nids = cxt5047_adc_nids;
1362 spec->capsrc_nids = cxt5047_capsrc_nids;
1363 spec->input_mux = &cxt5047_capture_source;
1364 spec->num_mixers = 1;
1365 spec->mixers[0] = cxt5047_mixers;
1366 spec->num_init_verbs = 1;
1367 spec->init_verbs[0] = cxt5047_init_verbs;
1368 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001369 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1370 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001371
1372 codec->patch_ops = conexant_patch_ops;
1373 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1374
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001375 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1376 cxt5047_models,
1377 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001378 switch (board_config) {
1379 case CXT5047_LAPTOP:
1380 break;
1381 case CXT5047_LAPTOP_HP:
1382 spec->input_mux = &cxt5047_hp_capture_source;
1383 spec->num_init_verbs = 2;
1384 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1385 spec->mixers[0] = cxt5047_hp_mixers;
1386 codec->patch_ops.init = cxt5047_hp_init;
1387 break;
1388 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001389 spec->input_mux = &cxt5047_toshiba_capture_source;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001390 spec->num_init_verbs = 2;
1391 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davis82f30042007-02-13 12:45:44 +01001392 spec->mixers[0] = cxt5047_toshiba_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001393 break;
1394#ifdef CONFIG_SND_DEBUG
1395 case CXT5047_TEST:
1396 spec->input_mux = &cxt5047_test_capture_source;
1397 spec->mixers[0] = cxt5047_test_mixer;
1398 spec->init_verbs[0] = cxt5047_test_init_verbs;
1399#endif
1400 }
1401 return 0;
1402}
1403
1404struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001405 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1406 .patch = patch_cxt5045 },
1407 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1408 .patch = patch_cxt5047 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001409 {} /* terminator */
1410};