blob: bb915ede0ceb1671917a7a742de12b70b8da6ff7 [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
Takashi Iwai461e2c72008-01-25 11:35:17 +010067 unsigned int cur_adc_idx;
68 hda_nid_t cur_adc;
69 unsigned int cur_adc_stream_tag;
70 unsigned int cur_adc_format;
71
Tobin Davisc9b443d2006-11-14 12:13:39 +010072 /* capture source */
73 const struct hda_input_mux *input_mux;
74 hda_nid_t *capsrc_nids;
75 unsigned int cur_mux[3];
76
77 /* channel model */
78 const struct hda_channel_mode *channel_mode;
79 int num_channel_mode;
80
81 /* PCM information */
82 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
83
84 struct mutex amp_mutex; /* PCM volume/mute control mutex */
85 unsigned int spdif_route;
86
87 /* dynamic controls, init_verbs and input_mux */
88 struct auto_pin_cfg autocfg;
89 unsigned int num_kctl_alloc, num_kctl_used;
90 struct snd_kcontrol_new *kctl_alloc;
91 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +020092 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Tobin Davisc9b443d2006-11-14 12:13:39 +010093
94};
95
96static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
97 struct hda_codec *codec,
98 struct snd_pcm_substream *substream)
99{
100 struct conexant_spec *spec = codec->spec;
101 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
102}
103
104static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
105 struct hda_codec *codec,
106 unsigned int stream_tag,
107 unsigned int format,
108 struct snd_pcm_substream *substream)
109{
110 struct conexant_spec *spec = codec->spec;
111 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
112 stream_tag,
113 format, substream);
114}
115
116static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
117 struct hda_codec *codec,
118 struct snd_pcm_substream *substream)
119{
120 struct conexant_spec *spec = codec->spec;
121 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
122}
123
124/*
125 * Digital out
126 */
127static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
128 struct hda_codec *codec,
129 struct snd_pcm_substream *substream)
130{
131 struct conexant_spec *spec = codec->spec;
132 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
133}
134
135static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
136 struct hda_codec *codec,
137 struct snd_pcm_substream *substream)
138{
139 struct conexant_spec *spec = codec->spec;
140 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
141}
142
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200143static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
144 struct hda_codec *codec,
145 unsigned int stream_tag,
146 unsigned int format,
147 struct snd_pcm_substream *substream)
148{
149 struct conexant_spec *spec = codec->spec;
150 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
151 stream_tag,
152 format, substream);
153}
154
Tobin Davisc9b443d2006-11-14 12:13:39 +0100155/*
156 * Analog capture
157 */
158static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
159 struct hda_codec *codec,
160 unsigned int stream_tag,
161 unsigned int format,
162 struct snd_pcm_substream *substream)
163{
164 struct conexant_spec *spec = codec->spec;
165 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
166 stream_tag, 0, format);
167 return 0;
168}
169
170static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
171 struct hda_codec *codec,
172 struct snd_pcm_substream *substream)
173{
174 struct conexant_spec *spec = codec->spec;
175 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
176 0, 0, 0);
177 return 0;
178}
179
180
181
182static struct hda_pcm_stream conexant_pcm_analog_playback = {
183 .substreams = 1,
184 .channels_min = 2,
185 .channels_max = 2,
186 .nid = 0, /* fill later */
187 .ops = {
188 .open = conexant_playback_pcm_open,
189 .prepare = conexant_playback_pcm_prepare,
190 .cleanup = conexant_playback_pcm_cleanup
191 },
192};
193
194static struct hda_pcm_stream conexant_pcm_analog_capture = {
195 .substreams = 1,
196 .channels_min = 2,
197 .channels_max = 2,
198 .nid = 0, /* fill later */
199 .ops = {
200 .prepare = conexant_capture_pcm_prepare,
201 .cleanup = conexant_capture_pcm_cleanup
202 },
203};
204
205
206static struct hda_pcm_stream conexant_pcm_digital_playback = {
207 .substreams = 1,
208 .channels_min = 2,
209 .channels_max = 2,
210 .nid = 0, /* fill later */
211 .ops = {
212 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200213 .close = conexant_dig_playback_pcm_close,
214 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100215 },
216};
217
218static struct hda_pcm_stream conexant_pcm_digital_capture = {
219 .substreams = 1,
220 .channels_min = 2,
221 .channels_max = 2,
222 /* NID is set in alc_build_pcms */
223};
224
Takashi Iwai461e2c72008-01-25 11:35:17 +0100225static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
226 struct hda_codec *codec,
227 unsigned int stream_tag,
228 unsigned int format,
229 struct snd_pcm_substream *substream)
230{
231 struct conexant_spec *spec = codec->spec;
232 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
233 spec->cur_adc_stream_tag = stream_tag;
234 spec->cur_adc_format = format;
235 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
236 return 0;
237}
238
239static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
240 struct hda_codec *codec,
241 struct snd_pcm_substream *substream)
242{
243 struct conexant_spec *spec = codec->spec;
244 snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0);
245 spec->cur_adc = 0;
246 return 0;
247}
248
249static struct hda_pcm_stream cx5051_pcm_analog_capture = {
250 .substreams = 1,
251 .channels_min = 2,
252 .channels_max = 2,
253 .nid = 0, /* fill later */
254 .ops = {
255 .prepare = cx5051_capture_pcm_prepare,
256 .cleanup = cx5051_capture_pcm_cleanup
257 },
258};
259
Tobin Davisc9b443d2006-11-14 12:13:39 +0100260static int conexant_build_pcms(struct hda_codec *codec)
261{
262 struct conexant_spec *spec = codec->spec;
263 struct hda_pcm *info = spec->pcm_rec;
264
265 codec->num_pcms = 1;
266 codec->pcm_info = info;
267
268 info->name = "CONEXANT Analog";
269 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
270 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
271 spec->multiout.max_channels;
272 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
273 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100274 if (codec->vendor_id == 0x14f15051)
275 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
276 cx5051_pcm_analog_capture;
277 else
278 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
279 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100280 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
281 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
282
283 if (spec->multiout.dig_out_nid) {
284 info++;
285 codec->num_pcms++;
286 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100287 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100288 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
289 conexant_pcm_digital_playback;
290 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
291 spec->multiout.dig_out_nid;
292 if (spec->dig_in_nid) {
293 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
294 conexant_pcm_digital_capture;
295 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
296 spec->dig_in_nid;
297 }
298 }
299
300 return 0;
301}
302
303static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
304 struct snd_ctl_elem_info *uinfo)
305{
306 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
307 struct conexant_spec *spec = codec->spec;
308
309 return snd_hda_input_mux_info(spec->input_mux, uinfo);
310}
311
312static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
313 struct snd_ctl_elem_value *ucontrol)
314{
315 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
316 struct conexant_spec *spec = codec->spec;
317 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
318
319 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
320 return 0;
321}
322
323static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
324 struct snd_ctl_elem_value *ucontrol)
325{
326 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
327 struct conexant_spec *spec = codec->spec;
328 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
329
330 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
331 spec->capsrc_nids[adc_idx],
332 &spec->cur_mux[adc_idx]);
333}
334
335static int conexant_init(struct hda_codec *codec)
336{
337 struct conexant_spec *spec = codec->spec;
338 int i;
339
340 for (i = 0; i < spec->num_init_verbs; i++)
341 snd_hda_sequence_write(codec, spec->init_verbs[i]);
342 return 0;
343}
344
345static void conexant_free(struct hda_codec *codec)
346{
347 struct conexant_spec *spec = codec->spec;
348 unsigned int i;
349
350 if (spec->kctl_alloc) {
351 for (i = 0; i < spec->num_kctl_used; i++)
352 kfree(spec->kctl_alloc[i].name);
353 kfree(spec->kctl_alloc);
354 }
355
356 kfree(codec->spec);
357}
358
Tobin Davisc9b443d2006-11-14 12:13:39 +0100359static int conexant_build_controls(struct hda_codec *codec)
360{
361 struct conexant_spec *spec = codec->spec;
362 unsigned int i;
363 int err;
364
365 for (i = 0; i < spec->num_mixers; i++) {
366 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
367 if (err < 0)
368 return err;
369 }
370 if (spec->multiout.dig_out_nid) {
371 err = snd_hda_create_spdif_out_ctls(codec,
372 spec->multiout.dig_out_nid);
373 if (err < 0)
374 return err;
375 }
376 if (spec->dig_in_nid) {
377 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
378 if (err < 0)
379 return err;
380 }
381 return 0;
382}
383
384static struct hda_codec_ops conexant_patch_ops = {
385 .build_controls = conexant_build_controls,
386 .build_pcms = conexant_build_pcms,
387 .init = conexant_init,
388 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100389};
390
391/*
392 * EAPD control
393 * the private value = nid | (invert << 8)
394 */
395
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200396#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100397
Tobin Davis82f30042007-02-13 12:45:44 +0100398static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100399 struct snd_ctl_elem_value *ucontrol)
400{
401 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
402 struct conexant_spec *spec = codec->spec;
403 int invert = (kcontrol->private_value >> 8) & 1;
404 if (invert)
405 ucontrol->value.integer.value[0] = !spec->cur_eapd;
406 else
407 ucontrol->value.integer.value[0] = spec->cur_eapd;
408 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100409
Tobin Davisc9b443d2006-11-14 12:13:39 +0100410}
411
Tobin Davis82f30042007-02-13 12:45:44 +0100412static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100413 struct snd_ctl_elem_value *ucontrol)
414{
415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
416 struct conexant_spec *spec = codec->spec;
417 int invert = (kcontrol->private_value >> 8) & 1;
418 hda_nid_t nid = kcontrol->private_value & 0xff;
419 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100420
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100421 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100422 if (invert)
423 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200424 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100425 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100426
Tobin Davisc9b443d2006-11-14 12:13:39 +0100427 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200428 snd_hda_codec_write_cache(codec, nid,
429 0, AC_VERB_SET_EAPD_BTLENABLE,
430 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100431 return 1;
432}
433
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100434/* controls for test mode */
435#ifdef CONFIG_SND_DEBUG
436
Tobin Davis82f30042007-02-13 12:45:44 +0100437#define CXT_EAPD_SWITCH(xname, nid, mask) \
438 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
439 .info = cxt_eapd_info, \
440 .get = cxt_eapd_get, \
441 .put = cxt_eapd_put, \
442 .private_value = nid | (mask<<16) }
443
444
445
Tobin Davisc9b443d2006-11-14 12:13:39 +0100446static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
447 struct snd_ctl_elem_info *uinfo)
448{
449 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
450 struct conexant_spec *spec = codec->spec;
451 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
452 spec->num_channel_mode);
453}
454
455static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
456 struct snd_ctl_elem_value *ucontrol)
457{
458 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
459 struct conexant_spec *spec = codec->spec;
460 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
461 spec->num_channel_mode,
462 spec->multiout.max_channels);
463}
464
465static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
466 struct snd_ctl_elem_value *ucontrol)
467{
468 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
469 struct conexant_spec *spec = codec->spec;
470 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
471 spec->num_channel_mode,
472 &spec->multiout.max_channels);
473 if (err >= 0 && spec->need_dac_fix)
474 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
475 return err;
476}
477
478#define CXT_PIN_MODE(xname, nid, dir) \
479 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
480 .info = conexant_ch_mode_info, \
481 .get = conexant_ch_mode_get, \
482 .put = conexant_ch_mode_put, \
483 .private_value = nid | (dir<<16) }
484
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100485#endif /* CONFIG_SND_DEBUG */
486
Tobin Davisc9b443d2006-11-14 12:13:39 +0100487/* Conexant 5045 specific */
488
489static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
490static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
491static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100492#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100493
Tobin Davis5cd57522006-11-20 17:42:09 +0100494static struct hda_channel_mode cxt5045_modes[1] = {
495 { 2, NULL },
496};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100497
498static struct hda_input_mux cxt5045_capture_source = {
499 .num_items = 2,
500 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100501 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100502 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100503 }
504};
505
Jiang Zhe5218c892008-01-17 11:18:41 +0100506static struct hda_input_mux cxt5045_capture_source_benq = {
507 .num_items = 3,
508 .items = {
509 { "IntMic", 0x1 },
510 { "ExtMic", 0x2 },
511 { "LineIn", 0x3 },
512 }
513};
514
Tobin Davisc9b443d2006-11-14 12:13:39 +0100515/* turn on/off EAPD (+ mute HP) as a master switch */
516static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
517 struct snd_ctl_elem_value *ucontrol)
518{
519 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
520 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100521 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100522
Tobin Davis82f30042007-02-13 12:45:44 +0100523 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100524 return 0;
525
Tobin Davis82f30042007-02-13 12:45:44 +0100526 /* toggle internal speakers mute depending of presence of
527 * the headphone jack
528 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200529 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
530 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
531 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100532
Takashi Iwai47fd8302007-08-10 17:11:07 +0200533 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
534 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
535 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100536 return 1;
537}
538
539/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200540static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
541 .ops = &snd_hda_bind_vol,
542 .values = {
543 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
544 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
545 0
546 },
547};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100548
Tobin Davis7f296732007-03-12 11:39:01 +0100549/* toggle input of built-in and mic jack appropriately */
550static void cxt5045_hp_automic(struct hda_codec *codec)
551{
552 static struct hda_verb mic_jack_on[] = {
553 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
554 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
555 {}
556 };
557 static struct hda_verb mic_jack_off[] = {
558 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
559 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
560 {}
561 };
562 unsigned int present;
563
564 present = snd_hda_codec_read(codec, 0x12, 0,
565 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
566 if (present)
567 snd_hda_sequence_write(codec, mic_jack_on);
568 else
569 snd_hda_sequence_write(codec, mic_jack_off);
570}
571
Tobin Davisc9b443d2006-11-14 12:13:39 +0100572
573/* mute internal speaker if HP is plugged */
574static void cxt5045_hp_automute(struct hda_codec *codec)
575{
Tobin Davis82f30042007-02-13 12:45:44 +0100576 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100577 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100578
Tobin Davis82f30042007-02-13 12:45:44 +0100579 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100580 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +0100581
Takashi Iwai47fd8302007-08-10 17:11:07 +0200582 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
583 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
584 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100585}
586
587/* unsolicited event for HP jack sensing */
588static void cxt5045_hp_unsol_event(struct hda_codec *codec,
589 unsigned int res)
590{
591 res >>= 26;
592 switch (res) {
593 case CONEXANT_HP_EVENT:
594 cxt5045_hp_automute(codec);
595 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100596 case CONEXANT_MIC_EVENT:
597 cxt5045_hp_automic(codec);
598 break;
599
Tobin Davisc9b443d2006-11-14 12:13:39 +0100600 }
601}
602
603static struct snd_kcontrol_new cxt5045_mixers[] = {
604 {
605 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
606 .name = "Capture Source",
607 .info = conexant_mux_enum_info,
608 .get = conexant_mux_enum_get,
609 .put = conexant_mux_enum_put
610 },
Takashi Iwaic8229c32007-10-19 08:06:21 +0200611 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
612 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
613 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
614 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
615 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
616 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
617 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
618 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
619 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
620 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200621 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100622 {
623 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
624 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100625 .info = cxt_eapd_info,
626 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100627 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100628 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100629 },
630
631 {}
632};
633
Jiang Zhe5218c892008-01-17 11:18:41 +0100634static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
635 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
636 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
637 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
638 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
639
640 {}
641};
642
Tobin Davisc9b443d2006-11-14 12:13:39 +0100643static struct hda_verb cxt5045_init_verbs[] = {
644 /* Line in, Mic */
645 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
Tobin Davis7f296732007-03-12 11:39:01 +0100646 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100647 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200648 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
649 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
650 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
651 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
652 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
653 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
654 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
655 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
656 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100657 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100658 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100659 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100660 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
661 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100662 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100663 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100664 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100665 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100666 { } /* end */
667};
668
Jiang Zhe5218c892008-01-17 11:18:41 +0100669static struct hda_verb cxt5045_benq_init_verbs[] = {
670 /* Int Mic, Mic */
671 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
672 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
673 /* Line In,HP, Amp */
674 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
675 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
676 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
677 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
678 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
679 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
680 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
681 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
682 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
683 /* Record selector: Int mic */
684 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
685 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
686 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
687 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100688 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100689 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
690 /* EAPD */
691 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
692 { } /* end */
693};
Tobin Davis7f296732007-03-12 11:39:01 +0100694
695static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
696 /* pin sensing on HP jack */
697 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200698 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100699};
700
701static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
702 /* pin sensing on HP jack */
703 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200704 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100705};
706
Tobin Davisc9b443d2006-11-14 12:13:39 +0100707#ifdef CONFIG_SND_DEBUG
708/* Test configuration for debugging, modelled after the ALC260 test
709 * configuration.
710 */
711static struct hda_input_mux cxt5045_test_capture_source = {
712 .num_items = 5,
713 .items = {
714 { "MIXER", 0x0 },
715 { "MIC1 pin", 0x1 },
716 { "LINE1 pin", 0x2 },
717 { "HP-OUT pin", 0x3 },
718 { "CD pin", 0x4 },
719 },
720};
721
722static struct snd_kcontrol_new cxt5045_test_mixer[] = {
723
724 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100725 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
726 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100727 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
728 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
729 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
730 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100731
732 /* Modes for retasking pin widgets */
733 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
734 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
735
Tobin Davis82f30042007-02-13 12:45:44 +0100736 /* EAPD Switch Control */
737 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
738
Tobin Davisc9b443d2006-11-14 12:13:39 +0100739 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100740
Tobin Davis7f296732007-03-12 11:39:01 +0100741 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
742 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
743 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
744 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
745 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
746 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
747 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
748 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
749 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
750 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100751 {
752 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
753 .name = "Input Source",
754 .info = conexant_mux_enum_info,
755 .get = conexant_mux_enum_get,
756 .put = conexant_mux_enum_put,
757 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200758 /* Audio input controls */
759 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
760 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
761 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
762 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
763 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
764 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
765 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
766 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
767 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
768 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100769 { } /* end */
770};
771
772static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100773 /* Set connections */
774 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
775 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
776 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100777 /* Enable retasking pins as output, initially without power amp */
778 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100779 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100780
781 /* Disable digital (SPDIF) pins initially, but users can enable
782 * them via a mixer switch. In the case of SPDIF-out, this initverb
783 * payload also sets the generation to 0, output to be in "consumer"
784 * PCM format, copyright asserted, no pre-emphasis and no validity
785 * control.
786 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100787 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
788 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100789
790 /* Start with output sum widgets muted and their output gains at min */
791 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
792 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
793
794 /* Unmute retasking pin widget output buffers since the default
795 * state appears to be output. As the pin mode is changed by the
796 * user the pin mode control will take care of enabling the pin's
797 * input/output buffers as needed.
798 */
799 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
800 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
801
802 /* Mute capture amp left and right */
803 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
804
805 /* Set ADC connection select to match default mixer setting (mic1
806 * pin)
807 */
808 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +0100809 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100810
811 /* Mute all inputs to mixer widget (even unconnected ones) */
812 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
813 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
814 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
815 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
816 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
817
818 { }
819};
820#endif
821
822
823/* initialize jack-sensing, too */
824static int cxt5045_init(struct hda_codec *codec)
825{
826 conexant_init(codec);
827 cxt5045_hp_automute(codec);
828 return 0;
829}
830
831
832enum {
Marc Boucher15908c32008-01-22 15:15:59 +0100833 CXT5045_LAPTOP_HPSENSE,
834 CXT5045_LAPTOP_MICSENSE,
835 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +0100836 CXT5045_BENQ,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100837#ifdef CONFIG_SND_DEBUG
838 CXT5045_TEST,
839#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100840 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100841};
842
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100843static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +0100844 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
845 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
846 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
847 [CXT5045_BENQ] = "benq",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100848#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100849 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +0100850#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100851};
852
853static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Marc Boucher15908c32008-01-22 15:15:59 +0100854 SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
855 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
856 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
857 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
858 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
859 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
Takashi Iwai0f6a5152008-01-29 13:26:04 +0100860 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +0100861 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HPSENSE),
862 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +0100863 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +0100864 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
865 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
866 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP_HPSENSE),
867 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
868 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
869 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
870 SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
871 SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
872 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100873 {}
874};
875
876static int patch_cxt5045(struct hda_codec *codec)
877{
878 struct conexant_spec *spec;
879 int board_config;
880
881 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
882 if (!spec)
883 return -ENOMEM;
884 mutex_init(&spec->amp_mutex);
885 codec->spec = spec;
886
887 spec->multiout.max_channels = 2;
888 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
889 spec->multiout.dac_nids = cxt5045_dac_nids;
890 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
891 spec->num_adc_nids = 1;
892 spec->adc_nids = cxt5045_adc_nids;
893 spec->capsrc_nids = cxt5045_capsrc_nids;
894 spec->input_mux = &cxt5045_capture_source;
895 spec->num_mixers = 1;
896 spec->mixers[0] = cxt5045_mixers;
897 spec->num_init_verbs = 1;
898 spec->init_verbs[0] = cxt5045_init_verbs;
899 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +0100900 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
901 spec->channel_mode = cxt5045_modes,
902
Tobin Davisc9b443d2006-11-14 12:13:39 +0100903
904 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100905
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100906 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
907 cxt5045_models,
908 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100909 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +0100910 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +0100911 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100912 spec->input_mux = &cxt5045_capture_source;
913 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +0100914 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
915 spec->mixers[0] = cxt5045_mixers;
916 codec->patch_ops.init = cxt5045_init;
917 break;
Marc Boucher15908c32008-01-22 15:15:59 +0100918 case CXT5045_LAPTOP_MICSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +0100919 spec->input_mux = &cxt5045_capture_source;
920 spec->num_init_verbs = 2;
921 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100922 spec->mixers[0] = cxt5045_mixers;
923 codec->patch_ops.init = cxt5045_init;
924 break;
Marc Boucher15908c32008-01-22 15:15:59 +0100925 default:
926 case CXT5045_LAPTOP_HPMICSENSE:
927 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
928 spec->input_mux = &cxt5045_capture_source;
929 spec->num_init_verbs = 3;
930 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
931 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
932 spec->mixers[0] = cxt5045_mixers;
933 codec->patch_ops.init = cxt5045_init;
934 break;
Jiang Zhe5218c892008-01-17 11:18:41 +0100935 case CXT5045_BENQ:
936 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
937 spec->input_mux = &cxt5045_capture_source_benq;
938 spec->num_init_verbs = 1;
939 spec->init_verbs[0] = cxt5045_benq_init_verbs;
940 spec->mixers[0] = cxt5045_mixers;
941 spec->mixers[1] = cxt5045_benq_mixers;
942 spec->num_mixers = 2;
943 codec->patch_ops.init = cxt5045_init;
944 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100945#ifdef CONFIG_SND_DEBUG
946 case CXT5045_TEST:
947 spec->input_mux = &cxt5045_test_capture_source;
948 spec->mixers[0] = cxt5045_test_mixer;
949 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +0100950 break;
951
Tobin Davisc9b443d2006-11-14 12:13:39 +0100952#endif
953 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +0100954
955 /*
956 * Fix max PCM level to 0 dB
957 * (originall it has 0x2b steps with 0dB offset 0x14)
958 */
959 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
960 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
961 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
962 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
963 (1 << AC_AMPCAP_MUTE_SHIFT));
964
Tobin Davisc9b443d2006-11-14 12:13:39 +0100965 return 0;
966}
967
968
969/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +0100970#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +0100971
Tobin Davis82f30042007-02-13 12:45:44 +0100972static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100973static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
974static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +0100975
Tobin Davis5cd57522006-11-20 17:42:09 +0100976static struct hda_channel_mode cxt5047_modes[1] = {
977 { 2, NULL },
978};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100979
980static struct hda_input_mux cxt5047_capture_source = {
Tobin Davis7f296732007-03-12 11:39:01 +0100981 .num_items = 1,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100982 .items = {
Tobin Davis7f296732007-03-12 11:39:01 +0100983 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100984 }
985};
986
987static struct hda_input_mux cxt5047_hp_capture_source = {
988 .num_items = 1,
989 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100990 { "ExtMic", 0x2 },
991 }
992};
993
994static struct hda_input_mux cxt5047_toshiba_capture_source = {
995 .num_items = 2,
996 .items = {
997 { "ExtMic", 0x2 },
998 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100999 }
1000};
1001
1002/* turn on/off EAPD (+ mute HP) as a master switch */
1003static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1004 struct snd_ctl_elem_value *ucontrol)
1005{
1006 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1007 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001008 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001009
Tobin Davis82f30042007-02-13 12:45:44 +01001010 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001011 return 0;
1012
Tobin Davis82f30042007-02-13 12:45:44 +01001013 /* toggle internal speakers mute depending of presence of
1014 * the headphone jack
1015 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001016 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1017 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1018 HDA_AMP_MUTE, bits);
1019 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1020 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1021 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001022 return 1;
1023}
1024
Tobin Davis82f30042007-02-13 12:45:44 +01001025/* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001026static struct hda_bind_ctls cxt5047_bind_master_vol = {
1027 .ops = &snd_hda_bind_vol,
1028 .values = {
1029 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1030 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1031 0
1032 },
1033};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001034
1035/* mute internal speaker if HP is plugged */
1036static void cxt5047_hp_automute(struct hda_codec *codec)
1037{
Tobin Davis82f30042007-02-13 12:45:44 +01001038 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001039 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001040
Tobin Davis82f30042007-02-13 12:45:44 +01001041 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001042 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Tobin Davisdd87da12007-02-26 16:07:42 +01001043
Takashi Iwai47fd8302007-08-10 17:11:07 +02001044 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1045 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1046 HDA_AMP_MUTE, bits);
Tobin Davis82f30042007-02-13 12:45:44 +01001047 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001048 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1049 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001050}
1051
Tobin Davisfb3409e2007-05-17 09:40:47 +02001052/* mute internal speaker if HP is plugged */
1053static void cxt5047_hp2_automute(struct hda_codec *codec)
1054{
1055 struct conexant_spec *spec = codec->spec;
1056 unsigned int bits;
1057
1058 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1059 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1060
Takashi Iwai47fd8302007-08-10 17:11:07 +02001061 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1062 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1063 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001064 /* Mute/Unmute PCM 2 for good measure - some systems need this */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001065 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1066 HDA_AMP_MUTE, bits);
Tobin Davisfb3409e2007-05-17 09:40:47 +02001067}
1068
Tobin Davisc9b443d2006-11-14 12:13:39 +01001069/* toggle input of built-in and mic jack appropriately */
1070static void cxt5047_hp_automic(struct hda_codec *codec)
1071{
1072 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001073 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1074 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001075 {}
1076 };
1077 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001078 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1079 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001080 {}
1081 };
1082 unsigned int present;
1083
Tobin Davis7f296732007-03-12 11:39:01 +01001084 present = snd_hda_codec_read(codec, 0x15, 0,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001085 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1086 if (present)
1087 snd_hda_sequence_write(codec, mic_jack_on);
1088 else
1089 snd_hda_sequence_write(codec, mic_jack_off);
1090}
1091
1092/* unsolicited event for HP jack sensing */
1093static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1094 unsigned int res)
1095{
Marc Boucher9f113e02008-01-22 15:18:08 +01001096 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001097 case CONEXANT_HP_EVENT:
1098 cxt5047_hp_automute(codec);
1099 break;
1100 case CONEXANT_MIC_EVENT:
1101 cxt5047_hp_automic(codec);
1102 break;
1103 }
1104}
1105
Tobin Davisfb3409e2007-05-17 09:40:47 +02001106/* unsolicited event for HP jack sensing - non-EAPD systems */
1107static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1108 unsigned int res)
1109{
1110 res >>= 26;
1111 switch (res) {
1112 case CONEXANT_HP_EVENT:
1113 cxt5047_hp2_automute(codec);
1114 break;
1115 case CONEXANT_MIC_EVENT:
1116 cxt5047_hp_automic(codec);
1117 break;
1118 }
1119}
1120
Tobin Davisc9b443d2006-11-14 12:13:39 +01001121static struct snd_kcontrol_new cxt5047_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001122 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1123 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001124 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1125 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001126 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1127 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1128 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1129 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001130 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1131 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
Tobin Davisb7589ce2007-04-24 17:56:55 +02001132 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1133 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1134 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1135 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001136
1137 {}
1138};
1139
1140static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1141 {
1142 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1143 .name = "Capture Source",
1144 .info = conexant_mux_enum_info,
1145 .get = conexant_mux_enum_get,
1146 .put = conexant_mux_enum_put
1147 },
1148 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1149 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1150 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1151 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1152 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1153 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +02001154 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
Tobin Davis82f30042007-02-13 12:45:44 +01001155 {
1156 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1157 .name = "Master Playback Switch",
1158 .info = cxt_eapd_info,
1159 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001160 .put = cxt5047_hp_master_sw_put,
1161 .private_value = 0x13,
1162 },
1163
1164 {}
1165};
1166
1167static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1168 {
1169 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1170 .name = "Capture Source",
1171 .info = conexant_mux_enum_info,
1172 .get = conexant_mux_enum_get,
1173 .put = conexant_mux_enum_put
1174 },
1175 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1176 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1177 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1178 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1179 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1180 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1181 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1182 {
1183 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1184 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +01001185 .info = cxt_eapd_info,
1186 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001187 .put = cxt5047_hp_master_sw_put,
1188 .private_value = 0x13,
1189 },
1190 { } /* end */
1191};
1192
1193static struct hda_verb cxt5047_init_verbs[] = {
1194 /* Line in, Mic, Built-in Mic */
1195 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1196 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1197 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001198 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001199 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1200 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis7f296732007-03-12 11:39:01 +01001201 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1202 /* Record selector: Mic */
1203 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1204 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1205 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1206 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001207 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1208 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1209 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1210 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001211 /* SPDIF route: PCM */
1212 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001213 /* Enable unsolicited events */
1214 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1215 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001216 { } /* end */
1217};
1218
1219/* configuration for Toshiba Laptops */
1220static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1221 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1222 /* pin sensing on HP and Mic jacks */
1223 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1224 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davis82f30042007-02-13 12:45:44 +01001225 /* Speaker routing */
1226 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001227 {}
1228};
1229
1230/* configuration for HP Laptops */
1231static struct hda_verb cxt5047_hp_init_verbs[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001232 /* pin sensing on HP jack */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001233 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaib84f08d2008-02-18 12:36:11 +01001234 /* 0x13 is actually shared by both HP and speaker;
1235 * setting the connection to 0 (=0x19) makes the master volume control
1236 * working mysteriouslly...
1237 */
1238 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
Tobin Davis82f30042007-02-13 12:45:44 +01001239 /* Record selector: Ext Mic */
1240 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
Tobin Davis82f30042007-02-13 12:45:44 +01001241 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1242 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1243 /* Speaker routing */
1244 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001245 {}
1246};
1247
1248/* Test configuration for debugging, modelled after the ALC260 test
1249 * configuration.
1250 */
1251#ifdef CONFIG_SND_DEBUG
1252static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001253 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001254 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001255 { "LINE1 pin", 0x0 },
1256 { "MIC1 pin", 0x1 },
1257 { "MIC2 pin", 0x2 },
1258 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001259 },
1260};
1261
1262static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1263
1264 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001265 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1266 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1267 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1268 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001269 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1270 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1271 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1272 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001273 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1274 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1275 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1276 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001277
1278 /* Modes for retasking pin widgets */
1279 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1280 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1281
Tobin Davis82f30042007-02-13 12:45:44 +01001282 /* EAPD Switch Control */
1283 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1284
Tobin Davisc9b443d2006-11-14 12:13:39 +01001285 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001286 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1287 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1288 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1289 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1290 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1291 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1292 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1293 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001294
Tobin Davis82f30042007-02-13 12:45:44 +01001295 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1296 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1297 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1298 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1299 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1300 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1301 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1302 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001303 {
1304 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1305 .name = "Input Source",
1306 .info = conexant_mux_enum_info,
1307 .get = conexant_mux_enum_get,
1308 .put = conexant_mux_enum_put,
1309 },
Marc Boucher9f113e02008-01-22 15:18:08 +01001310 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1311 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1312 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1313 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1314 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1315 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1316 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1317 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1318 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1319 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1320
Tobin Davisc9b443d2006-11-14 12:13:39 +01001321 { } /* end */
1322};
1323
1324static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001325 /* Enable retasking pins as output, initially without power amp */
1326 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1327 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1328 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1329
1330 /* Disable digital (SPDIF) pins initially, but users can enable
1331 * them via a mixer switch. In the case of SPDIF-out, this initverb
1332 * payload also sets the generation to 0, output to be in "consumer"
1333 * PCM format, copyright asserted, no pre-emphasis and no validity
1334 * control.
1335 */
1336 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1337
1338 /* Ensure mic1, mic2, line1 pin widgets take input from the
1339 * OUT1 sum bus when acting as an output.
1340 */
1341 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1342 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1343
1344 /* Start with output sum widgets muted and their output gains at min */
1345 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1346 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1347
1348 /* Unmute retasking pin widget output buffers since the default
1349 * state appears to be output. As the pin mode is changed by the
1350 * user the pin mode control will take care of enabling the pin's
1351 * input/output buffers as needed.
1352 */
1353 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1354 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1355 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1356
1357 /* Mute capture amp left and right */
1358 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1359
1360 /* Set ADC connection select to match default mixer setting (mic1
1361 * pin)
1362 */
1363 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1364
1365 /* Mute all inputs to mixer widget (even unconnected ones) */
1366 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1367 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1368 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1369 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1370 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1371 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1372 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1373 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1374
1375 { }
1376};
1377#endif
1378
1379
1380/* initialize jack-sensing, too */
1381static int cxt5047_hp_init(struct hda_codec *codec)
1382{
1383 conexant_init(codec);
1384 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001385 return 0;
1386}
1387
1388
1389enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001390 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1391 CXT5047_LAPTOP_HP, /* Some HP laptops */
1392 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001393#ifdef CONFIG_SND_DEBUG
1394 CXT5047_TEST,
1395#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001396 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001397};
1398
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001399static const char *cxt5047_models[CXT5047_MODELS] = {
1400 [CXT5047_LAPTOP] = "laptop",
1401 [CXT5047_LAPTOP_HP] = "laptop-hp",
1402 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001403#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001404 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001405#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001406};
1407
1408static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1409 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001410 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001411 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
Tobin Davis82f30042007-02-13 12:45:44 +01001412 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001413 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001414 {}
1415};
1416
1417static int patch_cxt5047(struct hda_codec *codec)
1418{
1419 struct conexant_spec *spec;
1420 int board_config;
1421
1422 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1423 if (!spec)
1424 return -ENOMEM;
1425 mutex_init(&spec->amp_mutex);
1426 codec->spec = spec;
1427
1428 spec->multiout.max_channels = 2;
1429 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1430 spec->multiout.dac_nids = cxt5047_dac_nids;
1431 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1432 spec->num_adc_nids = 1;
1433 spec->adc_nids = cxt5047_adc_nids;
1434 spec->capsrc_nids = cxt5047_capsrc_nids;
1435 spec->input_mux = &cxt5047_capture_source;
1436 spec->num_mixers = 1;
1437 spec->mixers[0] = cxt5047_mixers;
1438 spec->num_init_verbs = 1;
1439 spec->init_verbs[0] = cxt5047_init_verbs;
1440 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001441 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1442 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001443
1444 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001445
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001446 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1447 cxt5047_models,
1448 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001449 switch (board_config) {
1450 case CXT5047_LAPTOP:
Tobin Davisfb3409e2007-05-17 09:40:47 +02001451 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001452 break;
1453 case CXT5047_LAPTOP_HP:
1454 spec->input_mux = &cxt5047_hp_capture_source;
1455 spec->num_init_verbs = 2;
1456 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1457 spec->mixers[0] = cxt5047_hp_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001458 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001459 codec->patch_ops.init = cxt5047_hp_init;
1460 break;
1461 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001462 spec->input_mux = &cxt5047_toshiba_capture_source;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001463 spec->num_init_verbs = 2;
1464 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davis82f30042007-02-13 12:45:44 +01001465 spec->mixers[0] = cxt5047_toshiba_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001466 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001467 break;
1468#ifdef CONFIG_SND_DEBUG
1469 case CXT5047_TEST:
1470 spec->input_mux = &cxt5047_test_capture_source;
1471 spec->mixers[0] = cxt5047_test_mixer;
1472 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001473 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001474#endif
1475 }
1476 return 0;
1477}
1478
Takashi Iwai461e2c72008-01-25 11:35:17 +01001479/* Conexant 5051 specific */
1480static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1481static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1482#define CXT5051_SPDIF_OUT 0x1C
1483#define CXT5051_PORTB_EVENT 0x38
1484#define CXT5051_PORTC_EVENT 0x39
1485
1486static struct hda_channel_mode cxt5051_modes[1] = {
1487 { 2, NULL },
1488};
1489
1490static void cxt5051_update_speaker(struct hda_codec *codec)
1491{
1492 struct conexant_spec *spec = codec->spec;
1493 unsigned int pinctl;
1494 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1495 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1496 pinctl);
1497}
1498
1499/* turn on/off EAPD (+ mute HP) as a master switch */
1500static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1501 struct snd_ctl_elem_value *ucontrol)
1502{
1503 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1504
1505 if (!cxt_eapd_put(kcontrol, ucontrol))
1506 return 0;
1507 cxt5051_update_speaker(codec);
1508 return 1;
1509}
1510
1511/* toggle input of built-in and mic jack appropriately */
1512static void cxt5051_portb_automic(struct hda_codec *codec)
1513{
1514 unsigned int present;
1515
1516 present = snd_hda_codec_read(codec, 0x17, 0,
1517 AC_VERB_GET_PIN_SENSE, 0) &
1518 AC_PINSENSE_PRESENCE;
1519 snd_hda_codec_write(codec, 0x14, 0,
1520 AC_VERB_SET_CONNECT_SEL,
1521 present ? 0x01 : 0x00);
1522}
1523
1524/* switch the current ADC according to the jack state */
1525static void cxt5051_portc_automic(struct hda_codec *codec)
1526{
1527 struct conexant_spec *spec = codec->spec;
1528 unsigned int present;
1529 hda_nid_t new_adc;
1530
1531 present = snd_hda_codec_read(codec, 0x18, 0,
1532 AC_VERB_GET_PIN_SENSE, 0) &
1533 AC_PINSENSE_PRESENCE;
1534 if (present)
1535 spec->cur_adc_idx = 1;
1536 else
1537 spec->cur_adc_idx = 0;
1538 new_adc = spec->adc_nids[spec->cur_adc_idx];
1539 if (spec->cur_adc && spec->cur_adc != new_adc) {
1540 /* stream is running, let's swap the current ADC */
1541 snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0);
1542 spec->cur_adc = new_adc;
1543 snd_hda_codec_setup_stream(codec, new_adc,
1544 spec->cur_adc_stream_tag, 0,
1545 spec->cur_adc_format);
1546 }
1547}
1548
1549/* mute internal speaker if HP is plugged */
1550static void cxt5051_hp_automute(struct hda_codec *codec)
1551{
1552 struct conexant_spec *spec = codec->spec;
1553
1554 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1555 AC_VERB_GET_PIN_SENSE, 0) &
1556 AC_PINSENSE_PRESENCE;
1557 cxt5051_update_speaker(codec);
1558}
1559
1560/* unsolicited event for HP jack sensing */
1561static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1562 unsigned int res)
1563{
1564 switch (res >> 26) {
1565 case CONEXANT_HP_EVENT:
1566 cxt5051_hp_automute(codec);
1567 break;
1568 case CXT5051_PORTB_EVENT:
1569 cxt5051_portb_automic(codec);
1570 break;
1571 case CXT5051_PORTC_EVENT:
1572 cxt5051_portc_automic(codec);
1573 break;
1574 }
1575}
1576
1577static struct snd_kcontrol_new cxt5051_mixers[] = {
1578 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1579 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1580 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1581 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1582 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1583 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1584 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1585 {
1586 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1587 .name = "Master Playback Switch",
1588 .info = cxt_eapd_info,
1589 .get = cxt_eapd_get,
1590 .put = cxt5051_hp_master_sw_put,
1591 .private_value = 0x1a,
1592 },
1593
1594 {}
1595};
1596
1597static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1598 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1599 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1600 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1601 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1602 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1603 {
1604 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1605 .name = "Master Playback Switch",
1606 .info = cxt_eapd_info,
1607 .get = cxt_eapd_get,
1608 .put = cxt5051_hp_master_sw_put,
1609 .private_value = 0x1a,
1610 },
1611
1612 {}
1613};
1614
1615static struct hda_verb cxt5051_init_verbs[] = {
1616 /* Line in, Mic */
1617 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1618 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1619 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1620 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1621 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1622 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1623 /* SPK */
1624 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1625 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1626 /* HP, Amp */
1627 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1628 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1629 /* DAC1 */
1630 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1631 /* Record selector: Int mic */
1632 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1633 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1634 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1635 /* SPDIF route: PCM */
1636 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1637 /* EAPD */
1638 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1639 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1640 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1641 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1642 { } /* end */
1643};
1644
1645/* initialize jack-sensing, too */
1646static int cxt5051_init(struct hda_codec *codec)
1647{
1648 conexant_init(codec);
1649 if (codec->patch_ops.unsol_event) {
1650 cxt5051_hp_automute(codec);
1651 cxt5051_portb_automic(codec);
1652 cxt5051_portc_automic(codec);
1653 }
1654 return 0;
1655}
1656
1657
1658enum {
1659 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1660 CXT5051_HP, /* no docking */
1661 CXT5051_MODELS
1662};
1663
1664static const char *cxt5051_models[CXT5051_MODELS] = {
1665 [CXT5051_LAPTOP] = "laptop",
1666 [CXT5051_HP] = "hp",
1667};
1668
1669static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1670 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1671 CXT5051_LAPTOP),
1672 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1673 {}
1674};
1675
1676static int patch_cxt5051(struct hda_codec *codec)
1677{
1678 struct conexant_spec *spec;
1679 int board_config;
1680
1681 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1682 if (!spec)
1683 return -ENOMEM;
1684 mutex_init(&spec->amp_mutex);
1685 codec->spec = spec;
1686
1687 codec->patch_ops = conexant_patch_ops;
1688 codec->patch_ops.init = cxt5051_init;
1689
1690 spec->multiout.max_channels = 2;
1691 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1692 spec->multiout.dac_nids = cxt5051_dac_nids;
1693 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1694 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1695 spec->adc_nids = cxt5051_adc_nids;
1696 spec->num_mixers = 1;
1697 spec->mixers[0] = cxt5051_mixers;
1698 spec->num_init_verbs = 1;
1699 spec->init_verbs[0] = cxt5051_init_verbs;
1700 spec->spdif_route = 0;
1701 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1702 spec->channel_mode = cxt5051_modes;
1703 spec->cur_adc = 0;
1704 spec->cur_adc_idx = 0;
1705
1706 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1707 cxt5051_models,
1708 cxt5051_cfg_tbl);
1709 switch (board_config) {
1710 case CXT5051_HP:
1711 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1712 spec->mixers[0] = cxt5051_hp_mixers;
1713 break;
1714 default:
1715 case CXT5051_LAPTOP:
1716 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1717 break;
1718 }
1719
1720 return 0;
1721}
1722
1723
1724/*
1725 */
1726
Tobin Davisc9b443d2006-11-14 12:13:39 +01001727struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01001728 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1729 .patch = patch_cxt5045 },
1730 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1731 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01001732 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1733 .patch = patch_cxt5051 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001734 {} /* terminator */
1735};