blob: 8b8de96df13863c6fde1daab747f78d26de19eb1 [file] [log] [blame]
Tobin Davisc9b443d2006-11-14 12:13:39 +01001/*
2 * HD audio interface patch for Conexant HDA audio codec
3 *
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
7 *
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
Tobin Davisc9b443d2006-11-14 12:13:39 +010023#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/slab.h>
26#include <linux/pci.h>
27#include <sound/core.h>
28#include "hda_codec.h"
29#include "hda_local.h"
30
31#define CXT_PIN_DIR_IN 0x00
32#define CXT_PIN_DIR_OUT 0x01
33#define CXT_PIN_DIR_INOUT 0x02
34#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
35#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
36
37#define CONEXANT_HP_EVENT 0x37
38#define CONEXANT_MIC_EVENT 0x38
39
40
41
42struct conexant_spec {
43
44 struct snd_kcontrol_new *mixers[5];
45 int num_mixers;
46
47 const struct hda_verb *init_verbs[5]; /* initialization verbs
48 * don't forget NULL
49 * termination!
50 */
51 unsigned int num_init_verbs;
52
53 /* playback */
54 struct hda_multi_out multiout; /* playback set-up
55 * max_channels, dacs must be set
56 * dig_out_nid and hp_nid are optional
57 */
58 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010059 unsigned int hp_present;
Tobin Davisc9b443d2006-11-14 12:13:39 +010060 unsigned int need_dac_fix;
61
62 /* capture */
63 unsigned int num_adc_nids;
64 hda_nid_t *adc_nids;
65 hda_nid_t dig_in_nid; /* digital-in NID; optional */
66
67 /* capture source */
68 const struct hda_input_mux *input_mux;
69 hda_nid_t *capsrc_nids;
70 unsigned int cur_mux[3];
71
72 /* channel model */
73 const struct hda_channel_mode *channel_mode;
74 int num_channel_mode;
75
76 /* PCM information */
77 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
78
79 struct mutex amp_mutex; /* PCM volume/mute control mutex */
80 unsigned int spdif_route;
81
82 /* dynamic controls, init_verbs and input_mux */
83 struct auto_pin_cfg autocfg;
84 unsigned int num_kctl_alloc, num_kctl_used;
85 struct snd_kcontrol_new *kctl_alloc;
86 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +020087 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Tobin Davisc9b443d2006-11-14 12:13:39 +010088
89};
90
91static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
92 struct hda_codec *codec,
93 struct snd_pcm_substream *substream)
94{
95 struct conexant_spec *spec = codec->spec;
96 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
97}
98
99static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
100 struct hda_codec *codec,
101 unsigned int stream_tag,
102 unsigned int format,
103 struct snd_pcm_substream *substream)
104{
105 struct conexant_spec *spec = codec->spec;
106 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
107 stream_tag,
108 format, substream);
109}
110
111static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
112 struct hda_codec *codec,
113 struct snd_pcm_substream *substream)
114{
115 struct conexant_spec *spec = codec->spec;
116 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
117}
118
119/*
120 * Digital out
121 */
122static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
123 struct hda_codec *codec,
124 struct snd_pcm_substream *substream)
125{
126 struct conexant_spec *spec = codec->spec;
127 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
128}
129
130static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
131 struct hda_codec *codec,
132 struct snd_pcm_substream *substream)
133{
134 struct conexant_spec *spec = codec->spec;
135 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
136}
137
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200138static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
139 struct hda_codec *codec,
140 unsigned int stream_tag,
141 unsigned int format,
142 struct snd_pcm_substream *substream)
143{
144 struct conexant_spec *spec = codec->spec;
145 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
146 stream_tag,
147 format, substream);
148}
149
Tobin Davisc9b443d2006-11-14 12:13:39 +0100150/*
151 * Analog capture
152 */
153static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
154 struct hda_codec *codec,
155 unsigned int stream_tag,
156 unsigned int format,
157 struct snd_pcm_substream *substream)
158{
159 struct conexant_spec *spec = codec->spec;
160 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
161 stream_tag, 0, format);
162 return 0;
163}
164
165static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
166 struct hda_codec *codec,
167 struct snd_pcm_substream *substream)
168{
169 struct conexant_spec *spec = codec->spec;
170 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
171 0, 0, 0);
172 return 0;
173}
174
175
176
177static struct hda_pcm_stream conexant_pcm_analog_playback = {
178 .substreams = 1,
179 .channels_min = 2,
180 .channels_max = 2,
181 .nid = 0, /* fill later */
182 .ops = {
183 .open = conexant_playback_pcm_open,
184 .prepare = conexant_playback_pcm_prepare,
185 .cleanup = conexant_playback_pcm_cleanup
186 },
187};
188
189static struct hda_pcm_stream conexant_pcm_analog_capture = {
190 .substreams = 1,
191 .channels_min = 2,
192 .channels_max = 2,
193 .nid = 0, /* fill later */
194 .ops = {
195 .prepare = conexant_capture_pcm_prepare,
196 .cleanup = conexant_capture_pcm_cleanup
197 },
198};
199
200
201static struct hda_pcm_stream conexant_pcm_digital_playback = {
202 .substreams = 1,
203 .channels_min = 2,
204 .channels_max = 2,
205 .nid = 0, /* fill later */
206 .ops = {
207 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200208 .close = conexant_dig_playback_pcm_close,
209 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100210 },
211};
212
213static struct hda_pcm_stream conexant_pcm_digital_capture = {
214 .substreams = 1,
215 .channels_min = 2,
216 .channels_max = 2,
217 /* NID is set in alc_build_pcms */
218};
219
220static int conexant_build_pcms(struct hda_codec *codec)
221{
222 struct conexant_spec *spec = codec->spec;
223 struct hda_pcm *info = spec->pcm_rec;
224
225 codec->num_pcms = 1;
226 codec->pcm_info = info;
227
228 info->name = "CONEXANT Analog";
229 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
230 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
231 spec->multiout.max_channels;
232 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
233 spec->multiout.dac_nids[0];
234 info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_analog_capture;
235 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
236 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
237
238 if (spec->multiout.dig_out_nid) {
239 info++;
240 codec->num_pcms++;
241 info->name = "Conexant Digital";
242 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
243 conexant_pcm_digital_playback;
244 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
245 spec->multiout.dig_out_nid;
246 if (spec->dig_in_nid) {
247 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
248 conexant_pcm_digital_capture;
249 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
250 spec->dig_in_nid;
251 }
252 }
253
254 return 0;
255}
256
257static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
258 struct snd_ctl_elem_info *uinfo)
259{
260 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
261 struct conexant_spec *spec = codec->spec;
262
263 return snd_hda_input_mux_info(spec->input_mux, uinfo);
264}
265
266static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
267 struct snd_ctl_elem_value *ucontrol)
268{
269 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
270 struct conexant_spec *spec = codec->spec;
271 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
272
273 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
274 return 0;
275}
276
277static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
278 struct snd_ctl_elem_value *ucontrol)
279{
280 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
281 struct conexant_spec *spec = codec->spec;
282 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
283
284 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
285 spec->capsrc_nids[adc_idx],
286 &spec->cur_mux[adc_idx]);
287}
288
289static int conexant_init(struct hda_codec *codec)
290{
291 struct conexant_spec *spec = codec->spec;
292 int i;
293
294 for (i = 0; i < spec->num_init_verbs; i++)
295 snd_hda_sequence_write(codec, spec->init_verbs[i]);
296 return 0;
297}
298
299static void conexant_free(struct hda_codec *codec)
300{
301 struct conexant_spec *spec = codec->spec;
302 unsigned int i;
303
304 if (spec->kctl_alloc) {
305 for (i = 0; i < spec->num_kctl_used; i++)
306 kfree(spec->kctl_alloc[i].name);
307 kfree(spec->kctl_alloc);
308 }
309
310 kfree(codec->spec);
311}
312
Tobin Davisc9b443d2006-11-14 12:13:39 +0100313static int conexant_build_controls(struct hda_codec *codec)
314{
315 struct conexant_spec *spec = codec->spec;
316 unsigned int i;
317 int err;
318
319 for (i = 0; i < spec->num_mixers; i++) {
320 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
321 if (err < 0)
322 return err;
323 }
324 if (spec->multiout.dig_out_nid) {
325 err = snd_hda_create_spdif_out_ctls(codec,
326 spec->multiout.dig_out_nid);
327 if (err < 0)
328 return err;
329 }
330 if (spec->dig_in_nid) {
331 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
332 if (err < 0)
333 return err;
334 }
335 return 0;
336}
337
338static struct hda_codec_ops conexant_patch_ops = {
339 .build_controls = conexant_build_controls,
340 .build_pcms = conexant_build_pcms,
341 .init = conexant_init,
342 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100343};
344
345/*
346 * EAPD control
347 * the private value = nid | (invert << 8)
348 */
349
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200350#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100351
Tobin Davis82f30042007-02-13 12:45:44 +0100352static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100353 struct snd_ctl_elem_value *ucontrol)
354{
355 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
356 struct conexant_spec *spec = codec->spec;
357 int invert = (kcontrol->private_value >> 8) & 1;
358 if (invert)
359 ucontrol->value.integer.value[0] = !spec->cur_eapd;
360 else
361 ucontrol->value.integer.value[0] = spec->cur_eapd;
362 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100363
Tobin Davisc9b443d2006-11-14 12:13:39 +0100364}
365
Tobin Davis82f30042007-02-13 12:45:44 +0100366static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100367 struct snd_ctl_elem_value *ucontrol)
368{
369 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
370 struct conexant_spec *spec = codec->spec;
371 int invert = (kcontrol->private_value >> 8) & 1;
372 hda_nid_t nid = kcontrol->private_value & 0xff;
373 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100374
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100375 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100376 if (invert)
377 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200378 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100379 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100380
Tobin Davisc9b443d2006-11-14 12:13:39 +0100381 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200382 snd_hda_codec_write_cache(codec, nid,
383 0, AC_VERB_SET_EAPD_BTLENABLE,
384 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100385 return 1;
386}
387
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100388/* controls for test mode */
389#ifdef CONFIG_SND_DEBUG
390
Tobin Davis82f30042007-02-13 12:45:44 +0100391#define CXT_EAPD_SWITCH(xname, nid, mask) \
392 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
393 .info = cxt_eapd_info, \
394 .get = cxt_eapd_get, \
395 .put = cxt_eapd_put, \
396 .private_value = nid | (mask<<16) }
397
398
399
Tobin Davisc9b443d2006-11-14 12:13:39 +0100400static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
401 struct snd_ctl_elem_info *uinfo)
402{
403 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
404 struct conexant_spec *spec = codec->spec;
405 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
406 spec->num_channel_mode);
407}
408
409static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
410 struct snd_ctl_elem_value *ucontrol)
411{
412 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
413 struct conexant_spec *spec = codec->spec;
414 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
415 spec->num_channel_mode,
416 spec->multiout.max_channels);
417}
418
419static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
420 struct snd_ctl_elem_value *ucontrol)
421{
422 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
423 struct conexant_spec *spec = codec->spec;
424 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
425 spec->num_channel_mode,
426 &spec->multiout.max_channels);
427 if (err >= 0 && spec->need_dac_fix)
428 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
429 return err;
430}
431
432#define CXT_PIN_MODE(xname, nid, dir) \
433 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
434 .info = conexant_ch_mode_info, \
435 .get = conexant_ch_mode_get, \
436 .put = conexant_ch_mode_put, \
437 .private_value = nid | (dir<<16) }
438
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100439#endif /* CONFIG_SND_DEBUG */
440
Tobin Davisc9b443d2006-11-14 12:13:39 +0100441/* Conexant 5045 specific */
442
443static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
444static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
445static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
446#define CXT5045_SPDIF_OUT 0x13
447
Tobin Davis5cd57522006-11-20 17:42:09 +0100448static struct hda_channel_mode cxt5045_modes[1] = {
449 { 2, NULL },
450};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100451
452static struct hda_input_mux cxt5045_capture_source = {
453 .num_items = 2,
454 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100455 { "IntMic", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100456 { "LineIn", 0x2 },
457 }
458};
459
460/* turn on/off EAPD (+ mute HP) as a master switch */
461static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
462 struct snd_ctl_elem_value *ucontrol)
463{
464 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
465 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100466 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100467
Tobin Davis82f30042007-02-13 12:45:44 +0100468 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100469 return 0;
470
Tobin Davis82f30042007-02-13 12:45:44 +0100471 /* toggle internal speakers mute depending of presence of
472 * the headphone jack
473 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200474 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
475 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
476 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100477
Takashi Iwai47fd8302007-08-10 17:11:07 +0200478 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
479 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
480 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100481 return 1;
482}
483
484/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200485static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
486 .ops = &snd_hda_bind_vol,
487 .values = {
488 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
489 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
490 0
491 },
492};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100493
Tobin Davis7f296732007-03-12 11:39:01 +0100494/* toggle input of built-in and mic jack appropriately */
495static void cxt5045_hp_automic(struct hda_codec *codec)
496{
497 static struct hda_verb mic_jack_on[] = {
498 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
499 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
500 {}
501 };
502 static struct hda_verb mic_jack_off[] = {
503 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
504 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
505 {}
506 };
507 unsigned int present;
508
509 present = snd_hda_codec_read(codec, 0x12, 0,
510 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
511 if (present)
512 snd_hda_sequence_write(codec, mic_jack_on);
513 else
514 snd_hda_sequence_write(codec, mic_jack_off);
515}
516
Tobin Davisc9b443d2006-11-14 12:13:39 +0100517
518/* mute internal speaker if HP is plugged */
519static void cxt5045_hp_automute(struct hda_codec *codec)
520{
Tobin Davis82f30042007-02-13 12:45:44 +0100521 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100522 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100523
Tobin Davis82f30042007-02-13 12:45:44 +0100524 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100525 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100526
Takashi Iwai47fd8302007-08-10 17:11:07 +0200527 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
528 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
529 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100530}
531
532/* unsolicited event for HP jack sensing */
533static void cxt5045_hp_unsol_event(struct hda_codec *codec,
534 unsigned int res)
535{
536 res >>= 26;
537 switch (res) {
538 case CONEXANT_HP_EVENT:
539 cxt5045_hp_automute(codec);
540 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100541 case CONEXANT_MIC_EVENT:
542 cxt5045_hp_automic(codec);
543 break;
544
Tobin Davisc9b443d2006-11-14 12:13:39 +0100545 }
546}
547
548static struct snd_kcontrol_new cxt5045_mixers[] = {
549 {
550 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
551 .name = "Capture Source",
552 .info = conexant_mux_enum_info,
553 .get = conexant_mux_enum_get,
554 .put = conexant_mux_enum_put
555 },
Takashi Iwaic8229c32007-10-19 08:06:21 +0200556 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
557 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
558 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
559 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
560 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
561 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
562 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
563 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
564 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
565 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200566 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100567 {
568 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
569 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100570 .info = cxt_eapd_info,
571 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100572 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100573 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100574 },
575
576 {}
577};
578
579static struct hda_verb cxt5045_init_verbs[] = {
580 /* Line in, Mic */
581 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
Tobin Davis7f296732007-03-12 11:39:01 +0100582 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100583 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200584 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
585 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
586 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
587 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
588 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
589 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
590 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
591 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
592 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100593 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100594 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100595 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100596 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
597 /* SPDIF route: PCM */
598 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100599 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100600 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100601 { } /* end */
602};
603
Tobin Davis7f296732007-03-12 11:39:01 +0100604
605static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
606 /* pin sensing on HP jack */
607 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200608 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100609};
610
611static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
612 /* pin sensing on HP jack */
613 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200614 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100615};
616
Tobin Davisc9b443d2006-11-14 12:13:39 +0100617#ifdef CONFIG_SND_DEBUG
618/* Test configuration for debugging, modelled after the ALC260 test
619 * configuration.
620 */
621static struct hda_input_mux cxt5045_test_capture_source = {
622 .num_items = 5,
623 .items = {
624 { "MIXER", 0x0 },
625 { "MIC1 pin", 0x1 },
626 { "LINE1 pin", 0x2 },
627 { "HP-OUT pin", 0x3 },
628 { "CD pin", 0x4 },
629 },
630};
631
632static struct snd_kcontrol_new cxt5045_test_mixer[] = {
633
634 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100635 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
636 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100637 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
638 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
639 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
640 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100641
642 /* Modes for retasking pin widgets */
643 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
644 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
645
Tobin Davis82f30042007-02-13 12:45:44 +0100646 /* EAPD Switch Control */
647 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
648
Tobin Davisc9b443d2006-11-14 12:13:39 +0100649 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100650
Tobin Davis7f296732007-03-12 11:39:01 +0100651 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
652 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
653 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
654 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
655 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
656 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
657 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
658 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
659 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
660 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100661 {
662 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
663 .name = "Input Source",
664 .info = conexant_mux_enum_info,
665 .get = conexant_mux_enum_get,
666 .put = conexant_mux_enum_put,
667 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200668 /* Audio input controls */
669 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
670 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
671 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
672 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
673 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
674 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
675 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
676 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
677 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
678 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100679 { } /* end */
680};
681
682static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100683 /* Set connections */
684 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
685 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
686 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100687 /* Enable retasking pins as output, initially without power amp */
688 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100689 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100690
691 /* Disable digital (SPDIF) pins initially, but users can enable
692 * them via a mixer switch. In the case of SPDIF-out, this initverb
693 * payload also sets the generation to 0, output to be in "consumer"
694 * PCM format, copyright asserted, no pre-emphasis and no validity
695 * control.
696 */
697 {0x13, AC_VERB_SET_DIGI_CONVERT_1, 0},
698
699 /* Start with output sum widgets muted and their output gains at min */
700 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
701 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
702
703 /* Unmute retasking pin widget output buffers since the default
704 * state appears to be output. As the pin mode is changed by the
705 * user the pin mode control will take care of enabling the pin's
706 * input/output buffers as needed.
707 */
708 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
709 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
710
711 /* Mute capture amp left and right */
712 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
713
714 /* Set ADC connection select to match default mixer setting (mic1
715 * pin)
716 */
717 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +0100718 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100719
720 /* Mute all inputs to mixer widget (even unconnected ones) */
721 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
722 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
723 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
724 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
725 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
726
727 { }
728};
729#endif
730
731
732/* initialize jack-sensing, too */
733static int cxt5045_init(struct hda_codec *codec)
734{
735 conexant_init(codec);
736 cxt5045_hp_automute(codec);
737 return 0;
738}
739
740
741enum {
Tobin Davis7f296732007-03-12 11:39:01 +0100742 CXT5045_LAPTOP, /* Laptops w/ EAPD support */
743 CXT5045_FUJITSU, /* Laptops w/ EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100744#ifdef CONFIG_SND_DEBUG
745 CXT5045_TEST,
746#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100747 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100748};
749
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100750static const char *cxt5045_models[CXT5045_MODELS] = {
751 [CXT5045_LAPTOP] = "laptop",
Tobin Davis7f296732007-03-12 11:39:01 +0100752 [CXT5045_FUJITSU] = "fujitsu",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100753#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100754 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100755#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100756};
757
758static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Tobin Davis4d69d752007-05-03 12:17:11 +0200759 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP),
760 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +0100761 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP),
762 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP),
Tobin Davis4d69d752007-05-03 12:17:11 +0200763 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP),
Takashi Iwai38f8b392008-01-08 17:19:22 +0100764 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP),
Claudio Matsuoka8481da52007-07-03 20:05:19 +0200765 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP),
Tobin Davis7f296732007-03-12 11:39:01 +0100766 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_FUJITSU),
Tobin Davisf8f794a2007-06-25 12:14:25 +0200767 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP),
Takashi Iwai61bae092007-10-22 17:05:35 +0200768 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP),
Tobin Davis7f296732007-03-12 11:39:01 +0100769 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100770 {}
771};
772
773static int patch_cxt5045(struct hda_codec *codec)
774{
775 struct conexant_spec *spec;
776 int board_config;
777
778 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
779 if (!spec)
780 return -ENOMEM;
781 mutex_init(&spec->amp_mutex);
782 codec->spec = spec;
783
784 spec->multiout.max_channels = 2;
785 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
786 spec->multiout.dac_nids = cxt5045_dac_nids;
787 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
788 spec->num_adc_nids = 1;
789 spec->adc_nids = cxt5045_adc_nids;
790 spec->capsrc_nids = cxt5045_capsrc_nids;
791 spec->input_mux = &cxt5045_capture_source;
792 spec->num_mixers = 1;
793 spec->mixers[0] = cxt5045_mixers;
794 spec->num_init_verbs = 1;
795 spec->init_verbs[0] = cxt5045_init_verbs;
796 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +0100797 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
798 spec->channel_mode = cxt5045_modes,
799
Tobin Davisc9b443d2006-11-14 12:13:39 +0100800
801 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100802
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100803 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
804 cxt5045_models,
805 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100806 switch (board_config) {
807 case CXT5045_LAPTOP:
Tobin Davis7f296732007-03-12 11:39:01 +0100808 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100809 spec->input_mux = &cxt5045_capture_source;
810 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +0100811 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
812 spec->mixers[0] = cxt5045_mixers;
813 codec->patch_ops.init = cxt5045_init;
814 break;
815 case CXT5045_FUJITSU:
816 spec->input_mux = &cxt5045_capture_source;
817 spec->num_init_verbs = 2;
818 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100819 spec->mixers[0] = cxt5045_mixers;
820 codec->patch_ops.init = cxt5045_init;
821 break;
822#ifdef CONFIG_SND_DEBUG
823 case CXT5045_TEST:
824 spec->input_mux = &cxt5045_test_capture_source;
825 spec->mixers[0] = cxt5045_test_mixer;
826 spec->init_verbs[0] = cxt5045_test_init_verbs;
827#endif
828 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +0100829
830 /*
831 * Fix max PCM level to 0 dB
832 * (originall it has 0x2b steps with 0dB offset 0x14)
833 */
834 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
835 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
836 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
837 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
838 (1 << AC_AMPCAP_MUTE_SHIFT));
839
Tobin Davisc9b443d2006-11-14 12:13:39 +0100840 return 0;
841}
842
843
844/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +0100845#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +0100846
Tobin Davis82f30042007-02-13 12:45:44 +0100847static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100848static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
849static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100850
Tobin Davis5cd57522006-11-20 17:42:09 +0100851static struct hda_channel_mode cxt5047_modes[1] = {
852 { 2, NULL },
853};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100854
855static struct hda_input_mux cxt5047_capture_source = {
Tobin Davis7f296732007-03-12 11:39:01 +0100856 .num_items = 1,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100857 .items = {
Tobin Davis7f296732007-03-12 11:39:01 +0100858 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100859 }
860};
861
862static struct hda_input_mux cxt5047_hp_capture_source = {
863 .num_items = 1,
864 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100865 { "ExtMic", 0x2 },
866 }
867};
868
869static struct hda_input_mux cxt5047_toshiba_capture_source = {
870 .num_items = 2,
871 .items = {
872 { "ExtMic", 0x2 },
873 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100874 }
875};
876
877/* turn on/off EAPD (+ mute HP) as a master switch */
878static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
879 struct snd_ctl_elem_value *ucontrol)
880{
881 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
882 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100883 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100884
Tobin Davis82f30042007-02-13 12:45:44 +0100885 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100886 return 0;
887
Tobin Davis82f30042007-02-13 12:45:44 +0100888 /* toggle internal speakers mute depending of presence of
889 * the headphone jack
890 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200891 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
892 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
893 HDA_AMP_MUTE, bits);
894 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
895 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
896 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100897 return 1;
898}
899
Tobin Davis82f30042007-02-13 12:45:44 +0100900/* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200901static struct hda_bind_ctls cxt5047_bind_master_vol = {
902 .ops = &snd_hda_bind_vol,
903 .values = {
904 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
905 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
906 0
907 },
908};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100909
910/* mute internal speaker if HP is plugged */
911static void cxt5047_hp_automute(struct hda_codec *codec)
912{
Tobin Davis82f30042007-02-13 12:45:44 +0100913 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100914 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100915
Tobin Davis82f30042007-02-13 12:45:44 +0100916 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100917 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100918
Takashi Iwai47fd8302007-08-10 17:11:07 +0200919 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
920 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
921 HDA_AMP_MUTE, bits);
Tobin Davis82f30042007-02-13 12:45:44 +0100922 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200923 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
924 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100925}
926
Tobin Davisfb3409e2007-05-17 09:40:47 +0200927/* mute internal speaker if HP is plugged */
928static void cxt5047_hp2_automute(struct hda_codec *codec)
929{
930 struct conexant_spec *spec = codec->spec;
931 unsigned int bits;
932
933 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
934 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
935
Takashi Iwai47fd8302007-08-10 17:11:07 +0200936 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
937 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
938 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +0200939 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200940 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
941 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +0200942}
943
Tobin Davisc9b443d2006-11-14 12:13:39 +0100944/* toggle input of built-in and mic jack appropriately */
945static void cxt5047_hp_automic(struct hda_codec *codec)
946{
947 static struct hda_verb mic_jack_on[] = {
948 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
949 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
950 {}
951 };
952 static struct hda_verb mic_jack_off[] = {
953 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
954 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
955 {}
956 };
957 unsigned int present;
958
Tobin Davis7f296732007-03-12 11:39:01 +0100959 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100960 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
961 if (present)
962 snd_hda_sequence_write(codec, mic_jack_on);
963 else
964 snd_hda_sequence_write(codec, mic_jack_off);
965}
966
967/* unsolicited event for HP jack sensing */
968static void cxt5047_hp_unsol_event(struct hda_codec *codec,
969 unsigned int res)
970{
971 res >>= 26;
972 switch (res) {
973 case CONEXANT_HP_EVENT:
974 cxt5047_hp_automute(codec);
975 break;
976 case CONEXANT_MIC_EVENT:
977 cxt5047_hp_automic(codec);
978 break;
979 }
980}
981
Tobin Davisfb3409e2007-05-17 09:40:47 +0200982/* unsolicited event for HP jack sensing - non-EAPD systems */
983static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
984 unsigned int res)
985{
986 res >>= 26;
987 switch (res) {
988 case CONEXANT_HP_EVENT:
989 cxt5047_hp2_automute(codec);
990 break;
991 case CONEXANT_MIC_EVENT:
992 cxt5047_hp_automic(codec);
993 break;
994 }
995}
996
Tobin Davisc9b443d2006-11-14 12:13:39 +0100997static struct snd_kcontrol_new cxt5047_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100998 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
999 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001000 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1001 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001002 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1003 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1004 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1005 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001006 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1007 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
Tobin Davisb7589ce2007-04-24 17:56:55 +02001008 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1009 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1010 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1011 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001012
1013 {}
1014};
1015
1016static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1017 {
1018 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1019 .name = "Capture Source",
1020 .info = conexant_mux_enum_info,
1021 .get = conexant_mux_enum_get,
1022 .put = conexant_mux_enum_put
1023 },
1024 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1025 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1026 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1027 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1028 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1029 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +02001030 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
Tobin Davis82f30042007-02-13 12:45:44 +01001031 {
1032 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1033 .name = "Master Playback Switch",
1034 .info = cxt_eapd_info,
1035 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001036 .put = cxt5047_hp_master_sw_put,
1037 .private_value = 0x13,
1038 },
1039
1040 {}
1041};
1042
1043static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1044 {
1045 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1046 .name = "Capture Source",
1047 .info = conexant_mux_enum_info,
1048 .get = conexant_mux_enum_get,
1049 .put = conexant_mux_enum_put
1050 },
1051 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1052 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1053 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1054 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1055 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1056 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1057 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1058 {
1059 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1060 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001061 .info = cxt_eapd_info,
1062 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001063 .put = cxt5047_hp_master_sw_put,
1064 .private_value = 0x13,
1065 },
1066 { } /* end */
1067};
1068
1069static struct hda_verb cxt5047_init_verbs[] = {
1070 /* Line in, Mic, Built-in Mic */
1071 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1072 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1073 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001074 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001075 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1076 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis7f296732007-03-12 11:39:01 +01001077 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1078 /* Record selector: Mic */
1079 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1080 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1081 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1082 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001083 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1084 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1085 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1086 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001087 /* SPDIF route: PCM */
1088 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001089 /* Enable unsolicited events */
1090 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1091 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001092 { } /* end */
1093};
1094
1095/* configuration for Toshiba Laptops */
1096static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1097 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1098 /* pin sensing on HP and Mic jacks */
1099 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1100 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001101 /* Speaker routing */
1102 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001103 {}
1104};
1105
1106/* configuration for HP Laptops */
1107static struct hda_verb cxt5047_hp_init_verbs[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001108 /* pin sensing on HP jack */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001109 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001110 /* Record selector: Ext Mic */
1111 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
Tobin Davis82f30042007-02-13 12:45:44 +01001112 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1113 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1114 /* Speaker routing */
1115 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001116 {}
1117};
1118
1119/* Test configuration for debugging, modelled after the ALC260 test
1120 * configuration.
1121 */
1122#ifdef CONFIG_SND_DEBUG
1123static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001124 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001125 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001126 { "LINE1 pin", 0x0 },
1127 { "MIC1 pin", 0x1 },
1128 { "MIC2 pin", 0x2 },
1129 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001130 },
1131};
1132
1133static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1134
1135 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001136 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1137 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1138 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1139 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001140 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1141 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1142 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1143 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001144 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1145 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1146 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1147 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001148
1149 /* Modes for retasking pin widgets */
1150 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1151 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1152
Tobin Davis82f30042007-02-13 12:45:44 +01001153 /* EAPD Switch Control */
1154 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1155
Tobin Davisc9b443d2006-11-14 12:13:39 +01001156 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001157 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1158 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1159 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1160 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1161 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1162 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1163 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1164 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001165
Tobin Davis82f30042007-02-13 12:45:44 +01001166 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1167 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1168 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1169 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1170 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1171 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1172 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1173 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001174 {
1175 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1176 .name = "Input Source",
1177 .info = conexant_mux_enum_info,
1178 .get = conexant_mux_enum_get,
1179 .put = conexant_mux_enum_put,
1180 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001181 { } /* end */
1182};
1183
1184static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001185 /* Enable retasking pins as output, initially without power amp */
1186 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1187 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1188 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1189
1190 /* Disable digital (SPDIF) pins initially, but users can enable
1191 * them via a mixer switch. In the case of SPDIF-out, this initverb
1192 * payload also sets the generation to 0, output to be in "consumer"
1193 * PCM format, copyright asserted, no pre-emphasis and no validity
1194 * control.
1195 */
1196 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1197
1198 /* Ensure mic1, mic2, line1 pin widgets take input from the
1199 * OUT1 sum bus when acting as an output.
1200 */
1201 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1202 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1203
1204 /* Start with output sum widgets muted and their output gains at min */
1205 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1206 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1207
1208 /* Unmute retasking pin widget output buffers since the default
1209 * state appears to be output. As the pin mode is changed by the
1210 * user the pin mode control will take care of enabling the pin's
1211 * input/output buffers as needed.
1212 */
1213 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1214 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1215 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1216
1217 /* Mute capture amp left and right */
1218 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1219
1220 /* Set ADC connection select to match default mixer setting (mic1
1221 * pin)
1222 */
1223 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1224
1225 /* Mute all inputs to mixer widget (even unconnected ones) */
1226 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1227 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1228 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1229 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1230 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1231 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1232 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1233 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1234
1235 { }
1236};
1237#endif
1238
1239
1240/* initialize jack-sensing, too */
1241static int cxt5047_hp_init(struct hda_codec *codec)
1242{
1243 conexant_init(codec);
1244 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001245 return 0;
1246}
1247
1248
1249enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001250 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1251 CXT5047_LAPTOP_HP, /* Some HP laptops */
1252 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001253#ifdef CONFIG_SND_DEBUG
1254 CXT5047_TEST,
1255#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001256 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001257};
1258
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001259static const char *cxt5047_models[CXT5047_MODELS] = {
1260 [CXT5047_LAPTOP] = "laptop",
1261 [CXT5047_LAPTOP_HP] = "laptop-hp",
1262 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001263#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001264 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001265#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001266};
1267
1268static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1269 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001270 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001271 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
Tobin Davis82f30042007-02-13 12:45:44 +01001272 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001273 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001274 {}
1275};
1276
1277static int patch_cxt5047(struct hda_codec *codec)
1278{
1279 struct conexant_spec *spec;
1280 int board_config;
1281
1282 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1283 if (!spec)
1284 return -ENOMEM;
1285 mutex_init(&spec->amp_mutex);
1286 codec->spec = spec;
1287
1288 spec->multiout.max_channels = 2;
1289 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1290 spec->multiout.dac_nids = cxt5047_dac_nids;
1291 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1292 spec->num_adc_nids = 1;
1293 spec->adc_nids = cxt5047_adc_nids;
1294 spec->capsrc_nids = cxt5047_capsrc_nids;
1295 spec->input_mux = &cxt5047_capture_source;
1296 spec->num_mixers = 1;
1297 spec->mixers[0] = cxt5047_mixers;
1298 spec->num_init_verbs = 1;
1299 spec->init_verbs[0] = cxt5047_init_verbs;
1300 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001301 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1302 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001303
1304 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001305
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001306 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1307 cxt5047_models,
1308 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001309 switch (board_config) {
1310 case CXT5047_LAPTOP:
Tobin Davisfb3409e2007-05-17 09:40:47 +02001311 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001312 break;
1313 case CXT5047_LAPTOP_HP:
1314 spec->input_mux = &cxt5047_hp_capture_source;
1315 spec->num_init_verbs = 2;
1316 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1317 spec->mixers[0] = cxt5047_hp_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001318 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001319 codec->patch_ops.init = cxt5047_hp_init;
1320 break;
1321 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001322 spec->input_mux = &cxt5047_toshiba_capture_source;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001323 spec->num_init_verbs = 2;
1324 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davis82f30042007-02-13 12:45:44 +01001325 spec->mixers[0] = cxt5047_toshiba_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001326 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001327 break;
1328#ifdef CONFIG_SND_DEBUG
1329 case CXT5047_TEST:
1330 spec->input_mux = &cxt5047_test_capture_source;
1331 spec->mixers[0] = cxt5047_test_mixer;
1332 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001333 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001334#endif
1335 }
1336 return 0;
1337}
1338
1339struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001340 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1341 .patch = patch_cxt5045 },
1342 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1343 .patch = patch_cxt5047 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001344 {} /* terminator */
1345};