blob: ea3559fe332804b1c7afd3bf007610dc841d6a06 [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 },
Jiang zhef4beee92008-01-17 11:19:26 +0100456 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100457 }
458};
459
Jiang Zhe5218c892008-01-17 11:18:41 +0100460static struct hda_input_mux cxt5045_capture_source_benq = {
461 .num_items = 3,
462 .items = {
463 { "IntMic", 0x1 },
464 { "ExtMic", 0x2 },
465 { "LineIn", 0x3 },
466 }
467};
468
Tobin Davisc9b443d2006-11-14 12:13:39 +0100469/* turn on/off EAPD (+ mute HP) as a master switch */
470static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
471 struct snd_ctl_elem_value *ucontrol)
472{
473 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
474 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100475 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100476
Tobin Davis82f30042007-02-13 12:45:44 +0100477 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100478 return 0;
479
Tobin Davis82f30042007-02-13 12:45:44 +0100480 /* toggle internal speakers mute depending of presence of
481 * the headphone jack
482 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200483 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
484 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
485 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100486
Takashi Iwai47fd8302007-08-10 17:11:07 +0200487 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
488 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
489 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100490 return 1;
491}
492
493/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200494static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
495 .ops = &snd_hda_bind_vol,
496 .values = {
497 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
498 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
499 0
500 },
501};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100502
Tobin Davis7f296732007-03-12 11:39:01 +0100503/* toggle input of built-in and mic jack appropriately */
504static void cxt5045_hp_automic(struct hda_codec *codec)
505{
506 static struct hda_verb mic_jack_on[] = {
507 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
508 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
509 {}
510 };
511 static struct hda_verb mic_jack_off[] = {
512 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
513 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
514 {}
515 };
516 unsigned int present;
517
518 present = snd_hda_codec_read(codec, 0x12, 0,
519 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
520 if (present)
521 snd_hda_sequence_write(codec, mic_jack_on);
522 else
523 snd_hda_sequence_write(codec, mic_jack_off);
524}
525
Tobin Davisc9b443d2006-11-14 12:13:39 +0100526
527/* mute internal speaker if HP is plugged */
528static void cxt5045_hp_automute(struct hda_codec *codec)
529{
Tobin Davis82f30042007-02-13 12:45:44 +0100530 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100531 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100532
Tobin Davis82f30042007-02-13 12:45:44 +0100533 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100534 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100535
Takashi Iwai47fd8302007-08-10 17:11:07 +0200536 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
537 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
538 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100539}
540
541/* unsolicited event for HP jack sensing */
542static void cxt5045_hp_unsol_event(struct hda_codec *codec,
543 unsigned int res)
544{
545 res >>= 26;
546 switch (res) {
547 case CONEXANT_HP_EVENT:
548 cxt5045_hp_automute(codec);
549 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100550 case CONEXANT_MIC_EVENT:
551 cxt5045_hp_automic(codec);
552 break;
553
Tobin Davisc9b443d2006-11-14 12:13:39 +0100554 }
555}
556
557static struct snd_kcontrol_new cxt5045_mixers[] = {
558 {
559 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
560 .name = "Capture Source",
561 .info = conexant_mux_enum_info,
562 .get = conexant_mux_enum_get,
563 .put = conexant_mux_enum_put
564 },
Takashi Iwaic8229c32007-10-19 08:06:21 +0200565 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
566 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
567 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
568 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
569 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
570 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
571 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
572 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
573 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
574 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200575 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100576 {
577 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
578 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100579 .info = cxt_eapd_info,
580 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100581 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100582 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100583 },
584
585 {}
586};
587
Jiang Zhe5218c892008-01-17 11:18:41 +0100588static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
589 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
590 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
591 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
592 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
593
594 {}
595};
596
Tobin Davisc9b443d2006-11-14 12:13:39 +0100597static struct hda_verb cxt5045_init_verbs[] = {
598 /* Line in, Mic */
599 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
Tobin Davis7f296732007-03-12 11:39:01 +0100600 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100601 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200602 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
603 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
604 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
605 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
606 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
607 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
608 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
609 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
610 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100611 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100612 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100613 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100614 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
615 /* SPDIF route: PCM */
616 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100617 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100618 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100619 { } /* end */
620};
621
Jiang Zhe5218c892008-01-17 11:18:41 +0100622static struct hda_verb cxt5045_benq_init_verbs[] = {
623 /* Int Mic, Mic */
624 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
625 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
626 /* Line In,HP, Amp */
627 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
628 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
629 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
630 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
631 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
632 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
633 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
634 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
635 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
636 /* Record selector: Int mic */
637 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
638 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
639 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
640 /* SPDIF route: PCM */
641 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
642 /* EAPD */
643 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
644 { } /* end */
645};
Tobin Davis7f296732007-03-12 11:39:01 +0100646
647static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
648 /* pin sensing on HP jack */
649 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200650 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100651};
652
653static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
654 /* pin sensing on HP jack */
655 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200656 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100657};
658
Tobin Davisc9b443d2006-11-14 12:13:39 +0100659#ifdef CONFIG_SND_DEBUG
660/* Test configuration for debugging, modelled after the ALC260 test
661 * configuration.
662 */
663static struct hda_input_mux cxt5045_test_capture_source = {
664 .num_items = 5,
665 .items = {
666 { "MIXER", 0x0 },
667 { "MIC1 pin", 0x1 },
668 { "LINE1 pin", 0x2 },
669 { "HP-OUT pin", 0x3 },
670 { "CD pin", 0x4 },
671 },
672};
673
674static struct snd_kcontrol_new cxt5045_test_mixer[] = {
675
676 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100677 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
678 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100679 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
680 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
681 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
682 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100683
684 /* Modes for retasking pin widgets */
685 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
686 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
687
Tobin Davis82f30042007-02-13 12:45:44 +0100688 /* EAPD Switch Control */
689 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
690
Tobin Davisc9b443d2006-11-14 12:13:39 +0100691 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100692
Tobin Davis7f296732007-03-12 11:39:01 +0100693 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
694 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
695 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
696 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
697 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
698 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
699 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
700 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
701 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
702 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100703 {
704 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
705 .name = "Input Source",
706 .info = conexant_mux_enum_info,
707 .get = conexant_mux_enum_get,
708 .put = conexant_mux_enum_put,
709 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200710 /* Audio input controls */
711 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
712 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
713 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
714 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
715 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
716 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
717 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
718 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
719 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
720 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100721 { } /* end */
722};
723
724static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100725 /* Set connections */
726 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
727 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
728 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100729 /* Enable retasking pins as output, initially without power amp */
730 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100731 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100732
733 /* Disable digital (SPDIF) pins initially, but users can enable
734 * them via a mixer switch. In the case of SPDIF-out, this initverb
735 * payload also sets the generation to 0, output to be in "consumer"
736 * PCM format, copyright asserted, no pre-emphasis and no validity
737 * control.
738 */
739 {0x13, AC_VERB_SET_DIGI_CONVERT_1, 0},
740
741 /* Start with output sum widgets muted and their output gains at min */
742 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
743 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
744
745 /* Unmute retasking pin widget output buffers since the default
746 * state appears to be output. As the pin mode is changed by the
747 * user the pin mode control will take care of enabling the pin's
748 * input/output buffers as needed.
749 */
750 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
751 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
752
753 /* Mute capture amp left and right */
754 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
755
756 /* Set ADC connection select to match default mixer setting (mic1
757 * pin)
758 */
759 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +0100760 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100761
762 /* Mute all inputs to mixer widget (even unconnected ones) */
763 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
764 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
765 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
766 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
767 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
768
769 { }
770};
771#endif
772
773
774/* initialize jack-sensing, too */
775static int cxt5045_init(struct hda_codec *codec)
776{
777 conexant_init(codec);
778 cxt5045_hp_automute(codec);
779 return 0;
780}
781
782
783enum {
Marc Boucher15908c32008-01-22 15:15:59 +0100784 CXT5045_LAPTOP_HPSENSE,
785 CXT5045_LAPTOP_MICSENSE,
786 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +0100787 CXT5045_BENQ,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100788#ifdef CONFIG_SND_DEBUG
789 CXT5045_TEST,
790#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100791 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100792};
793
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100794static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +0100795 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
796 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
797 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
798 [CXT5045_BENQ] = "benq",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100799#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100800 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100801#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100802};
803
804static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Marc Boucher15908c32008-01-22 15:15:59 +0100805 SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
806 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
807 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
808 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
809 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
810 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
811 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HPSENSE),
812 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +0100813 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +0100814 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
815 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
816 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP_HPSENSE),
817 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
818 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
819 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
820 SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
821 SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
822 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100823 {}
824};
825
826static int patch_cxt5045(struct hda_codec *codec)
827{
828 struct conexant_spec *spec;
829 int board_config;
830
831 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
832 if (!spec)
833 return -ENOMEM;
834 mutex_init(&spec->amp_mutex);
835 codec->spec = spec;
836
837 spec->multiout.max_channels = 2;
838 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
839 spec->multiout.dac_nids = cxt5045_dac_nids;
840 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
841 spec->num_adc_nids = 1;
842 spec->adc_nids = cxt5045_adc_nids;
843 spec->capsrc_nids = cxt5045_capsrc_nids;
844 spec->input_mux = &cxt5045_capture_source;
845 spec->num_mixers = 1;
846 spec->mixers[0] = cxt5045_mixers;
847 spec->num_init_verbs = 1;
848 spec->init_verbs[0] = cxt5045_init_verbs;
849 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +0100850 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
851 spec->channel_mode = cxt5045_modes,
852
Tobin Davisc9b443d2006-11-14 12:13:39 +0100853
854 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100855
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100856 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
857 cxt5045_models,
858 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100859 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +0100860 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +0100861 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100862 spec->input_mux = &cxt5045_capture_source;
863 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +0100864 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
865 spec->mixers[0] = cxt5045_mixers;
866 codec->patch_ops.init = cxt5045_init;
867 break;
Marc Boucher15908c32008-01-22 15:15:59 +0100868 case CXT5045_LAPTOP_MICSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +0100869 spec->input_mux = &cxt5045_capture_source;
870 spec->num_init_verbs = 2;
871 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100872 spec->mixers[0] = cxt5045_mixers;
873 codec->patch_ops.init = cxt5045_init;
874 break;
Marc Boucher15908c32008-01-22 15:15:59 +0100875 default:
876 case CXT5045_LAPTOP_HPMICSENSE:
877 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
878 spec->input_mux = &cxt5045_capture_source;
879 spec->num_init_verbs = 3;
880 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
881 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
882 spec->mixers[0] = cxt5045_mixers;
883 codec->patch_ops.init = cxt5045_init;
884 break;
Jiang Zhe5218c892008-01-17 11:18:41 +0100885 case CXT5045_BENQ:
886 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
887 spec->input_mux = &cxt5045_capture_source_benq;
888 spec->num_init_verbs = 1;
889 spec->init_verbs[0] = cxt5045_benq_init_verbs;
890 spec->mixers[0] = cxt5045_mixers;
891 spec->mixers[1] = cxt5045_benq_mixers;
892 spec->num_mixers = 2;
893 codec->patch_ops.init = cxt5045_init;
894 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100895#ifdef CONFIG_SND_DEBUG
896 case CXT5045_TEST:
897 spec->input_mux = &cxt5045_test_capture_source;
898 spec->mixers[0] = cxt5045_test_mixer;
899 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +0100900 break;
901
Tobin Davisc9b443d2006-11-14 12:13:39 +0100902#endif
903 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +0100904
905 /*
906 * Fix max PCM level to 0 dB
907 * (originall it has 0x2b steps with 0dB offset 0x14)
908 */
909 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
910 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
911 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
912 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
913 (1 << AC_AMPCAP_MUTE_SHIFT));
914
Tobin Davisc9b443d2006-11-14 12:13:39 +0100915 return 0;
916}
917
918
919/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +0100920#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +0100921
Tobin Davis82f30042007-02-13 12:45:44 +0100922static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100923static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
924static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100925
Tobin Davis5cd57522006-11-20 17:42:09 +0100926static struct hda_channel_mode cxt5047_modes[1] = {
927 { 2, NULL },
928};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100929
930static struct hda_input_mux cxt5047_capture_source = {
Tobin Davis7f296732007-03-12 11:39:01 +0100931 .num_items = 1,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100932 .items = {
Tobin Davis7f296732007-03-12 11:39:01 +0100933 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100934 }
935};
936
937static struct hda_input_mux cxt5047_hp_capture_source = {
938 .num_items = 1,
939 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100940 { "ExtMic", 0x2 },
941 }
942};
943
944static struct hda_input_mux cxt5047_toshiba_capture_source = {
945 .num_items = 2,
946 .items = {
947 { "ExtMic", 0x2 },
948 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100949 }
950};
951
952/* turn on/off EAPD (+ mute HP) as a master switch */
953static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
954 struct snd_ctl_elem_value *ucontrol)
955{
956 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
957 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100958 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100959
Tobin Davis82f30042007-02-13 12:45:44 +0100960 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100961 return 0;
962
Tobin Davis82f30042007-02-13 12:45:44 +0100963 /* toggle internal speakers mute depending of presence of
964 * the headphone jack
965 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200966 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
967 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
968 HDA_AMP_MUTE, bits);
969 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
970 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
971 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100972 return 1;
973}
974
Tobin Davis82f30042007-02-13 12:45:44 +0100975/* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200976static struct hda_bind_ctls cxt5047_bind_master_vol = {
977 .ops = &snd_hda_bind_vol,
978 .values = {
979 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
980 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
981 0
982 },
983};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100984
985/* mute internal speaker if HP is plugged */
986static void cxt5047_hp_automute(struct hda_codec *codec)
987{
Tobin Davis82f30042007-02-13 12:45:44 +0100988 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100989 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100990
Tobin Davis82f30042007-02-13 12:45:44 +0100991 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100992 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100993
Takashi Iwai47fd8302007-08-10 17:11:07 +0200994 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
995 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
996 HDA_AMP_MUTE, bits);
Tobin Davis82f30042007-02-13 12:45:44 +0100997 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200998 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
999 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001000}
1001
Tobin Davisfb3409e2007-05-17 09:40:47 +02001002/* mute internal speaker if HP is plugged */
1003static void cxt5047_hp2_automute(struct hda_codec *codec)
1004{
1005 struct conexant_spec *spec = codec->spec;
1006 unsigned int bits;
1007
1008 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1009 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1010
Takashi Iwai47fd8302007-08-10 17:11:07 +02001011 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1012 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1013 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001014 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001015 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1016 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001017}
1018
Tobin Davisc9b443d2006-11-14 12:13:39 +01001019/* toggle input of built-in and mic jack appropriately */
1020static void cxt5047_hp_automic(struct hda_codec *codec)
1021{
1022 static struct hda_verb mic_jack_on[] = {
1023 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1024 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1025 {}
1026 };
1027 static struct hda_verb mic_jack_off[] = {
1028 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1029 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1030 {}
1031 };
1032 unsigned int present;
1033
Tobin Davis7f296732007-03-12 11:39:01 +01001034 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001035 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1036 if (present)
1037 snd_hda_sequence_write(codec, mic_jack_on);
1038 else
1039 snd_hda_sequence_write(codec, mic_jack_off);
1040}
1041
1042/* unsolicited event for HP jack sensing */
1043static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1044 unsigned int res)
1045{
1046 res >>= 26;
1047 switch (res) {
1048 case CONEXANT_HP_EVENT:
1049 cxt5047_hp_automute(codec);
1050 break;
1051 case CONEXANT_MIC_EVENT:
1052 cxt5047_hp_automic(codec);
1053 break;
1054 }
1055}
1056
Tobin Davisfb3409e2007-05-17 09:40:47 +02001057/* unsolicited event for HP jack sensing - non-EAPD systems */
1058static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1059 unsigned int res)
1060{
1061 res >>= 26;
1062 switch (res) {
1063 case CONEXANT_HP_EVENT:
1064 cxt5047_hp2_automute(codec);
1065 break;
1066 case CONEXANT_MIC_EVENT:
1067 cxt5047_hp_automic(codec);
1068 break;
1069 }
1070}
1071
Tobin Davisc9b443d2006-11-14 12:13:39 +01001072static struct snd_kcontrol_new cxt5047_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001073 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1074 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001075 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1076 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001077 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),
Tobin Davis82f30042007-02-13 12:45:44 +01001081 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1082 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
Tobin Davisb7589ce2007-04-24 17:56:55 +02001083 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1084 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1085 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1086 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001087
1088 {}
1089};
1090
1091static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1092 {
1093 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1094 .name = "Capture Source",
1095 .info = conexant_mux_enum_info,
1096 .get = conexant_mux_enum_get,
1097 .put = conexant_mux_enum_put
1098 },
1099 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1100 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1101 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1102 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1103 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1104 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +02001105 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
Tobin Davis82f30042007-02-13 12:45:44 +01001106 {
1107 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1108 .name = "Master Playback Switch",
1109 .info = cxt_eapd_info,
1110 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001111 .put = cxt5047_hp_master_sw_put,
1112 .private_value = 0x13,
1113 },
1114
1115 {}
1116};
1117
1118static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1119 {
1120 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1121 .name = "Capture Source",
1122 .info = conexant_mux_enum_info,
1123 .get = conexant_mux_enum_get,
1124 .put = conexant_mux_enum_put
1125 },
1126 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1127 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1128 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1129 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1130 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1131 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1132 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1133 {
1134 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1135 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001136 .info = cxt_eapd_info,
1137 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001138 .put = cxt5047_hp_master_sw_put,
1139 .private_value = 0x13,
1140 },
1141 { } /* end */
1142};
1143
1144static struct hda_verb cxt5047_init_verbs[] = {
1145 /* Line in, Mic, Built-in Mic */
1146 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1147 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1148 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001149 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001150 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1151 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis7f296732007-03-12 11:39:01 +01001152 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1153 /* Record selector: Mic */
1154 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1155 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1156 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1157 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001158 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1159 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1160 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1161 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001162 /* SPDIF route: PCM */
1163 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001164 /* Enable unsolicited events */
1165 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1166 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001167 { } /* end */
1168};
1169
1170/* configuration for Toshiba Laptops */
1171static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1172 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1173 /* pin sensing on HP and Mic jacks */
1174 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1175 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001176 /* Speaker routing */
1177 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001178 {}
1179};
1180
1181/* configuration for HP Laptops */
1182static struct hda_verb cxt5047_hp_init_verbs[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001183 /* pin sensing on HP jack */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001184 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001185 /* Record selector: Ext Mic */
1186 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
Tobin Davis82f30042007-02-13 12:45:44 +01001187 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1188 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1189 /* Speaker routing */
1190 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001191 {}
1192};
1193
1194/* Test configuration for debugging, modelled after the ALC260 test
1195 * configuration.
1196 */
1197#ifdef CONFIG_SND_DEBUG
1198static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001199 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001200 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001201 { "LINE1 pin", 0x0 },
1202 { "MIC1 pin", 0x1 },
1203 { "MIC2 pin", 0x2 },
1204 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001205 },
1206};
1207
1208static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1209
1210 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001211 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1212 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1213 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1214 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001215 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1216 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1217 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1218 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001219 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1220 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1221 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1222 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001223
1224 /* Modes for retasking pin widgets */
1225 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1226 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1227
Tobin Davis82f30042007-02-13 12:45:44 +01001228 /* EAPD Switch Control */
1229 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1230
Tobin Davisc9b443d2006-11-14 12:13:39 +01001231 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001232 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1233 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1234 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1235 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1236 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1237 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1238 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1239 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001240
Tobin Davis82f30042007-02-13 12:45:44 +01001241 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1242 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1243 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1244 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1245 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1246 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1247 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1248 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001249 {
1250 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1251 .name = "Input Source",
1252 .info = conexant_mux_enum_info,
1253 .get = conexant_mux_enum_get,
1254 .put = conexant_mux_enum_put,
1255 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001256 { } /* end */
1257};
1258
1259static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001260 /* Enable retasking pins as output, initially without power amp */
1261 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1262 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1263 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1264
1265 /* Disable digital (SPDIF) pins initially, but users can enable
1266 * them via a mixer switch. In the case of SPDIF-out, this initverb
1267 * payload also sets the generation to 0, output to be in "consumer"
1268 * PCM format, copyright asserted, no pre-emphasis and no validity
1269 * control.
1270 */
1271 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1272
1273 /* Ensure mic1, mic2, line1 pin widgets take input from the
1274 * OUT1 sum bus when acting as an output.
1275 */
1276 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1277 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1278
1279 /* Start with output sum widgets muted and their output gains at min */
1280 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1281 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1282
1283 /* Unmute retasking pin widget output buffers since the default
1284 * state appears to be output. As the pin mode is changed by the
1285 * user the pin mode control will take care of enabling the pin's
1286 * input/output buffers as needed.
1287 */
1288 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1289 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1290 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1291
1292 /* Mute capture amp left and right */
1293 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1294
1295 /* Set ADC connection select to match default mixer setting (mic1
1296 * pin)
1297 */
1298 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1299
1300 /* Mute all inputs to mixer widget (even unconnected ones) */
1301 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1302 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1303 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1304 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1305 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1306 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1307 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1308 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1309
1310 { }
1311};
1312#endif
1313
1314
1315/* initialize jack-sensing, too */
1316static int cxt5047_hp_init(struct hda_codec *codec)
1317{
1318 conexant_init(codec);
1319 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001320 return 0;
1321}
1322
1323
1324enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001325 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1326 CXT5047_LAPTOP_HP, /* Some HP laptops */
1327 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001328#ifdef CONFIG_SND_DEBUG
1329 CXT5047_TEST,
1330#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001331 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001332};
1333
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001334static const char *cxt5047_models[CXT5047_MODELS] = {
1335 [CXT5047_LAPTOP] = "laptop",
1336 [CXT5047_LAPTOP_HP] = "laptop-hp",
1337 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001338#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001339 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001340#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001341};
1342
1343static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1344 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001345 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001346 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
Tobin Davis82f30042007-02-13 12:45:44 +01001347 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001348 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001349 {}
1350};
1351
1352static int patch_cxt5047(struct hda_codec *codec)
1353{
1354 struct conexant_spec *spec;
1355 int board_config;
1356
1357 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1358 if (!spec)
1359 return -ENOMEM;
1360 mutex_init(&spec->amp_mutex);
1361 codec->spec = spec;
1362
1363 spec->multiout.max_channels = 2;
1364 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1365 spec->multiout.dac_nids = cxt5047_dac_nids;
1366 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1367 spec->num_adc_nids = 1;
1368 spec->adc_nids = cxt5047_adc_nids;
1369 spec->capsrc_nids = cxt5047_capsrc_nids;
1370 spec->input_mux = &cxt5047_capture_source;
1371 spec->num_mixers = 1;
1372 spec->mixers[0] = cxt5047_mixers;
1373 spec->num_init_verbs = 1;
1374 spec->init_verbs[0] = cxt5047_init_verbs;
1375 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001376 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1377 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001378
1379 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001380
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001381 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1382 cxt5047_models,
1383 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001384 switch (board_config) {
1385 case CXT5047_LAPTOP:
Tobin Davisfb3409e2007-05-17 09:40:47 +02001386 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001387 break;
1388 case CXT5047_LAPTOP_HP:
1389 spec->input_mux = &cxt5047_hp_capture_source;
1390 spec->num_init_verbs = 2;
1391 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1392 spec->mixers[0] = cxt5047_hp_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001393 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001394 codec->patch_ops.init = cxt5047_hp_init;
1395 break;
1396 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001397 spec->input_mux = &cxt5047_toshiba_capture_source;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001398 spec->num_init_verbs = 2;
1399 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davis82f30042007-02-13 12:45:44 +01001400 spec->mixers[0] = cxt5047_toshiba_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001401 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001402 break;
1403#ifdef CONFIG_SND_DEBUG
1404 case CXT5047_TEST:
1405 spec->input_mux = &cxt5047_test_capture_source;
1406 spec->mixers[0] = cxt5047_test_mixer;
1407 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001408 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001409#endif
1410 }
1411 return 0;
1412}
1413
1414struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001415 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1416 .patch = patch_cxt5045 },
1417 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1418 .patch = patch_cxt5047 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001419 {} /* terminator */
1420};